2012-07-15 3 views
0

무슨 일이 있었습니까? 이전에는 ok로 작동했지만 오류가 발생합니다.Java Mail을 사용하여 첨부 파일을 보낼 수 없습니다.

그것은 연결 오류처럼 보이는
public Send(String user, String password) 
    { 
     this.user = user; 
     this.password = password; 
     Properties props = new Properties(); 
     props.setProperty("mail.transport.protocol", "smtp"); 
     props.setProperty("mail.host", mailhost); 
     props.put("mail.smtp.auth", "true"); 
     props.put("mail.smtp.port", "465"); 
     props.put("mail.smtp.socketFactory.port", "465"); 
     props.put("mail.smtp.so cketFactory.class","javax.net.ssl.SSLSocketFactory"); 
     props.put("mail.smtp.socketFactory.fallback", "false"); 
     props.setProperty("mail.smtp.quitwait", "false"); 
     session = Session.getDefaultInstance(props, this); 
    } 

    protected PasswordAuthentication getPasswordAuthentication() 
    { 
     return new PasswordAuthentication(user, password); 
    } 

public void sendMail (final String recipients, final String FileName) 
    { 
     Thread SendThread = new Thread() 
     { 
      public void run() 
      {     
       try 
       {    
        //String SSS = FileName.replace("+", "");     
        //String Fname = new File (SSS).getName(); 

        String Fname = new File (FileName).getName(); 
        String subject = Fname.substring(0, 9);  
        Log.e("!!!!!!!!!!!!!!!!!!!!!! ", Fname); 

        String RusFname = new String (Fname.getBytes()); 
        String sender = "_X_X_X_"; 
        MimeMessage message = new MimeMessage(session); 
        message.setSender(new InternetAddress(sender)); 
        message.setSubject(subject);    
        MimeBodyPart attachmentPart = new MimeBodyPart();      
        FileDataSource fileDataSource = new FileDataSource(FileName) 
        { 
         @Override 
         public String getContentType() 
         { 
          return "application/octet-stream"; 
         } 
        }; 
        attachmentPart.setDataHandler(new DataHandler(fileDataSource));        
        attachmentPart.setFileName(MimeUtility.encodeText(RusFname));    
        Multipart multipart = new MimeMultipart(); 
        multipart.addBodyPart(attachmentPart);    
        message.setContent(multipart);   
        if (recipients.indexOf(',') > 0) 
         message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(recipients)); 
        else 
         message.setRecipient(Message.RecipientType.TO, new InternetAddress(recipients)); 
        Transport.send(message); 
        File f = new File(FileName); 
        Log.e("!!!!!!!!!!!!!!!!!!!!!! ", "Sended"); 
        f.delete();     
       } 
       catch (MessagingException ex) 
       { 
        ex.printStackTrace(); 
       } catch (UnsupportedEncodingException e) 
       { 
        e.printStackTrace(); 
       } 
      } 
     }; 
     SendThread.start(); 
    } 
07-15 15:32:31.849: WARN/System.err(10287): javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 465, response: -1 
07-15 15:32:31.849: WARN/System.err(10287):  at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1379) 
07-15 15:32:31.849: WARN/System.err(10287):  at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:412) 
07-15 15:32:31.849: WARN/System.err(10287):  at javax.mail.Service.connect(Service.java:310) 
07-15 15:32:31.854: WARN/System.err(10287):  at javax.mail.Service.connect(Service.java:169) 
+0

는 당신의 의도이다 아닌지 모르겠어요,하지만 당신이 정말로 자바를 사용하여 전자 메일을 보내 싶어 Intent.ACTION_SEND 대신 Mail을 사용 하시겠습니까? 이 마지막 것은 훨씬 쉽고 빠르게 사용할 수 있습니다. – yugidroid

답변

1

... 네트워크 상태를 확인하시기 바랍니다 등 방화벽

관련 문제