Reputation: 11569
Is there any built in functionality to MIME a file in C# .Net? What I am looking to do is:
Any suggestions on how I would go about this (not the encryption or signing part but the MIMEing)? What exactly is envolved in MIMEing a file?
Upvotes: 3
Views: 11970
Reputation: 1832
Something that hasn't been mentioned is MimeKit. It does everything that you need it to do.
(this is still a top hit in google so thought I'd add this gem)
Upvotes: 0
Reputation: 5823
As far as I know there is no such support in the bare .NET. You have to try one of third party libraries. One of them is our Rebex Secure Mail for .NET. Following code shows how to achieve it:
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 = "[email protected]";
message.To = "[email protected]";
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)
(Code taken from the S/MIME tutorial page)
Upvotes: 2
Reputation: 56409
Rather than deal with third party libraries, I suggest you look to the core .NET library. Use the Attachment class; it's been around since .NET 2.
Upvotes: 2