Scala and Gmail

I was looking for a Scala-esque wrapper around Apache Commons Email and I’ve found just that in this Gist which I’ve forked to add the configuration details using Typesafe Config.

As far as the addition goes, it’s a function to add the Email hostname/port/ssl/smtpserver/username/password:

      def withResources = (email:Email) => {
        val conf = ConfigFactory.load
        email.setHostName(conf.getString("email.hostname"))
        email.setSmtpPort(conf.getInt("email.port"))
        email.setAuthentication(conf.getString("email.username"),conf.getString("email.password"))
        email.setSSL(conf.getBoolean("email.is.ssl"))
        email
      }

The original Gist is constructing the Email flavour according to the need (html/simple/attachement) which I am wrapping around a Some (since the case is exhaustive) so I can then map it to the above function to add the underlying configs.