Dari has several classes for sending and receiving email. This section describes how to connect those classes to a local email server for development and testing.

The development environment described in this section uses GreenMail as the server and Thunderbird as the client—both running on localhost. You can modify this topology in the following ways:

  • Run GreenMail on a remote host or a virtual guest.
  • Use other email clients and servers, and adjust these instructions accordingly.

Step 1: Install Mail Server

In this step you install the GreenMail mail server.

  1. Create a directory where you want to install the server, such as ~/greenmail.

  2. Go to GreenMail’s download page.

  3. Copy the download link for the GreenMail Standalone server.

  4. Change to the directory you created in step 1.

  5. Using curl, download the GreenMail server using the link you copied in step 3. The command you enter is similar to the following.

    curl -o greenmail-standalone.jar

    Be sure to use the parameter -o greenmail-standalone.jar.

  6. Using the following table as a reference, set environment variables for the IP address and email login.

    Variable Description Example
    MAIL_USER Username for the email account. worf
    MAIL_PASSWORD Password for retrieving email. omg
    MAIL_DOMAIN Domain-name portion of the email address (usually localhost for the local host). localhost,
    HOST_IP IP address of the machine running the email server (usually for the local host).,

    For information about setting up a Vagrant virtual machine to run the email server, see Vagrant. When using Vagrant (or any other remote or virtual machine), you need to use the corresponding values for MAIL_DOMAIN and HOST_IP.

  7. Display the email address: echo $MAIL_USER@$MAIL_DOMAIN. You’ll enter this address when configuring the email client.

  8. Start the email server with the following command:

    java -Dgreenmail.setup.test.all \
    -Dgreenmail.users=$MAIL_USER:$MAIL_PASSWORD@$MAIL_DOMAIN \
    -Dgreenmail.hostname=$HOST_IP \
    -Dgreenmail.verbose=true \
    -jar greenmail-standalone.jar

The email server starts and displays output to the console, similar to the following. Note the IP address and port number for the IMAP and SMTP servers; you’ll use those when configuring the email client.

5       DEBUG           imap.ImapServer| Started imap:
6       DEBUG           smtp.SmtpServer| Started smtp:
6       DEBUG           pop3.Pop3Server| Started pop3:
374     DEBUG           pop3.Pop3Server| Started pop3s:
380     DEBUG           smtp.SmtpServer| Started smtps:
392     DEBUG            util.GreenMail| Started services, performing check if all up
394     DEBUG           imap.ImapServer| Started imaps:

Step 2: Install Mail Client

In this step you install and configure the Thunderbird email client. The steps are similar for other email clients.

  1. Download Thunderbird. Go to and click Free Download.

  2. Install Thunderbird, then run it.

  3. If a dialog box appears asking to use Thunderbird as a default client, click Skip Integration.

  4. Select Tools > Account Settings. A list of accounts appears.

  5. Under the list of accounts, click Account Actions and select Add Mail Account. A dialog box appears.

  6. In the Your name field, type your name.

  7. In the Email address field, type the email address from step 7 of Step 1: Install Mail Server.

  8. In the Password field, type the password you used for MAIL_PASSWORD in step 6 of Step 1: Install Mail Server.

  9. Click Continue. Thunderbird fails to connect to the server and displays an advanced configuration dialog box.

  10. For the incoming protocol, select IMAP.

  11. In the Server Hostname column, type the name you used for MAIL_DOMAIN in step 6 of Step 1: Install Mail Server. (Delete any leading periods.)

  12. In the Port column, enter the port numbers for IMAP and SMTP from GreenMail’s console output.

  13. In the SSL column, select None.

  14. In the Authentication column, select Normal password.

  15. For incoming and outgoing usernames, ensure the username matches MAIL_USER from step 6 of Step 1: Install Mail Server.

  16. Click Re-test. Thunderbird displays a message that the settings were found by probing the server.

  17. Click Done. A warning message appears.

  18. Mark I understand the risks and click Done. You return to the list of accounts.

  19. Click Outgoing Server (SMTP). A list of outgoing servers appears.

  20. Select the server you created in the advanced configuration in step 9, then click Set Default.

  21. Click OK. You return to Thunderbird’s main window.

  22. Send yourself an email to the address from step 7. If you receive the email, the connection between the email client and email server is complete.


Step 3: Configure Dari

You can configure Dari to connect to any number of email servers. This configuration serves as an abstraction layer that Brightspot uses to send and receive emails. In particular, when configuring an email server running on localhost, you can develop and test Brightspot’s notifications feature.

  1. In a text editor, open the Tomcat configuration file conf/context.xml.

  2. Add the following lines:

    <Environment name="dari/defaultMailProvider" value="greenmail" type="java.lang.String" />
    <Environment name="dari/mailProvider/greenmail/class" value="com.psddev.dari.util.SmtpMailProvider" type="java.lang.String" />
    <Environment name="dari/mailProvider/greenmail/host" value="$HOST_IP" type="java.lang.String" />
    <Environment name="dari/mailProvider/greenmail/port" value="$PORT" type="java.lang.String" />
    <Environment name="dari/mailProvider/greenmail/username" value="$MAIL_USER" type="java.lang.String" />
    <Environment name="dari/mailProvider/greenmail/password" value="$MAIL_PASSWORD" type="java.lang.String" />
  3. Save and close the configuration file.

  4. Restart the Tomcat server.

In the previous snippet—

  • Line 1 specifies the default email server configuration as greenmail.
  • Line 3 specifies the IP address at which the email server is running. Use the value for HOST_IP from step 6 in Step 1: Install Mail Server.
  • Line 4 specifies the port on which the SMTP server is running. Use the port number from GreenMail’s console output.
  • Line 5 specifies the username for logging on to the SMTP server. Use the value for MAIL_USER from step 6 in Step 1: Install Mail Server.
  • Line 6 specifies the password for logging on to the SMTP server. Use the value for MAIL_PASSWORD from step 6 in Step 1: Install Mail Server.