solarissf 0 Newbie Poster

Hello All,

I've been scouring the internet for code on sending email through lotus notes and this is what I found:

static void SendNotesErrorMail( string err, string file) 
{
    //Pass in file name 
    string filename = file; 
    //Pass in error message from TryCatch 
    string errMessage = err; 
    //Create new notes session 
    NotesSession _notesSession = new NotesSession(); 
    //Initialize Notes Database to null; nothing in VB. 
    NotesDatabase _notesDataBase = null; 
    //Initialize Notes Document to null; nothing in VB. 
    NotesDocument _notesDocument = null; 
    //Notes Server Name in form of: ServerName/Domain. 
    string sServerName = ConfigurationManager.AppSettings [ "ServerName" ]; 

    //Mail File is in form of: mail\\userName.nsf 
    string sMailFile = ConfigurationManager.AppSettings [ "MailFile" ]; 
    string password = ConfigurationManager.AppSettings [ "Password" ]; 
    string sSendTo = ConfigurationManager.AppSettings [ "SendTo" ]; 
    string sSubject = "Billing Error"; 
    //required for send, since it's byRef and not byVal, gets set later. 
    object oItemValue = null; 
    //use string array to CC Send 
    string[] sCopyTo = new string[4]; 
    sCopyTo [ 0 ] = 
        ConfigurationManager.AppSettings [ "Recipient0" ]; 
    sCopyTo [ 1 ] = 
        ConfigurationManager.AppSettings [ "Recipient1" ]; 
    sCopyTo [ 2 ] = 
        ConfigurationManager.AppSettings [ "Recipient2" ]; 
    sCopyTo [ 3 ] = 
        ConfigurationManager.AppSettings [ "Recipient3" ]; 
    //Initialize Notes Session 
    _notesSession.Initialize(password);

    //Get Database via server name & c:\notes\data\mailfilename.nsf 
    //if not found set to false to not create one 
    _notesDataBase = _notesSession.GetDatabase(sServerName, sMailFile, 
        false); 

    //If the database is not already open then open it. 
    if ( !_notesDataBase.IsOpen ) 
    {
        _notesDataBase.Open( );
    }

    //Create the notes document 
    _notesDocument = _notesDataBase.CreateDocument();

    //Set document type 
    _notesDocument.ReplaceItemValue(
        "Form", "Memo"); 

    //sent notes memo fields (To: CC: Bcc: Subject etc) 
    _notesDocument.ReplaceItemValue(
        "SendTo", sSendTo); 
    _notesDocument.ReplaceItemValue(
        "CopyTo", sCopyTo); 
    _notesDocument.ReplaceItemValue(
        "Subject", sSubject); 

    //Set the body of the email. This allows you to use the appendtext 
    NotesRichTextItem _richTextItem = _notesDocument.CreateRichTextItem("Body"); 

    //add lines to memo email body. the \r\n is needed for each new line. 
    _richTextItem.AppendText(
        "Error: " + errMessage + "\r\n"); 
    _richTextItem.AppendText(
        "File: " + filename + "\r\n"); 
    _richTextItem.AppendText(
        "Resolution: " + resolution + "\r\n"); 
    //send email & pass in byRef field, this case SendTo (always have this, 

    //cc or bcc may not always be there. 
    oItemValue = _notesDocument.GetItemValue( 
        "SendTo" ); 
    _notesDocument.Send(
        false, ref oItemValue); 

    //release resources. 
    _richTextItem = 
        null; 
    _notesDocument = 
        null; 
    _notesDataBase = 
        null; 
    _notesSession = 
        null; 
}

which I do not understand nor can I make work... does anyone know any simpler code for sending email?

thanks