1

我正在尝试按照 RFC1847 协议创建一个多部分/签名的 mime 电子邮件。这是它应该看起来的样子(部分签名被删除):

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

我无法弄清楚如何实际将其作为电子邮件发送。我正在使用 MailMessage 并尝试按如下方式添加它:

var stream = new MemoryStream(Encoding.ASCII.GetBytes(message));
var view = new AlternateView(stream, "application/pkcs7-mime; smime-type=signed-data;name=smime.p7m");

但是它不起作用。MailMessage 添加不同的标题并将其全部搞砸。

我怎样才能正确发送这个?

4

1 回答 1

0

我不再使用 MailMessage 类,因为我无法让它工作。相反,我使用的是 EWS 托管 api,如下所示:

var mail = new EmailMessage(_service);
mail.Subject = filename;
mail.MimeContent = new MimeContent("us-ascii", Encoding.ASCII.GetBytes(messageContentWithHeaders));
mail.SendAndSaveCopy();
于 2013-07-31T14:33:58.107 回答