Using Sendgrid with Lift
If you want to send email from your Lift app using SendGrid you need to do two things: set an authenticator and enable the javax.mail authentication flag. That second part isn't obvious.
Step by step...
Assuming your Lift props file contains the following:
# Sendgrid.com configuration: mail.smtp.host=smtp.sendgrid.net mail.user=you@example.com mail.password=letme1n
In Boot you need to set the authenticator:
import javax.mail._
def optionalAuth: Box[Authenticator] = for {
user <- Props.get("mail.user")
pass <- Props.get("mail.password")
} yield new Authenticator {
override def getPasswordAuthentication = new PasswordAuthentication(user,pass)
}
Mailer.authenticator = optionalAuth
And the part that I forgot:
optionalAuth foreach { a => System.setProperty("mail.smtp.auth", "true") }



Comments 2 Comments
I just have a quick question - Did you get this error?:
ERROR - Couldn't send mail
com.sun.mail.smtp.SMTPSendFailedException: 550 Cannot receive from specified address <me>: Unauthenticated senders not allowed
If so, how did you fix it?
Thanks again,
Jose