Sending e-mail and SMS from Scala using Heroku and Ubuntu server

1.7k views Asked by At

I'm creating a simple HTTP proxy that will sit between mobile apps and a backend SOAP server. The proxy server will be wrapped in a filter that sends e-mail and sms notifications when discovering certain types of messages. I've decided to use Scala, Finagle and Heroku. My client however insists that the system must not be tied down to Heroku, if ever they decide to host on their own Ubuntu servers. So, they are skeptical of using Heroku plugins that will make it difficult to setup the same service on Ubuntu later.

If anyone can share some ideas on approaching this problem, I will really appreciate it. In particular:

  • Is there anything special they will need to run Finagle on Ubuntu? Can I just use SBT to get everything 'magically'?
  • Are there any good solutions, libraries or services out there, that allows the sending of mail or SMS in a simple and secure manner that will play well with both Heroku and Ubuntu?
  • Sending mail from Java typical uses system properties. How does one set this up for a remote server like Heroku?
1

There are 1 answers

0
Ant Kutschera On BEST ANSWER

Sending mail from Java doesn't need system properties:

Properties props = new Properties();
props.put("mail.smtp.auth", "true");
Session session = Session.getInstance(props);
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress("[email protected]"));   
message.setRecipients(Message.RecipientType.TO, new InternetAddress("[email protected]"));
message.setSubject("Some Subject");
message.setText("Some Message");
Transport transport = session.getTransport("smtp");
transport.connect(host, port, username, password);
Transport.send(message);

Load the props and host, port, username, password out of a properties file if you like. Or out of a database.

So, sending mail is entirely independent of Ubuntu and Heroku.

Sending SMS I've done like this: http://nexmo.com/documentation/libs/index.html#java