0 votes

How do I sign email with attachment with DKIM (DomainKeys Identified Mail) using your library?

by
retagged by

1 Answer

0 votes
 
Best answer
  1. First you need to obtain private and public key for DKIM purposes.
  2. Then you need to create DNS record for DKIM.
  3. Final step is sending signed message.

For details on 1 and 2 please follow the steps described in sign emails with DKIM.

Step 3 is very simple.

Note the usage of PemReader class that reads "dkim_private.key" file obtained from OpenSSL's key generation. Also note that attachment is added to the email (*AddAttachment*):

MailBuilder builder = new MailBuilder();
builder.Subject = "Hello";
builder.Text = "Hello";
builder.From.Add(new MailBox("alice@example.com"));
builder.To.Add(new MailBox("bob@mail.com"));
builder.AddAttachment(@"c:\report.csv");

RSACryptoServiceProvider rsa = 
    new PemReader().ReadPrivateKeyFromFile(@"d:\dkim_private.key");    
builder.DKIMSign(rsa, "alpha", "example.com");

IMail email = builder.Create();

using(Smtp smtp = new Smtp())
{
    smtp.Connect("smtp.example.com");  // or ConnectSSL for SSL
    smtp.UseBestLogin("alice@example.com", "password");
    smtp.SendMessage(email);                     
    smtp.Close();   
} 

There are several ways of adding attachment to the DKIM signed email (byte[] array, filename).

by (300k points)
...