Development

This document describes how a user can utilize the Application Program Interface (API) of the email-core package to develop their own interface to a SMTP server. The following topics can be found in this document:

API Entry Points

Following section describes how a user can utilize the Application Program Interface (API) of the Email Core package to send an email to one or multiple recipients from a Java Application. Additional information is also available from the JavaDocs documentation for this project.

1. Choose one of Constructors below:

// Default constructor
public SendEmail()

or
 
// Constructor with host and port for SMTP server    
public SendEmail(String host, String port)  
      
or

// Constructor with host, port, username, and password for SMTP server
public SendEmail(String host, String port, String user, String pass) 
      

2a. Set host and port for the SMTP server:

If it is required to change host name and port number of the e-mail server, then you can set these properties as follows. The default host value is 'localhost'. The default port number is '25'.

se.setHost(host);     // to set the smtp host name
se.setPort(port);     // to set the smtp port number
      

2b. Set User Authentication:

If it is required to provide user ID and Password to the e-mail server for authentication purpose, then you can set these properties as follows.

se.setUser(username);     // to set username for the email authentication
se.setPassword(password); // to set password for the email authentication
      

2c. Set Sender's Email ID:

If it is required to change the sender's email id, then you can set it as follows.

se.setFrom(from);     // to set the sender's email id
      

3. Call send() method to send a message to one or more recipients. If you send a message to multiple recipients using bottom send() method, the value of 'toAddress' should be separated by ','.

public void send(ArrayList<String> listOfEmails, String subject, String msgContent)    
         
or
        
public void send(String toAddress, String subject, String msgContent)
      

Test Executable JAR

To test the Email Core via command line, execute a program with the following command:

% java gov.nasa.pds.tracking.email.SendEmail <recipient> <host> <port> <username> <password>
      
Command-Line OptionDescription
<recipient>Specify an email address to receive the test email.
<host>Specify a host name of the email server. The default host is localhost.
<port>Specify a port number of the email server. The default port is 25.
<username>Specify a username for authentication with the email server. This argument is optional.
<password>Specify a password associated with the username. This argument is optional.