2
我正在使用此代碼從iis服務器部署的應用程序通過gmail發送電子郵件。 我不斷收到無法連接到遠程服務器的消息。通過asp.net發送電子郵件代碼。無法解決錯誤
請在解決this--
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("[email protected]");
msg.To.Add("[email protected]");
msg.IsBodyHtml = true;
client.Host = "smtp.gmail.com";
System.Net.NetworkCredential basicauthenticationinfo = new System.Net.NetworkCredential("[email protected]", "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;
}
}