diff --git a/.gitignore b/.gitignore index 881b3a1..4c418a7 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ tmp/ # Setup-specific src/main/resources/application.conf +src/main/resources/application.conf.backup # sbt specific .cache diff --git a/src/main/resources/application.conf.example b/src/main/resources/application.conf.example index 550e1ff..eec9544 100644 --- a/src/main/resources/application.conf.example +++ b/src/main/resources/application.conf.example @@ -35,17 +35,24 @@ postgresDBConfig = { #Ex: #smtpHost = "smtp.gmail.com" #smtpPort = 465 -#smtpAuth = true +#smtpTLS = false +#smtpSSL = true #smtpUser = "server@myarimaa.com" #smtpPass = "foobar" +#smtpDebug = false #noReplyAddress = "no-reply@myarimaa.com" #helpAddress = "help@myarimaa.com" + smtpHost = "" smtpPort = 465 -smtpAuth = true +#Use TLS (generally with port 587) +smtpTLS = false +#Use SSL (generally with port 465) +smtpSSL = true smtpUser = "" smtpPass = "" - +#Output debug messages when email sending +smtpDebug=false #Address for no-reply email sent by the server noReplyAddress = "" #Address that should be listed as a help/contact address diff --git a/src/main/scala/ScalatraBootstrap.scala b/src/main/scala/ScalatraBootstrap.scala index cc642f2..489d187 100644 --- a/src/main/scala/ScalatraBootstrap.scala +++ b/src/main/scala/ScalatraBootstrap.scala @@ -59,9 +59,11 @@ class ScalatraBootstrap extends LifeCycle { val domainName = config.getString("domainName") val smtpHost = config.getString("smtpHost") val smtpPort = config.getInt("smtpPort") - val smtpAuth = config.getBoolean("smtpAuth") + val smtpTLS = config.getBoolean("smtpTLS") + val smtpSSL = config.getBoolean("smtpSSL") val smtpUser = config.getString("smtpUser") val smtpPass = config.getString("smtpPass") + val smtpDebug = config.getBoolean("smtpDebug") val noReplyAddress = config.getString("noReplyAddress") val helpAddress = config.getString("helpAddress") @@ -74,7 +76,7 @@ class ScalatraBootstrap extends LifeCycle { val db = DatabaseConfig.getDB() val scheduler = actorSystem.scheduler - val emailer = new Emailer(siteName,siteAddress,smtpHost,smtpPort,smtpAuth,smtpUser,smtpPass,noReplyAddress,helpAddress)(mainEC) + val emailer = new Emailer(siteName,siteAddress,smtpHost,smtpPort,smtpTLS,smtpSSL,smtpUser,smtpPass,smtpDebug,noReplyAddress,helpAddress)(mainEC) val accounts = new Accounts(domainName,db,scheduler)(mainEC) val siteLogin = new SiteLogin(accounts,emailer,cryptEC,scheduler)(mainEC) val games = new Games(db,siteLogin.logins,scheduler,accounts,serverInstanceID)(mainEC) diff --git a/src/main/scala/org/playarimaa/server/Accounts.scala b/src/main/scala/org/playarimaa/server/Accounts.scala index df1e5a2..359fab0 100644 --- a/src/main/scala/org/playarimaa/server/Accounts.scala +++ b/src/main/scala/org/playarimaa/server/Accounts.scala @@ -134,6 +134,7 @@ class Accounts(val domainName: String, val db: Database, val scheduler: Schedule def removeIfGuest(username: Username): Future[Unit] = { val lowercaseName = username.toLowerCase val query: DBIO[Int] = Accounts.table.filter(_.lowercaseName === lowercaseName).filter(_.isGuest).delete + logger.info("Removing guest account: " + username) db.run(DBIO.seq(query)) } @@ -141,6 +142,7 @@ class Accounts(val domainName: String, val db: Database, val scheduler: Schedule def removeIfUnverified(username: Username): Future[Unit] = { val lowercaseName = username.toLowerCase val query: DBIO[Int] = Accounts.table.filter(_.lowercaseName === lowercaseName).filter(_.emailVerifyNeeded.isDefined).delete + logger.info("Removing unverified account: " + username) db.run(DBIO.seq(query)) } diff --git a/src/main/scala/org/playarimaa/server/Emailer.scala b/src/main/scala/org/playarimaa/server/Emailer.scala index 3b87a8d..de050a7 100644 --- a/src/main/scala/org/playarimaa/server/Emailer.scala +++ b/src/main/scala/org/playarimaa/server/Emailer.scala @@ -12,9 +12,11 @@ class Emailer( siteAddress: String, smtpHost: String, smtpPort: Int, - smtpAuth: Boolean, + smtpTLS: Boolean, + smtpSSL: Boolean, smtpUser: String, smtpPass: String, + smtpDebug: Boolean, noReplyAddress: String, helpAddress: String )(implicit ec: ExecutionContext) { @@ -33,12 +35,14 @@ class Emailer( email.setHostName(smtpHost) email.setSmtpPort(smtpPort) email.setAuthenticator(new org.apache.commons.mail.DefaultAuthenticator(smtpUser, smtpPass)) - email.setSSLOnConnect(smtpAuth) + email.setStartTLSEnabled(smtpTLS) + email.setSSLOnConnect(smtpSSL) email.setFrom(noReplyAddress) email.setSubject(subject) email.setTextMsg(body) email.setHtmlMsg(body) email.addTo(to) + email.setDebug(smtpDebug) email.send() () } diff --git a/src/test/scala/ChatTests.scala b/src/test/scala/ChatTests.scala index 3fcc2dd..6dfa62d 100644 --- a/src/test/scala/ChatTests.scala +++ b/src/test/scala/ChatTests.scala @@ -34,9 +34,11 @@ class ChatServletTests(_system: ActorSystem) extends TestKit(_system) with Scala val domainName = config.getString("domainName") val smtpHost = ""//config.getString("smtpHost") val smtpPort = 0//config.getInt("smtpPort") - val smtpAuth = config.getBoolean("smtpAuth") + val smtpTLS = config.getBoolean("smtpTLS") + val smtpSSL = config.getBoolean("smtpSSL") val smtpUser = config.getString("smtpUser") val smtpPass = config.getString("smtpPass") + val smtpDebug = config.getBoolean("smtpDebug") val noReplyAddress = config.getString("noReplyAddress") val helpAddress = config.getString("helpAddress") @@ -47,7 +49,7 @@ class ChatServletTests(_system: ActorSystem) extends TestKit(_system) with Scala val serverInstanceID: Long = System.currentTimeMillis val db = DatabaseConfig.getDB() val scheduler = actorSystem.scheduler - val emailer = new Emailer(siteName,siteAddress,smtpHost,smtpPort,smtpAuth,smtpUser,smtpPass,noReplyAddress,helpAddress)(mainEC) + val emailer = new Emailer(siteName,siteAddress,smtpHost,smtpPort,smtpTLS,smtpSSL,smtpUser,smtpPass,smtpDebug,noReplyAddress,helpAddress)(mainEC) val accounts = new Accounts(domainName,db,scheduler)(mainEC) val siteLogin = new SiteLogin(accounts,emailer,cryptEC,scheduler)(mainEC) val games = new Games(db,siteLogin.logins,scheduler,accounts,serverInstanceID)(mainEC) diff --git a/src/test/scala/GameServerTests.scala b/src/test/scala/GameServerTests.scala index c554b05..18fa526 100644 --- a/src/test/scala/GameServerTests.scala +++ b/src/test/scala/GameServerTests.scala @@ -36,9 +36,11 @@ class GameServletTests(_system: ActorSystem) extends TestKit(_system) with Scala val domainName = config.getString("domainName") val smtpHost = ""//config.getString("smtpHost") val smtpPort = 0//config.getInt("smtpPort") - val smtpAuth = config.getBoolean("smtpAuth") + val smtpTLS = config.getBoolean("smtpTLS") + val smtpSSL = config.getBoolean("smtpSSL") val smtpUser = config.getString("smtpUser") val smtpPass = config.getString("smtpPass") + val smtpDebug = config.getBoolean("smtpDebug") val noReplyAddress = config.getString("noReplyAddress") val helpAddress = config.getString("helpAddress") @@ -48,7 +50,7 @@ class GameServletTests(_system: ActorSystem) extends TestKit(_system) with Scala val serverInstanceID: Long = System.currentTimeMillis val db = DatabaseConfig.getDB() val scheduler = actorSystem.scheduler - val emailer = new Emailer(siteName,siteAddress,smtpHost,smtpPort,smtpAuth,smtpUser,smtpPass,noReplyAddress,helpAddress)(mainEC) + val emailer = new Emailer(siteName,siteAddress,smtpHost,smtpPort,smtpTLS,smtpSSL,smtpUser,smtpPass,smtpDebug,noReplyAddress,helpAddress)(mainEC) val accounts = new Accounts(domainName,db,scheduler)(mainEC) val siteLogin = new SiteLogin(accounts,emailer,cryptEC,scheduler)(mainEC) val games = new Games(db,siteLogin.logins,scheduler,accounts,serverInstanceID)(mainEC)