Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I use below code to send mail with attachments from a Lotus Notes client to internet mailboxes.

All of other mailboxes work well with this code, however when my mail send to Microsoft Exchange 2010 and Outlook the attachment has been parsed to garbled languages in text body. I tried many ways but couldn't fix.

I need an urgent suppport from you to help me fix this issue.

Domino.NotesDocument oNotesDocument = null;
            object oItemValue = null;
            
            try
            {
                //Create an in memory document in the server database
                oNotesDocument = m_notesDatabase.CreateDocument();

                //Assign Field Values
                oNotesDocument.ReplaceItemValue("Form", "Memo");
                oNotesDocument.ReplaceItemValue("From", msgData.FromMail);
                oNotesDocument.ReplaceItemValue("SendTo",
                    msgData.ToMail.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries));

                if (!String.IsNullOrEmpty(msgData.ReplyTo))
                {
                    oNotesDocument.ReplaceItemValue("ReplyTo", msgData.ReplyTo);
                }
                if (!String.IsNullOrEmpty(msgData.Principal))
                {
                    oNotesDocument.ReplaceItemValue("Principal", msgData.Principal);
                }
                if (!string.IsNullOrEmpty(msgData.CcAddresses))
                {
                    oNotesDocument.ReplaceItemValue("CopyTo",
                        msgData.CcAddresses.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries));
                }
                oNotesDocument.ReplaceItemValue("Subject", msgData.Subject);

                Domino.NotesRichTextItem rtItem = oNotesDocument.CreateRichTextItem("Body");

                FormatMessge(rtItem, msgData.Body);

                rtItem.AddNewLine(2, true);

                //attach file       
                if (msgData.AttachedFile != null)
                {
                    foreach (string fileName in msgData.AttachedFile)
                    {                        
                        rtItem.EmbedObject(EMBED_TYPE.EMBED_ATTACHMENT, "",
                                           fileName, "");
                    }
                    
                }
                

                              

                //Save to "Sent" folder
                oNotesDocument.SaveMessageOnSend = true; //Ensure memo shows in sent folder
                oNotesDocument.ReplaceItemValue("postDate", DateTime.Now);
                //Send requires an object for the recipients, so I give the send method the SendTo field as an object.
                oItemValue = oNotesDocument.GetItemValue("SendTo");
                //Send the email
                // oNotesDocument.Send(false, ref oItemValue);

                return true;
            }
            catch (System.Exception error)
            {
                throw error;
            }
            finally
            {   
                oNotesDocument = null;
                oItemValue = null;
                GC.Collect();
            }
Posted
Updated 4-Sep-15 2:29am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900