none
[E2007][TA][C#] How to construct multipart Mime message RRS feed

  • Question

  • The EmailMessage item I am using is in the following namespace: Microsoft.Exchange.Data.Transport.Email

    I am having trouble trying to figure out how to take a .mht file and read the content into the body and have it display properly with a base64 encoded png as part of the file.

    private static SmtpServer mSmtpServer;

    var msg = EmailMessage.Create(BodyFormat.Html);

    var ndrBody = new StreamReader("MsgBodyFile.mht");
    msg.Body.MimePart.SetContentStream(ContentTransferEncoding.Unknown, ndrBody.BaseStream, CachingMode.Copy);
    msgBody.Close();
    msg.Sender = new EmailRecipient("sender", "sender@company.com");
    msg.To.Add(new EmailRecipient("Recipient", "Recipient@company.com"));
    mSmtpServer.SubmitMessage(msg);

    This is not showing up correctly but the content of the file is the body of the message as text. any Ideas?



    • Edited by T. Sweet Thursday, February 9, 2012 11:01 PM
    Thursday, February 9, 2012 10:47 PM

Answers

  • Alright, I found the overload for EmailMessage.Create wich takes a mime document, however the embeded image doesn't show up in the message properly

    var body = new MimeDocument();

    body.GetLoadStream().Write(ndrBody, 0, ndrBody.Length);

    var msg = EmailMessage.Create(body);

    • Marked as answer by T. Sweet Friday, February 10, 2012 11:42 PM
    Friday, February 10, 2012 7:19 PM
  • OK, figured out that Microsoft didn't like my document at all. I had to create a word doc email template and save is as an mht file then stip out all the crap Microsoft adds in there that is unneccesary (about 100K worth) then the message sent fine.
    • Marked as answer by T. Sweet Friday, February 10, 2012 11:41 PM
    Friday, February 10, 2012 11:41 PM

All replies

  • So i tried a different way:

    var writeStream = mgs.MimeDocument.GetLoadStream();

    but I get an exception:  "Loading into a non-empty document is not allowed."

    However, if I just create a standalone MimeDocument and use the same method to load the mime document I get all the mime parts and sections correctly.

    var body = new MimeDocument();
    body.GetLoadStream().Write(ndrBody, 0, ndrBody.Length);

    Now I just need to figure out how to get the Separate MimeDocument object into the message as the body.....

    Friday, February 10, 2012 7:07 PM
  • Alright, I found the overload for EmailMessage.Create wich takes a mime document, however the embeded image doesn't show up in the message properly

    var body = new MimeDocument();

    body.GetLoadStream().Write(ndrBody, 0, ndrBody.Length);

    var msg = EmailMessage.Create(body);

    • Marked as answer by T. Sweet Friday, February 10, 2012 11:42 PM
    Friday, February 10, 2012 7:19 PM
  • OK, figured out that Microsoft didn't like my document at all. I had to create a word doc email template and save is as an mht file then stip out all the crap Microsoft adds in there that is unneccesary (about 100K worth) then the message sent fine.
    • Marked as answer by T. Sweet Friday, February 10, 2012 11:41 PM
    Friday, February 10, 2012 11:41 PM