0 votes
by (160 points)
edited

Please let me know how to create a MDN message. i had tried with creating a new email and adding followinf headers to it:-

mess.Headers.Add("Content-Type", "message/disposition-notification");
mess.Headers.Add("Content-Disposition", "inline");
mess.Headers.Add("Content-Transfer-Encoding", "7bit");
mess.Headers.Add("Original-Message-ID", "<--MESSAGEID-->");
mess.Headers.Add("Disposition", "automatic-action/MDN-sent-automatically;processed");
mess.Headers.Add("Final-Recipient", "rfc822;some@domain.com");

Please provide help in this case.

Regards, Rakesh Rai

Applies to: Rebex Secure Mail

1 Answer

0 votes
by (147k points)
edited

Most of the Content-Something headers cannot be added like this. Please try using the appropriate methods instead, like this:

        byte[] content = Encoding.ASCII.GetBytes("<--MESSAGECONTENT-->");
        var contentStream = new MemoryStream(content, false);

        var mess = new MimeMessage();
        mess.ContentDisposition = new ContentDisposition("inline");
        mess.SetContent(contentStream, null, "message/disposition-notification", TransferEncoding.SevenBit);
        mess.Headers.Add("Original-Message-ID", "<--MESSAGEID-->");
        mess.Headers.Add("Disposition", "automatic-action/MDN-sent-automatically;processed");
        mess.Headers.Add("Final-Recipient", "rfc822;some@domain.com");

        mess.Save(@"c:\temp\mdn-sample.eml");

If you have a sample of the kind of a message you would like to create, please post it as well - we will let you know how to create an equivalent message using Rebex Secure Mail.

by (160 points)
edited

I had tried with the above example but now i am getting new error that is "malformed content". My requiremnt is MDN should be encrypted and signed. Below is my code:

MailMessage mess1 = new MailMessage(); mess1.Load(@"c:\Test\mdn-sample.eml"); Certificate recipient = Certificate.LoadDer("Loading receipient certificate"); Certificate signer = Certificate.LoadPfx("Loading Signing Certificate"); mess1.Encrypt(recipient); mess1.Sign(signer); mess1.Save(@"c:\Test\mdn-sample1.eml");

Please let me where i need to change the code.

Regards, Rakesh Rai

by (160 points)
edited

Below is the Message looks like :-

From: <sender address=""> To: <recipient address=""> Original-Message-ID: ORIGINALMESSAGEID Disposition: automatic-action/MDN-sent-automatically;processed MIME-Version: 1.0 Content-Type: application/pkcs7-mime; name="smime.p7m"; smime-type="signed-data" Content-Transfer-Encoding: base64

----- BASE 64 MESSAGE ------

...