我有关于使用asp.net发送smtp邮件的问题。当我尝试通过smtp协议发送时,我收到以下错误。
The server response was: 5.5.1 Authentication Required
我正在使用这样的东西;
string mess = "";
mess += "<b>You have mail</b></br>";
mess += "<b>Name Surname</b>" + textName.Text + "</br>";
mess += "<b>Email adress</b>" + textEmail.Text + "</br>";
mess += "<b>Subject</b>" + textSubject.Text + "</br>";
mess += "<b>Message</b>" + textMessage.Text + "</br>";
mess += "<b>Date</b>" + DateTime.Now.ToString();
MailMessage msg = new MailMessage();
msg.IsBodyHtml = true;
msg.To.Add("oruc_esma@hotmail.com");
msg.From = new MailAddress("turkishcorpus1@gmail.com", "Esma oruc",System.Text.Encoding.UTF8);
msg.Subject = textSubject.Text;
msg.Body = mess;
SmtpClient smp = new SmtpClient();
smp.Credentials = new NetworkCredential("turkishcorpus1@gmail.com", "my password");
smp.Port = 587;
smp.Host = "smtp.gmail.com";
smp.EnableSsl = true;
smp.Send(msg);
}
提前致谢,
答案 0 :(得分:0)
要在ASP.NET中通过SMTP发送Gmail,请使用此
var smtp = new SmtpClient
{
Host = "smtp.gmail.com",
Port = 587,
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Credentials = new NetworkCredential("turkishcorpus1@gmail.com", "my password")
};
using (var message = new MailMessage("turkishcorpus1@gmail.com", "oruc_esma@hotmail.com")
{
Subject = "This is the title of the mail",
Body = "This is the body"
//,IsBodyHtml = true //optional
})
{
smtp.Send(message);
}