duke_swh -2 Newbie Poster

Hi,

I'm trying to send an email using a lotus notes account and c# which is working fine. It is a two part mail which consistes of an HTML formatted message and attachment/s. The problem i'm encountering is when I have multiple attachments in different file formats. For example when I attach an excel file(first attachment) and a word file(second attachment), when the recepient gets the mail the first attachment opens perfectly fine but the second attachment gives an error of incorrect format. But if I attach the same file types(2 excel files or 2 word files), both files are opening perfectly.

This is the code i'm using:

public static void sendLotusFormat()

{

Domino.NotesSession session = new Domino.NotesSession();

string password = "<lotusmailpassword>";

session.Initialize(password);

object itemvalue = null;

String mailServer = ConfigurationManager.AppSettings["lotusmailserver"];

String mailFile = "<path to names.nsf>";

Domino.NotesDatabase email = session.GetDatabase(mailServer, mailFile, false);

if (!email.IsOpen) email.Open();

Domino.NotesDocument memo = email.CreateDocument();

memo.ReplaceItemValue("Form", "Memo");

memo.ReplaceItemValue("Subject","Subject");

string mess = someHTMLformattedmessage;

memo.ReplaceItemValue("SendTo", mailaddress);

memo.SaveMessageOnSend = true;

itemvalue = memo.GetItemValue("SendTo");

session.ConvertMime = false;

Domino.NotesStream stream = session.CreateStream();

stream.WriteText(mess, Domino.EOL_TYPE.EOL_ANY);

Domino.NotesMIMEEntity mimeBody = memo.CreateMIMEEntity("Body");

Domino.NotesMIMEEntity mimeHtml = mimeBody.CreateChildEntity(null);

Domino.NotesMIMEHeader header = mimeBody.CreateHeader("Subject");

//For the HTML part of the message

mimeHtml.SetContentFromText(stream, "text/html; charset=\"iso-8859-1\"", Domino.MIME_ENCODING.ENC_QUOTED_PRINTABLE);

stream.Close();

stream.Truncate();



if (file.Count > 0)

{

String fileName = "";

//This is for looping through an arraylist with names of the files to be attached

foreach (string i in file)

{

fileName =i.Substring(i.LastIndexOf("\\") + 1);

mimeHtml = mimeBody.CreateChildEntity(null);

header = mimeHtml.CreateHeader("Content-Disposition");

header.SetHeaderVal("attachment; filename=" + fileName);

header = mimeHtml.CreateHeader("Content-ID");

header.SetHeaderVal(fileName);

stream = session.CreateStream();

if (stream.Open(i, "binary"))

{

mimeHtml.SetContentFromBytes(stream, "application/octet-stream", Domino.MIME_ENCODING.ENC_IDENTITY_BINARY);

mimeHtml.EncodeContent(MIME_ENCODING.ENC_BASE64);

}

stream.Close();

stream.Truncate();

}

}