OpenNTF.org - Class to create email from any
My Links (Not logged in)
Code Bin Search
 
Hosted by Prominic.NET
Rate This Code
5 - brilliant stuff
4 - very nice
3 - average
2 - needs work
1 - bad
   OpenNTF Code Bin
About This Code
Brief Description:
Class to create email from any Java application 
Rating:
Not Rated Yet 
Contributor:
Brian Green 
Category:
Java 
Type:
Email 
Document Release:
1.0 
Notes Version:
R6.x 
Last Modified:
07 Aug 2003 
OpenNTF Disclaimer

All of the program code and information presented in the OpenNTF.org Code Bin are provided "as-is", and should be used at your own risk. OpenNTF.org make no express or implied warranty about anything in the Code Bin, and OpenNTF.org will not be responsible or liable for any damage caused by the use or misuse of anything from this site. OpenNTF.org makes no guarantees about anything. Please thoroughly test all of the knowledge and code you find here before you attempt to use them in your production environment.

Code / Description
import lotus.domino.NotesException;


/**
* Send an email message using the Domino mail server. Can be used in non-Domino Java applications, and can also be run from the command line.
*/
public class DominoMailbox
{

/**
* One person or group name. For example, Brian Green/Acme@AcmeMAIL. Group names must appear in the Domino
* sever's address book.
*/
public String sendTo;

/**
* One person or group name. For example, Brian Green/Acme@AcmeMAIL. Group names must appear in the Domino
* sever's address book.
*/
public String copyTo;

/**
* The email's subject line.
*/
public String subject;

/**
* The email's message text.
*/
public String message;

/**
* Host name of the Domino server. A connection will be opened to this server.
*/
private String dominoServer = "mail.acme.com";

/**
* Mailbox available to the dominoUsername.
*/
private String dominoMailbox = "mail\\user.nsf";

/**
* Username of the Domino user. Must be allowed to access the target database (dominoMailbox), and must be allowed
* to open DIIOP connections to the dominoServer. (The DIIOP task must be running on the Domino server.)
*/
private String dominoUsername = "Power User/ACME";

/**
* Internet password for the dominoUsername. Defined in the Domino server's address book.
*/
private String dominoPassword = "password";


/**
* Constructs a new email message. Call the "send" method when you're ready to send it.
* @param sendTo
* @param copyTo
* @param subject
* @param message
*/
public DominoMailbox( String sendTo, String copyTo, String subject, String message )
{
this.sendTo = sendTo;
this.copyTo = copyTo;
this.subject = subject;
this.message = message;
}

/**
* Optional startup - Send a message from the command line.
* @param args To run from the command line, specify 4 parameters.
* [1] SendTo. One person or group name. For example, Brian Green/Acme@AcmeMAIL"
* [2] CopyTo. One person or group name.
* [3] Subject.
* [4] Message.
*/
public static void main( String[] args )
{
if ( args.length != 4 )
{
System.out.println( "\n\n" +
"To start from the command line, you must supply these arguments: \n" +
"[1] SendTo. One person or group name. For example, Brian Green/Acme@AcmeMAIL \n" +
"[2] CopyTo. One person or group name. \n" +
"[3] Subject. \n" +
"[4] Message. \n\n" );
}
else
{
DominoMailbox mail = new DominoMailbox( args[0], args[1], args[2], args[3] );
mail.send();
}
}

/**
* Connects to the Domino application server, and sends an email.
*/
public void send()
{
try
{
lotus.domino.Session dominoSession = lotus.domino.NotesFactory.createSession( dominoServer, dominoUsername, dominoPassword );
lotus.domino.Database dominoDb = dominoSession.getDatabase( dominoServer, dominoMailbox );
//System.out.println( "Connected as: " + dominoSession.getUserName() );

lotus.domino.Document memo = dominoDb.createDocument();
memo.appendItemValue( "Form", "Memo" );
memo.appendItemValue( "Importance", "1" );
memo.appendItemValue( "CopyTo", copyTo );
memo.appendItemValue( "Subject", subject );
memo.appendItemValue( "Body", message );
memo.send( false, sendTo );

//Recycle
dominoDb.recycle();
dominoSession.recycle();
}
catch ( NotesException e )
{
System.out.println( "Error - " + e.id + " " + e.text );
//e.printStackTrace( System.out );
}
catch ( Exception e )
{
System.out.println( "Error - " + e.toString() );
//e.printStackTrace( System.out );
}

}


}

Usage / Example
DominoMailbox mail = new DominoMailbox( sendTo, copyTo, subject, message );
mail.send();
Code Attachments
 Comments

No documents found

 Add your comment!