Skip to content

Instantly share code, notes, and snippets.

@tototoshi
Created January 13, 2011 13:10
Show Gist options
  • Save tototoshi/777837 to your computer and use it in GitHub Desktop.
Save tototoshi/777837 to your computer and use it in GitHub Desktop.
ScalaでGmail
import java.util.{Date, Properties}
import javax.mail._
import javax.mail.internet._
val host = "smtp.gmail.com"
val username = "your_mail_address at gmail.com"
val password = "your_password"
val props: Properties = System.getProperties
props.put("mail.smtps.auth", "true")
val session: Session = Session.getInstance(props, null)
val msg = new MimeMessage(session)
msg.setRecipients(Message.RecipientType.TO,
"recipient at gmail.com")
msg.setSubject("From Scala To You!")
msg.setSentDate(new Date)
msg.setText("すから!!\n")
val t: Transport = session.getTransport("smtps")
try {
t.connect(host, username, password)
t.sendMessage(msg, msg.getAllRecipients)
} finally {
t.close()
}
@gregv21v
Copy link

gregv21v commented Sep 8, 2013

Do I have to include an external library to get access to javax.mail?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment