Created
April 9, 2017 13:00
-
-
Save biscuitrainbow/b391e91f5674d75734e2ff4a82320098 to your computer and use it in GitHub Desktop.
6. ระบบสามารถส่งไฟล์ข้อมูลไปยัง E-Mail Address ได้
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private MimeMessage createMessageWithAttachment(Email email) throws MessagingException { | |
Properties properties = new Properties(); | |
Session session = Session.getDefaultInstance(properties, null); | |
MimeMessage mimeMessage = new MimeMessage(session); | |
mimeMessage.setFrom(new InternetAddress(email.getSender())); | |
mimeMessage.addRecipient(javax.mail.Message.RecipientType.TO, new InternetAddress(email.getReceiver())); | |
mimeMessage.setSubject(email.getSubject()); | |
MimeBodyPart bodyPart = new MimeBodyPart(); | |
bodyPart.setContent(email.getBody(), "text/plain"); | |
MimeMultipart multipart = new MimeMultipart(); | |
DataSource source = new FileDataSource(email.getAttachment()); | |
bodyPart.setDataHandler(new DataHandler(source)); | |
bodyPart.setFileName(email.getAttachment().getName()); | |
multipart.addBodyPart(bodyPart); | |
mimeMessage.setContent(multipart); | |
return mimeMessage; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment