0
        String[] Sendto = File.ReadAllLines("SendTo.txt");
        SmtpClient X = new SmtpClient("smtp.gmail.com", 587);
        //X.UseDefaultCredentials = false;

        NetworkCredential Auth = new NetworkCredential("Someone@gmail.com", "Plainttext password");
        X.Credentials = Auth;
        X.EnableSsl = true;
        foreach (string recip in Sendto)
        {
            try
            {
                MailAddress from = new MailAddress("Someone@gmail.com");

                MailAddress to = new MailAddress(recip);
                MailMessage myMail = new MailMessage(from, to);
                myMail.Priority = MailPriority.High;
                myMail.Subject = "Your Test is Done";
                myMail.SubjectEncoding =
                myMail.BodyEncoding = System.Text.Encoding.UTF8;
                myMail.IsBodyHtml = true;
               X.Send(myMail);
            }
            catch (Exception ex)
            { Console.WriteLine(ex.Message); }

为什么这不起作用?我嗅探了流量,我确实收到了来自 smpt.google.com 的 dns 回复,但无法连接到远程服务器

4

1 回答 1

0

修改后的答案端口 993 不起作用...

对我有用的是:-

请注意,如果您有两步验证,您可能需要一个应用专用密码。

var mail = new MailMessage();

mail.From = new MailAddress("from address");
mail.To.Add("to address");
mail.Subject = "Test Mail";
mail.Body = "This is for testing SMTP mail from GMAIL";

var smtpServer = new SmtpClient("smtp.gmail.com");
smtpServer.Port = 587;
smtpServer.Credentials = new System.Net.NetworkCredential("user", "password");
smtpServer.EnableSsl = true;
smtpServer.Send(mail);
于 2013-04-19T16:14:19.397 回答