Created
February 12, 2012 17:54
-
-
Save fbettag/1809910 to your computer and use it in GitHub Desktop.
mail.scala
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
val props: Properties = System.getProperties() | |
props.put("mail.smtp.from", "my@mail.from") | |
val session: Session = Session.getInstance(props, null) | |
val message = new MimeMessage(session) | |
message.setFrom(new InternetAddress("my@mail.from", "This is my Name")) | |
message.addRecipient(Message.RecipientType.TO, new InternetAddress("recipient@foo.org"))) | |
message.setSubject("Blubber") | |
val multipart = new MimeMultipart() | |
var messageBodyPart = new MimeBodyPart() | |
messageBodyPart.setText(plainContent + MailHelpers.footer) | |
multipart.addBodyPart(messageBodyPart) | |
messageBodyPart = new MimeBodyPart() | |
val source = new FileDataSource("/some/file.pdf") | |
messageBodyPart.setDataHandler(new DataHandler(source)) | |
messageBodyPart.setFileName("myfile.pdf") | |
multipart.addBodyPart(messageBodyPart) | |
message.setContent(multipart) | |
Transport.send(message) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment