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.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s