Exemplo n.º 1
0
        public void AddDkimHeader(System.Net.Mail.MailMessage message)
        {
            if (string.IsNullOrWhiteSpace(GlobalConfiguration.Configuration.DkimPrivateKey))
            {
                return;
            }
            if (message.From.Host != GlobalConfiguration.Configuration.DkimDomain)
            {
                return;
            }

            try
            {
                var privateKey   = DKIM.PrivateKeySigner.Create(GlobalConfiguration.Configuration.DkimPrivateKey);
                var headerToSign = new string[] { "From", "To", "Subject" };

                var domainKeySigner = new DKIM.DomainKeySigner(privateKey,
                                                               GlobalConfiguration.Configuration.DkimDomain,
                                                               GlobalConfiguration.Configuration.DkimSelector,
                                                               headerToSign);

                var dkimSigner = new DkimSigner(privateKey,
                                                GlobalConfiguration.Configuration.DkimDomain,
                                                GlobalConfiguration.Configuration.DkimSelector,
                                                headerToSign);


                message.DomainKeySign(domainKeySigner);
                message.DkimSign(dkimSigner);
            }
            catch (Exception ex)
            {
                ex.Data.Add("domain", GlobalConfiguration.Configuration.DkimDomain);
                ex.Data.Add("from", message.From.Address);
                foreach (var emailTo in message.To)
                {
                    ex.Data.Add(string.Format("to{0}", message.To.IndexOf(emailTo)), emailTo.Address);
                }
                ex.Data.Add("subject", message.Subject);
                GlobalConfiguration.Configuration.Logger.Error(ex);
            }
        }
Exemplo n.º 2
0
        public void Valid_send_sign_DKIM(string headers)
        {

            var msg = new MailMessage();
            msg.To.Add(new MailAddress(_to, "Jim Bob"));
            msg.From = new MailAddress(_from, "Joe Bloggs");
            msg.Subject = "Test DKIM Message";
            msg.Body = "A simple message";


            var dkimSigner = new DkimSigner(PrivateKeySigner.Create(_privateKey), _domain, _selector, GetHeaders(headers));

            msg.DkimSign(dkimSigner);

            var smtp = new SmtpClient();

            smtp.Send(msg);



        }