我写了这段代码但它没有用
try
{
MailMessage mailMessage = new MailMessage();
mailMessage.To.Add("XXXXXXX@gmail.com");
mailMessage.From = new MailAddress("XXXXXXX@gmail.com");
mailMessage.Subject = "ASP.NET e-mail test";
mailMessage.Body = "Hello world,\n\nThis is an ASP.NET test e-mail!";
SmtpClient smtpClient = new SmtpClient("smtp.gmail.com");
smtpClient.Send(mailMessage);
Response.Write("E-mail sent!");
}
catch (Exception ex)
{
Response.Write("Could not send the e-mail - error: " + ex.Message);
}
我从asp.net教程中获取此代码。它不适合我。
我收到错误:
无法发送电子邮件
感谢任何帮助
答案 0 :(得分:0)
传递端口号。
new SmtpClient("smtp.gmail.com", 587);