I am trying to create a multipart/signed mime email following the RFC1847 protocol. This is how it is supposed to look (part of the signature is removed):
Content-Type: multipart/signed; protocol="application/pkcs7-signature"
micalg=sha1; boundary="--PTBoundry=3"
----PTBoundry=3
Content-Type: multipart/mixed;
boundary="--PTBoundry=2"
----PTBoundry=2
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: quoted-printable
TEST AF signed
----PTBoundry=2
Content-Type: application/octet-stream;
name=test2.txt
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename=test2.txt
bWludGVzdGF0dGFjaG1lbnRzaWduZWQ=
----PTBoundry=2--
----PTBoundry=3
Content-Type: application/pkcs7-signature; name="smime.p7s"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="smime.p7s"
MIIKfAYJKoZIhvcNAQcCoIIKbTCCCmkCAQExCzAJBgUrDgMCGgUAMAsGCSqGSIb3DQEHAaCCCNow
ggPVMIICvaADAgECAgMCNtEwDQYJKoZIhvcNAQEFBQAwQjELMAkGA1UEBhMCVVMxFjAUBgNVBAoT
PrENekpgrYkz
----PTBoundry=3--
empty line
I cannot figure out how to actually send this as an email. I am using MailMessage and I have tried to add it as written below:
var stream = new MemoryStream(Encoding.ASCII.GetBytes(message));
var view = new AlternateView(stream, "application/pkcs7-mime; smime-type=signed-data;name=smime.p7m");
however it does not work. The MailMessage adds different headers and messes it all up.
How can I send this correctly?
I am no longer using the MailMessage class, because I could not get it working. Instead I am using EWS managed api like this:
var mail = new EmailMessage(_service);
mail.Subject = filename;
mail.MimeContent = new MimeContent("us-ascii", Encoding.ASCII.GetBytes(messageContentWithHeaders));
mail.SendAndSaveCopy();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.