コード例 #1
0
        public void Valid_send_sign_DomainKey_then_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 DomainKeys & DKIM Message";
            msg.Body    = "A simple message";



            var domainKeySigner = new DomainKeySigner(PrivateKeySigner.Create(_privateKey), _domain, _selector, GetHeaders(headers));

            msg.DomainKeySign(domainKeySigner);


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

            msg.DkimSign(dkimSigner);



            var smtp = new SmtpClient();

            smtp.Send(msg);
        }
コード例 #2
0
        public void Create()
        {
            var s = PrivateKeySigner.Create(PrivateKey);


            s.Sign(Encoding.Default.GetBytes("some text to sign."), SigningAlgorithm.RSASha1);
        }
コード例 #3
0
        public void TestInitialize()
        {
            Message = new System.Net.Mail.MailMessage();
            Message.To.Add(new MailAddress("*****@*****.**", "Jim Bob"));
            Message.From    = new MailAddress("*****@*****.**", "Joe Bloggs");
            Message.Subject = "Test DKIM Message";
            Message.Body    = "A simple message";

            Smtp = new SmtpClient();
            Smtp.DeliveryMethod          = SmtpDeliveryMethod.SpecifiedPickupDirectory;
            Smtp.PickupDirectoryLocation = Path.GetTempPath();

            DkimSigner      = new DkimSigner(PrivateKeySigner.Create(PrivateKey), "acme.com", "dkim", GetHeaders("From,To,Subject"));
            DomainKeySigner = new DomainKeySigner(PrivateKeySigner.Create(PrivateKey), "acme.com", "dkim", GetHeaders("From,To,Subject"));
        }
コード例 #4
0
        private static bool SendEmailInternal(string to, string subject, string body, string replyToName, string replyToEmail)
        {
            try
            {
                if (Debugger.IsAttached || Configuration.GetSMTPUserName().IsNullOrEmpty())
                {
                    HttpContext.Current.Response.Write(subject + " " + body);
                    return(false);
                }

                var privateKey = PrivateKeySigner.Create(Configuration.GetDomainKey());

                using (var client = new SmtpClient())
                {
                    var message = new MailMessage();
                    message.To.Add(new MailAddress(to));

                    if (!replyToEmail.IsNullOrEmpty())
                    {
                        ActionExtensions.TryAction(() => message.ReplyToList.Add(new MailAddress(replyToEmail, replyToName)));
                    }

                    message.From       = new MailAddress("*****@*****.**", "rssheap");
                    message.Subject    = subject;
                    message.Body       = body;
                    message.IsBodyHtml = true;

                    var domainKeySigner = new DomainKeySigner(privateKey, "rssheap.com", "abc", new string[] { "From", "To", "Subject" });
                    message.DomainKeySign(domainKeySigner);

                    var dkimSigner = new DkimSigner(privateKey, "rssheap.com", "abc", new string[] { "From", "To", "Subject" });
                    message.DkimSign(dkimSigner);

                    client.Host = "192.99.232.179";
                    client.Port = 25;
                    client.UseDefaultCredentials = false;
                    client.Credentials           = new NetworkCredential(Configuration.GetSMTPUserName(), Configuration.GetSMTPPassword());
                    client.EnableSsl             = false;

                    client.Send(message);
                }
            }
            catch
            {
                return(false);
            }
            return(true);
        }
コード例 #5
0
        public static void SendEmailWithDKIP(string subject, string body)
        {
            if (Configuration.GetSMTPUserName().IsNullOrEmpty())
            {
                return;
            }

            var privateKey = PrivateKeySigner.Create(Configuration.GetDomainKey());

            var msg = new MailMessage();

            msg.To.Add(new MailAddress("*****@*****.**"));
            msg.From    = new MailAddress("*****@*****.**", "rssheap");
            msg.Subject = subject;
            msg.Body    = body;

            var domainKeySigner = new DomainKeySigner(privateKey, "rssheap.com", "abc", new string[] { "From", "To", "Subject" });

            msg.DomainKeySign(domainKeySigner);

            var dkimSigner = new DkimSigner(privateKey, "rssheap.com", "abc", new string[] { "From", "To", "Subject" });

            msg.DkimSign(dkimSigner);

            var client = new SmtpClient
            {
                Host = "192.99.232.179",
                Port = 25,
                UseDefaultCredentials = false,
                Credentials           = new NetworkCredential(Configuration.GetSMTPUserName(), Configuration.GetSMTPPassword()),
                EnableSsl             = false
            };

            try
            {
                client.Send(msg);
            }
            catch
            {
                string bp = string.Empty;
            }
        }
