Created
October 20, 2012 01:50
-
-
Save nisshiee/3921656 to your computer and use it in GitHub Desktop.
heroku+SendGrid+Play2+JavaMailでメールを送る
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
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