Search code examples
c#emaillotus-dominolotus

c# save sent email in Lotus Sent folder (domino interop)


I'm trying to solve a little stuck in my code. I'm sending email via Domino server, all mails were successfully sent, but mail is not visible in Sent email in Lotus Notes at all. Can you help me? Thanks

                    NotesSession notesSession = new NotesSession();
                    notesSession.Initialize(passw);
                    NotesDatabase nd = notesSession.GetDatabase("","names.nsf", bCreateonfail: false);

                    if (!nd.IsOpen)
                    {
                        nd.Open();
                    }

                    NotesDocument notesDocument = nd.CreateDocument();

                    notesDocument.SaveMessageOnSend = true;



                    notesDocument.ReplaceItemValue("Form", "Main Topic");

                    // set notes memo fields (To: CC: Bcc: Subject etc) 
                    notesDocument.ReplaceItemValue("SendTo", emailSup);



                    notesDocument.ReplaceItemValue("CopyTo", copyTo);


                    // Subject is the name of pdf file without .pdf
                    notesDocument.ReplaceItemValue("Subject", pdfFiles[i].Remove(pdfFiles[i].Length - 4, 4));

                    // Create the body of the email. This allows you to use the appendtext 
                    NotesRichTextItem richTextItem = notesDocument.CreateRichTextItem("Body");


                    //Path of attachment (pdf file)
                    string AttachPath = @"c:\...\PDF\" + pdfFiles[i];
                    string txtPath = @"c:\...\emailtxt.txt";
                    System.IO.StreamReader txt = new System.IO.StreamReader(txtPath, Encoding.GetEncoding("windows-1250"));

                    // Add email text from txt file.  
                    richTextItem.AppendText(txt.ReadToEnd());

                    // Attach file to e-mail
                    NotesEmbeddedObject obj_notesEmbeddedObject = richTextItem.EmbedObject(EMBED_TYPE.EMBED_ATTACHMENT, "", AttachPath, "Attachment");

                    notesDocument.SaveMessageOnSend = true;
                    notesDocument.Save(true, false);

                    notesDocument.Send(false);

Solution

  • You are creating a database object:

    NotesDatabase nd = notesSession.GetDatabase("","names.nsf", bCreateonfail: false);
    

    Then you are creating a document object in that database object:

     NotesDocument notesDocument = nd.CreateDocument();
    

    And then you are saving the document object in that database object:

     notesDocument.Save(true, false);
    

    Do you see the problem?

    You are saving the document in names.nsf on the local machine where your code is running. If you look in a view in names.nsf that selects @All, you will find it there.