Created
January 13, 2011 13:10
-
-
Save tototoshi/777837 to your computer and use it in GitHub Desktop.
ScalaでGmail
This file contains hidden or 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
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() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Do I have to include an external library to get access to javax.mail?