在C#.Net中有没有内置的MIME文件功能?我要做的是:
关于我将如何处理此问题的任何建议(不是加密或签名部分,而是MIMEing)? MIME文件中究竟包含哪些内容?
答案 0 :(得分:2)
答案 1 :(得分:2)
答案 2 :(得分:2)
据我所知,在.NET中没有这样的支持。你必须尝试第三方库之一。其中一个是我们的Rebex Secure Mail for .NET。以下代码显示了如何实现它:
using Rebex.Mail;
using Rebex.Mime.Headers;
using Rebex.Security.Certificates;
...
// load the sender's certificate and
// associated private key from a file
Certificate signer = Certificate.LoadPfx("hugo.pfx", "password");
// load the recipient's certificate
Certificate recipient = Certificate.LoadDer("joe.cer");
// create an instance of MailMessage
MailMessage message = new MailMessage();
// set its properties to desired values
message.From = "hugo@example.com";
message.To = "joe@example.com";
message.Subject = "This is a simple message";
message.BodyText = "Hello, Joe!";
message.BodyHtml = "Hello, <b>Joe</b>!";
// sign the message using Hugo's certificate
message.Sign(signer);
// and encrypt it using Joe's certificate
message.Encrypt(recipient);
// if you wanted Hugo to be able to read the message later as well,
// you can encrypt it for Hugo as well instead - comment out the previous
// encrypt and uncomment this one:
// message.Encrypt(recipient, signer)
(代码取自S/MIME tutorial page)