Skip to content

Instantly share code, notes, and snippets.

@fbettag
Created February 12, 2012 17:54
Show Gist options
  • Save fbettag/1809910 to your computer and use it in GitHub Desktop.
Save fbettag/1809910 to your computer and use it in GitHub Desktop.
mail.scala
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