コード例 #6
0
        public void Create()
        {
            var s = PrivateKeySigner.Create(
                @"-----BEGIN RSA PRIVATE KEY-----
MIICXAIBAAKBgQDcruApwJruvr9GHYMnUlkOevmczah961FxiQXu7JwHiepKGkVf
9f8DvzSiMprrqoR14f4puAi5PAG+MBxkvbAMI/kCc57E8nEN4ZGxKPRtuhiY6bsP
SpxI7LXgHqlt/yOFrJNdTjSwGpAlVfNMd3BnP2RSlHgj58ZSwYYhG15OmQIDAQAB
AoGAKOVbc0FXNOEybxrvAC15hX5ynYVbMSKXsDOVXuaIL7l2Ko9dxd+/h4E6jshT
/1JVQ8dCo5aQP0uIgydFS8H/SpiAqCEAPKUOCObcBH9O81yBSxUOcZCkv0y2Qsah
qZE0f4lYTxGYWZYC2GMZXt+cMHX528xEEg7UIHaR4U/hG/UCQQD3o8HcZcWR13rY
DcNLwZ+G1TW/OTtfz/5bd8GeGBELUs4TKBV8dQqdxkpkcmCOLwCfETcnlBvyH6OT
LxnpAWDnAkEA5CIk9r5JBRqz9tdknTyHmSok1ENsBM1uQ88b2TyEdODebe/mCZ6H
MJnp/qQEnZ+/UlkZJW/cI6QLFxqj6+NkfwJBAN34szRTJRztAPfYnk2xaMT7KAoX
yti/H0ftuGd1OxHjT0RskZXVc4aoztXqkBHin7P1QnL/l20YXw73EUqCKdECQEvf
HzQArQBJlTivAgNZMi+6WG1Pzwj52YYrxzNEcTj94HvnoTXpx0Req/fITNCvZE3a
3AYbYbdow1d3wLSe97kCQGfHreVl7MWOEk/5y0NASxaolY4+aFoXLwkGe1qIN2Vu
xsjBBm9osDHsFVIuggd4fYKj05IWA6jX4z1LiRnLvVc=
-----END RSA PRIVATE KEY-----");


            s.Sign(Encoding.Default.GetBytes("some text to sign."), SigningAlgorithm.RSASha1);
        }
コード例 #7
0
        public void SendSignedEmail()
        {
            var message = new MailMessage();



            message.To.Add(new MailAddress("*****@*****.**", "Port25"));



            message.From = new MailAddress(ConfigurationManager.AppSettings["from"]);

            message.Subject = @"test©";
            // message contains white space
//            message.Body = @"abc©
// ©   ©
// ©
//
//
//";

//            message.IsBodyHtml = false;


//            message.Body = @"
//line 1
//
//line 2
//
//line 3";


            message.AlternateViews.Add(AlternateView.CreateAlternateViewFromString("text", Encoding.ASCII, "text/plain"));
            message.AlternateViews.Add(AlternateView.CreateAlternateViewFromString("html", Encoding.ASCII, "text/html"));



            var privateKey = PrivateKeySigner.Create(ConfigurationManager.AppSettings["privatekey"], SigningAlgorithm.RSASha1);

            var dkim = new DkimSigner(
                privateKey,
                ConfigurationManager.AppSettings["domain"],
                ConfigurationManager.AppSettings["selector"],
                new string[] { "From", "To", "Subject" }
                );



            var debugger = new ConsoleDebug();

            dkim.Debug                = debugger;
            dkim.Encoding             = Encoding.ASCII;
            dkim.BodyCanonicalization = DkimCanonicalizationAlgorithm.Relaxed;



            var signedMessage = dkim.SignMessage(message);


            var text = signedMessage.GetText();

            debugger.WriteLine();
            debugger.WriteContent("dkim", text);



            //    var domainkey = new DomainKeySigner(
            //privateKey,
            //ConfigurationManager.AppSettings["domain"],
            //ConfigurationManager.AppSettings["selector"],
            //new string[] { "From", "To", "Subject" }
            //);

            //signedMessage = domainkey.SignMessage(signedMessage);

            //text = signedMessage.GetText();
            //debugger.WriteContent("domainkey", text);

            new SmtpClient().Send(signedMessage);
        }