Home

Awesome

Frege Email

Build Status Download

Frege Email aims to provide a simple API for sending emails via SMTP. It will help you, for instance, to equip your web application written in Frege with notifications.

The library is built by wrapping Java's Apache Commons Email. So you would be able to see it as a working example of Frege-Java interoperations.

Examples

A simple email

The following is the simplest self-contained example to send an email.

module Main where

import io.cheshirecat.frege.Email

server   = smtpServer.{ hostName = "smtp.example.com" }
addr     = address.{ email = "foo@example.com" }
testMail = email.{ subject  = "Test Mail"
                 , from     = addr
                 , to       = [addr]
                 , message  = "This is a test mail."
                 }

main _ = do
    flip catch handler $ do
        sendEmail server Nothing testMail
  where handler = \(e::EmailException) -> e.printStackTrace

The smtpServer is provided by the library for simplicity, which sends emails via port 25. To change the port, update the portNumber field of stmpServer.

Through your Gmail account

You can send emails through you Gmail account. Unlike the first example, you should:

...
server = sslSMTPServer.{ hostName = "smtp.gmail.com" }
auth   = authentication.{ userName = "yourusername"
                        , password = "yourpassword"
                        }
...

main _ = do
    flip catch handler $ do
        sendEmail server (Just auth) testMail
  where handler = \(e::EmailException) -> e.printStackTrace

Note that, for now, you have to allow less secure applications to access your Google accounts. See also the official help page.

With attachments

Sending emails with attachments is accomplished by using the attached field like:

...
file = attachment.{ name = "No Title"
                  , path = "path/to/your/picture.jpg"
                  }
testMail = email.{ subject  = "Test Mail"
                 , from     = addr
                 , to       = [addr]
                 , message  = "This is a test mail."
                 , attached = [file]
                 }
...

Build Settings

build.gradle

The binaries are avarable at Bintay:

repositories {
    maven {
        url 'http://dl.bintray.com/y-taka-23/maven'
    }
}

Add your dependencies:

compile 'io.cheshirecat:frege-email:0.1.0'

Version compatibility

Frege EmailFrege CompilerTarget JDKChinook (FYI)
0.1.03.23.288-gaa3af0c1.80.2.0

License

This project is released under the Apache 2.0 license. For more details, see LICENSE file.