pyc-website
main website for pyc inc.
git clone https://9o.is/git/pyc-website.git
SmtpMailer.scala
(1628B)
1 package inc.pyc
2 package config
3
4 import javax.mail.{Authenticator, PasswordAuthentication}
5 import javax.mail.internet.MimeMessage
6
7 import net.liftweb._
8 import common._
9 import util._
10
11 /*
12 * A Mailer config object that uses Props and auto configures for gmail
13 * if detected.
14 */
15 object SmtpMailer extends Loggable {
16 def init(): Unit = {
17
18 var isAuth = Props.get("mail.smtp.auth", "false").toBoolean
19
20 Mailer.customProperties = Props.get("mail.smtp.host", "localhost") match {
21 case "smtp.gmail.com" => // auto configure for gmail
22 isAuth = true
23 Map(
24 "mail.smtp.host" -> "smtp.gmail.com",
25 "mail.smtp.port" -> "587",
26 "mail.smtp.auth" -> "true",
27 "mail.smtp.starttls.enable" -> "true"
28 )
29 case h => Map(
30 "mail.smtp.host" -> h,
31 "mail.smtp.port" -> Props.get("mail.smtp.port", "25"),
32 "mail.smtp.auth" -> isAuth.toString
33 )
34 }
35
36 //Mailer.devModeSend.default.set((m : MimeMessage) => logger.info("Sending Mime Message: "+m))
37
38 if (isAuth) {
39 (Props.get("mail.smtp.user"), Props.get("mail.smtp.pass")) match {
40 case (Full(username), Full(password)) =>
41 logger.info("Smtp user: %s".format(username))
42 logger.info("Smtp password length: %s".format(password.length))
43 Mailer.authenticator = Full(new Authenticator() {
44 override def getPasswordAuthentication = new
45 PasswordAuthentication(username, password)
46 })
47 logger.info("SmtpMailer inited")
48 case _ => logger.error("Username/password not supplied for Mailer.")
49 }
50 }
51 }
52 }