【问题标题】:SMTP mail sending through ASP.Net通过 ASP.Net 发送 SMTP 邮件
【发布时间】:2011-07-09 19:29:01
【问题描述】:

我在使用 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);
} 

提前致谢,

【问题讨论】:

标签: asp.net authentication smtp


【解决方案1】:

要在 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);
}

【讨论】:

    猜你喜欢
    • 2019-05-15
    • 2014-03-05
    • 1970-01-01
    • 2011-02-07
    • 1970-01-01
    • 1970-01-01
    • 2023-03-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多