Skip to content

Commit

Permalink
Polish up email issues in the process of switching to amazon ses
Browse files Browse the repository at this point in the history
  • Loading branch information
lightvector authored and EC2 Default User committed Jan 17, 2016
1 parent 0f792d5 commit 7d81355
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 11 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ tmp/

# Setup-specific
src/main/resources/application.conf
src/main/resources/application.conf.backup

# sbt specific
.cache
Expand Down
13 changes: 10 additions & 3 deletions src/main/resources/application.conf.example
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,24 @@ postgresDBConfig = {
#Ex:
#smtpHost = "smtp.gmail.com"
#smtpPort = 465
#smtpAuth = true
#smtpTLS = false
#smtpSSL = true
#smtpUser = "[email protected]"
#smtpPass = "foobar"
#smtpDebug = false
#noReplyAddress = "[email protected]"
#helpAddress = "[email protected]"

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
Expand Down
6 changes: 4 additions & 2 deletions src/main/scala/ScalatraBootstrap.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions src/main/scala/org/playarimaa/server/Accounts.scala
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,15 @@ 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))
}

//Remove an account if its email is not verified
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))
}

Expand Down
8 changes: 6 additions & 2 deletions src/main/scala/org/playarimaa/server/Emailer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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()
()
}
Expand Down
6 changes: 4 additions & 2 deletions src/test/scala/ChatTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -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)
Expand Down
6 changes: 4 additions & 2 deletions src/test/scala/GameServerTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -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)
Expand Down

0 comments on commit 7d81355

Please sign in to comment.