logo

New Response

« Return to the blog entry

You are replying to:

    • avatar
    • Jie Cerbo
    • Posted on Sun 14 Aug 2011 04:35 AM

    I know this is an old thread but I hope somebody can still help me.

    I have done something similar in C#. However I'm encountering an issue when i am attaching multiple files with different file types. For example, I am attaching an excel file and a word file. When the mail is received in lotus notes client only the first attachment can be opened, the second attachment gives an error that the file is in a different format. Following 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();

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

    if (file.Count > 0)

    {

    String fileName = "";

    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();

    }

    }

    memo.Send(false, ref itemvalue);

    memo.Save(true, false, false);

    stream.Close();

    session.ConvertMime = true;

    memo.CloseMIMEEntities(true, "Body");

    memo.ComputeWithForm(true, false);

    }

    ********

Your Comments

Name:
E-mail:
(optional)
Website:
(optional)
Comment: