0

I'm using C# / Visual Studio 2012 to create an email process that replies to the sender of an email with their original email as an attachment. I do this when an error occurs while processing the email that they send. I'm using the stock .NET System.Net.Mail.MailMessage and System.Net.Mail.SmtpClient.

I take the original email eml, and construct a MemoryStream with the contents of the email eml:

memStream = new MemoryStream(Encoding.ASCII.GetBytes(exception.EmailEml));
memStream.Seek(0, SeekOrigin.Begin);

I then construct an email and try adding the attachment as follows:

 message.Attachments.Add(new Attachment(contentStream,
                    System.Net.Mime.MediaTypeNames.Text.Plain));
                message.Attachments[0].Name = subject + ".msg";

In Outlook, I see the message as an attachment, but Outlook isn't able to open the attachment. I get an error from Outlook...

Is it simply just a matter of setting the correct MIME type so that the .MSG attachment opens in Outlook, or is it something else that I need to do?

When I review the .msg attachment within a text editor, I see the following in the header:

Received: from server.com ([___]) by
 server.com ([___]) with mapi id
 ___; Mon, 25 Mar 2013 23:00:20 -0400
From: Me <myemailaddy>
To: Server Side Mailbox Process <processemailaddy>
Subject: subject text
Thread-Topic: Topic text
Thread-Index: Ac4pzgz84kK07LIdQ+uIR67iWBoSxw==
Date: Mon, 25 Mar 2013 23:00:20 -0400
Message-ID:
 <[email protected]>
Accept-Language: en-US
Content-Language: en-US
X-MS-Exchange-Organization-AuthAs: Internal
X-MS-Exchange-Organization-AuthMechanism: 04
X-MS-Exchange-Organization-AuthSource: server.com
X-MS-Has-Attach:
X-MS-Exchange-Organization-SCL: -1
X-MS-TNEF-Correlator:
Content-Type: text/html; charset="us-ascii"
MIME-Version: 1.0

Thanks!

5
  • what API you use to send the message? I see you quoted Outlook, but various API can use the default email client in windows.
    – jay
    Mar 26, 2013 at 6:17
  • Hi Jay, I'm using System.Net.Mail.MailMessage and System.Net.Mail.SmtpClient Mar 26, 2013 at 12:29
  • I figured out that my attachment is in eml format...per my answer below. So no need to investigate this one further, thanks! Mar 26, 2013 at 15:07
  • If you solve your own question, you should click the check mark next to your answer, not put "solved" in the title. Clicking the check mark makes it solved in the UI, changing the title does not. Mar 26, 2013 at 16:14
  • Thank you for the tip Dour High Arch. I had tried that beforehand and stackoverflow reported a user error message back to me saying "You can accept your own answer tomorrow". Hence I figured I'd indicated "Solved" in the title to let you and others know not to bother wasting your time on the question. Mar 26, 2013 at 16:57

1 Answer 1

1

My bad, the email source was in eml format. I am attaching the file to the email with an eml extenion now. The critical path in this case is working now with this approach!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.