发送电子邮件(Gmail)

时间:2015-07-22 14:06:27

标签: c# email smtp

这段代码几周前就已经运行了,但是当我现在尝试它时它不起作用。这是我的代码:

        SmtpClient client = new SmtpClient();
        client.Port = 587;
        client.Host = "smtp.gmail.com";
        client.EnableSsl = true;
        client.Timeout = 10000;
        client.DeliveryMethod = SmtpDeliveryMethod.Network;
        client.UseDefaultCredentials = false;
        client.Credentials = new System.Net.NetworkCredential("mail@gmail.com", "password");

        MailMessage mail = new MailMessage("mail@domain.com", "mail2@gmail.com", "Subject", "Body");
        mail.BodyEncoding = UTF8Encoding.UTF8;
        mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;

        client.Send(mail);

错误是:SMTPException未处理: System.dll

中发生了未处理的“System.Net.Mail.SmtpException”类型异常

其他信息:操作已超时。

0 个答案:

没有答案