SMTP mail sending through ASP.Net
I have a problem regarding smtp mail sending with asp.net.When I attempt to send through the smtp protocol,I get the following error.
The server response was: 5.5.1 Authentication Required
I'm using something like this;
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开发者_StackOverflow中文版);
}
Thanks in advance,
For sending gmail through SMTP in ASP.NET, use this
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);
}
精彩评论