Import Lotus. Domino. notesexception;
Import Lotus. Domino. Session;
Import Lotus. Domino. notesfactory;
Import Lotus. Domino. database;
Import Lotus. Domino. embeddedobject;
Import Lotus. Domino. richtextitem;
Import Lotus. Domino. Document;
Import java. util .*;
/**
* Send Lotus mail. The customer is in domino5.11. To send mail, refer to the Java library of designer 5.11 for Lotus database operations.
* The added attachments must be placed on the Domino server. They cannot be placed on the client to add attachments. Do not ask why. This is a fact.
* For example, put em_01/test/test.tar in as400 and use the relative path in the program. "test/test.tar" is relative to em_01 in the mail root directory.
*
* After the operation, you must release the resources used on Domino. Generally, you only need to release the database and session. Syntax: database. Recycle (), session. Recycle ();
*
*
*
*
* @ Author songlb
*
*/
Public class sendmaillotus {
Private richtextitem RRTI = NULL;
Private document memo = NULL;
Private session snotes = NULL;
Private Database dbmail = NULL;
Public Boolean attachflag = false;
/** Log File */
Static org. Apache. log4j. Logger log = org. Apache. log4j. Logger
. Getlogger (sendmaillotus. Class );
Public sendmaillotus (){
}
Public void startsend (long userid, string [] to, string from,
String smtpserver, string popserver, string subject, int interval,
Int prioritylevel, date datesent, string probehost, string user,
String password, string returnstate, string cawtoargument,
Int attachedsize, string sqlserver) throws alarmexception {
Try {
// Snotes = (Session) notesfactory. createsession (smtpserver, user, password );
String strior = notesfactory. getior (smtpserver );
Snotes = notesfactory. createsessionwithior (strior, user, password );
Dbmail = (database) snotes. getdatabase (snotes. getservername (),
"Mail //" + User + ". nsf", false );
{
If (dbmail = NULL ){
Log. Error ("unable to open user database file" + User + ". nsf ");
} Else {
Memo = (document) dbmail. createdocument ();
Memo. appenditemvalue ("form", "memo ");
Subject = "good mail! ";
Memo. appenditemvalue ("subject", subject );
RRTI = (richtextitem) memo. createrichtextitem ("body ");
Ti. addnewline (2 );
Ti. appendtext ("test mail! ");
String attachfilepath = "Location of attachments on the Domino server ";
Java. util. Vector v = new java. util. vector ();
V. addelement (to [0]); // recipient
Memo. setencryptonsend (true );
Memo. setsavemessageonsend (true );
Memo. setsignonsend (true );
Memo. Sign ();
If (attachflag &&(! Attachfilepath. Trim (). Equals (""))){
Ti. embedobject (embeddedobject. embed_attachment, null,
Attachfilepath, attachfilepath); // Add an attachment
}
Memo. setsavemessageonsend (true );
Memo. Send (true, V );
}
}
Stringbuffer TMP = new stringbuffer ();
For (Int J = 0; j <to. length; j ++ ){
TMP. append ("");
TMP. append (to [J]);
}
Java. util. Date enddate = new date ();
Log.info ("email sent successfully! ");
Maildatabase. insertmailsent (userid, sqlserver, from,
TMP. tostring (), smtpserver, popserver, subject, interval,
Prioritylevel, datesent, enddate, probehost, attachedsize,
Returnstate, null, null );
} Catch (notesexception e ){
Log. Error ("failed to send Lotus mail:" + (Lotus. Domino. notesexception) e). Text );
} Catch (exception ex ){
Log. Error ("failed to send Lotus mail:" + ex );
} Finally {
Try {
If (snotes! = NULL ){
If (dbmail! = NULL ){
Dbmail. Recycle ();
}
Snotes. Recycle (); // You must disable it. Otherwise, the server will crash.
Dbmail = NULL;
Snotes = NULL;
// Log.info ("============= Lotus version:" + snotes. getnotesversion ());
}
} Catch (notesexception ex1 ){
Log. Error ("An error occurred while closing the session! ");
} Catch (exception e ){
E. printstacktrace ();
}
}
}
Public static void main (string [] ARGs ){
Sendmaillotus send = new sendmaillotus ();
Proxyhandler. Test ();
Try {
String [] P = new string [1];
P [0] = "song2c@sohu.com ";
For (INT I = 0; I <3; I ++ ){
Send. startsend (1, P, "mailtest", "10.68.100.233 ",
"10.68.100.233", "Why I's check it! ", 20, 1,
New Date (), "127.0.0.1", "mailtest", "password", "0 ",
"0", 0, "127.0.0.1 ");
}
} Catch (exception ex ){
Ex. printstacktrace ();
}
Log.info ("Access ended! ");
}
}