Skip to content

Instantly share code, notes, and snippets.

@nisshiee
Created October 20, 2012 01:50
Show Gist options
  • Save nisshiee/3921656 to your computer and use it in GitHub Desktop.
Save nisshiee/3921656 to your computer and use it in GitHub Desktop.
heroku+SendGrid+Play2+JavaMailでメールを送る
package controllers
import play.api._
import play.api.mvc._
object SendmailTest extends Controller {
def index = Action {
sendmail
Ok(views.html.index("ok"))
}
def sendmail = {
import java.util._
import javax.mail._
import javax.mail.internet._
val props = System.getProperties
val auth = new Authenticator {
override val getPasswordAuthentication =
new PasswordAuthentication(props.getProperty("mail.smtp.user"), props.getProperty("mail.smtp.pass"))
}
val session = Session.getInstance(props, auth)
val msg = {
val m = new MimeMessage(session)
m.setFrom(new InternetAddress("hiro@nisshiee.org"))
m.setRecipients(Message.RecipientType.TO, "hiro@nisshiee.org")
m.setSubject("This is test mail from heroku", "ISO-2022-JP")
m.setSentDate(new Date)
m.setText("これはテストメールです", "ISO-2022-JP")
m
}
Transport.send(msg)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment