+1 vote

I need in an other time write a soft can send email with TLS, this email must it signed and encrypted with SSL private key instal on my computer.(private cert)
Can i use your Mail.dll lib for signed and encrypted my mail ?

by

1 Answer

0 votes
 
Best answer

Hi Julien,

It seems to me you are confusing 2 things:

  1. Establishing an encrypted connection to the server (using SSL/TLS protocol)
  2. Encrypting and signing a message itself (S/MIME)

The first one you achieve using ConnectSSL method:
https://www.limilabs.com/blog/use-ssl-with-imap
https://www.limilabs.com/blog/use-ssl-with-smtp

If you are confused about SSL, TLS, StartTLS here's a good article to help you:
https://www.limilabs.com/blog/ssl-vs-tls-vs-starttls-stls

The second is also easy. You need to tell MailBuilder, while building an email, to sign and encrypt a message using X509Certificate2 certificate:

MailBuilder builder = new MailBuilder();
builder.Html = "<html><body>Encrypted and signed</body></html>";
builder.Subject = "Encrypted and signed";
builder.From.Add(new MailBox("alice@example.com", "Alice"));
builder.To.Add(new MailBox("bob@example.com", "Bob"));
builder.AddAttachment(@"c:\report_2014.pdf");

builder.SignWith(new X509Certificate2("AliceSignCertificate.pfx", ""));
builder.EncryptWith(new X509Certificate2("AliceCertificate.pfx", ""));
builder.EncryptWith(new X509Certificate2("BobsCertificate.pfx", ""));

IMail email = builder.Create();

Now you can send this message:

using (Smtp client = new Smtp())
{
    client.ConnectSSL("smtp.example.com");
    client.UseBestLogin("alice", "password");
    client.SendMessage(email);
    client.Close();
}

You can find all SMIME samples here:
https://www.limilabs.com/mail/samples#smime-dkim

The one that will be most accurate is here:
https://www.limilabs.com/blog/send-encrypted-email-using-smime

by (298k points)
...