コード例 #1
0
ファイル: Program.cs プロジェクト: cuicheng11165/SMTPEmail
        private static SmtpClient GetSmtpClient(SmtpServer setting)
        {
            var client = new SmtpClient()
            {
                DeliveryMethod = SmtpDeliveryMethod.Network,
                Host           = setting.Host,
                EnableSsl      = setting.UseSSL,
                Timeout        = 18000000,
            };

            if (setting.Port > 0 && setting.Port < 65536)
            {
                client.Port = setting.Port;
            }

            if (string.IsNullOrEmpty(setting.Username) || string.IsNullOrEmpty(setting.Password))
            {
                client.UseDefaultCredentials = true;
            }
            else
            {
                var credetntial = new NetworkCredential(setting.Username, setting.Password);
                client.UseDefaultCredentials = false;
                client.Credentials           = credetntial;
            }

            return(client);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: cuicheng11165/SMTPEmail
        static void Main(string[] args)
        {
            var server = new SmtpServer {
                Host = "smtp.qq.com", Username = "******", Password = "******", Port = 25, Sender = "*****@*****.**", UseSSL = true
            };
            var smtpClient = GetSmtpClient(server);

            ServicePointManager.ServerCertificateValidationCallback = (a, b, c, d) => true;


            smtpClient.Send(server.Sender, "*****@*****.**", "123", "222");
        }