2012-07-11 3 views
1

아래 코드는 버튼을 누르면 Outlook 전자 메일을 엽니 다. 제목과 함께 메일에 파일을 자동으로 첨부하는 방법이 있습니까?전자 메일 보내기 (Java)

public void onSubmit() { 
      try { 
       Desktop.getDesktop().browse(new URI("mailto:[email protected]")); 
      } catch (IOException e) { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
      } catch (URISyntaxException e) { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
      }  
    } 

데스크톱 줄을 이렇게 변경하려고 시도했습니다. 이게 효과가 있니? 그 컴파일하지 비록 :

    Desktop.getDesktop().browse(new URI('mailto:[email protected]?subject=New_Profile&body=see attachment&attachment="xyz.xml"')); 
+0

여기를 참조하십시오 : [자바 : 시작 메일 클라이언트 첨부] (http://stackoverflow.com/questions/6029579/java-start-mail-client- 첨부 파일 첨부) –

답변

2
Desktop desktop = Desktop.getDesktop(); 
    String message = "mailto:[email protected]?subject=New_Profile&body=seeAttachment&attachment=c:/Update8.txt"; 
    URI uri = URI.create(message); 
    desktop.mail(uri); 

당신이 할 수있는 ' 수동으로 이메일에 아무 것도 첨부하지 마십시오.

1

아니, 거기에 파일을 첨부 할 수 없습니다. 제목과 본문을 지정할 수 있습니다. 그런데

http://skm.zoomquiet.org/data/20100419224556/index.html

, 당신은 자바,이 방법을 통해 메일을 발송하지 않습니다. 태그와 질문은 같은 주제에 관한 것이 아닙니다.

0

는이 작업을 수행하여 대상을 지정할 수 있습니다 : 그 주제는 URL 인코딩 할 필요가

Desktop.getDesktop().browse(new URI("mailto:[email protected]?subject=My+subject")); 

참고.

첨부 파일을 추가하는 일반적인 방법은 없지만 일부 메일 클라이언트는 특정 메일 클라이언트를 사용하는 방법이 있습니다.

0

짧은 대답은 아니오입니다. Jave는 수단을 통한 첨부 파일을 지원하지 않습니다. 2 년 동안 저를 괴롭혔습니다.

긴 대답은 당신은 MAPI & JNI를 사용하여 작업을 얻을 수 있지만, 모든 메일 클라이언트가 동일한으로, 상처의 세계를 위해 준비입니다

0

예 할 수 있습니다. 내 아래 코드는 완벽하게 작동합니다. 그것을 사용하십시오

클라이언트에게 자동화 된 전자 우편을 보내기 위하여 다만이 기능을 부르십시오. 매개 변수 "to"는 전자 메일을 보내려는 전자 메일 주소입니다. 나는 보통 Maven 프로젝트에서 그것을 할 https://www.tutorialspoint.com/java/java_sending_email.htm

reffer PDF를 부착 대한

. maven 프로젝트를 사용하고 있다면 다음과 같은 의존성을 임포트하십시오. https://mvnrepository.com/artifact/javax.mail/mail/1.4

private void sendMail(String to, String subject, String emailBody) throws MessagingException{ 
    final String username = "[email protected]"; 
    final String password = "emailPassword"; 

    Properties props = new Properties(); 
    props.put("mail.smtp.auth", "true"); 
    props.put("mail.smtp.starttls.enable", "true"); 
    props.put("mail.smtp.host", "smtp.gmail.com"); 
    props.put("mail.smtp.port", "587"); 

    Session session = Session.getInstance(props, 
      new javax.mail.Authenticator() { 
     protected PasswordAuthentication getPasswordAuthentication() { 
      return new PasswordAuthentication(username, password); 
     } 
    }); 

    try { 

     Message message = new MimeMessage(session); 
     message.setFrom(new InternetAddress("[email protected]")); 
     message.setRecipients(Message.RecipientType.TO, 
       InternetAddress.parse(to)); 
     message.setSubject(subject); 
     message.setContent(emailBody, "text/html; charset=utf-8"); 

     Transport.send(message); 

     System.out.println("Done"); 

    } catch (MessagingException e) { 
     throw new RuntimeException(e); 
    } 
} 

}