我正在使用此代码从 iis 服务器部署的应用程序从 gmail 发送电子邮件。我不断收到无法连接到远程服务器的消息。
请帮忙解决这个问题——
protected void SendMail()
{
MailMessage msg = new MailMessage();
System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient();
try
{
msg.Subject = "download complete";
msg.Body = "download is completed";
msg.From = new MailAddress("xxx@gmail.com");
msg.To.Add("yyy@gmail.com");
msg.IsBodyHtml = true;
client.Host = "smtp.gmail.com";
System.Net.NetworkCredential basicauthenticationinfo = new System.Net.NetworkCredential("xxx@gmail.com", "xxx");
client.Port = int.Parse("587");
client.EnableSsl = true;
client.UseDefaultCredentials = false;
client.Credentials = basicauthenticationinfo;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.Send(msg);
}
catch (Exception ex)
{
TextBox1.Text = ex.Message;
}
}