我想使用 ASP.NET 发送邮件,代码如下:
public void Semail(string subject, string messageBody, string toAddress)
{
MailMessage mail = new MailMessage();
mail.To.Add(toAddress);
//mail.To.Add("[email protected]");
mail.From = new MailAddress("[email protected]");
mail.Subject = subject;
string Body = messageBody;
mail.Body = Body;
mail.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Host = "sina.sharif.ir"; //Or Your SMTP Server Address
smtp.Credentials = new System.Net.NetworkCredential
("[email protected]", "******");
//Or your Smtp Email ID and Password
smtp.EnableSsl = true;
smtp.Send(mail);
}
但执行后我得到了这个错误:
Syntax error, command unrecognized. The server response was: Dovecot ready.
这是堆栈跟踪
[SmtpException: Syntax error, command unrecognized. The server response was: Dovecot ready.]
System.Net.Mail.SmtpConnection.GetConnection(ServicePoint servicePoint) +2176152
System.Net.Mail.SmtpClient.Send(MailMessage message) +2188821
Novitiate.fa.Register.btnLogin_Click(Object sender, EventArgs e) +2948
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +154
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3707
SMTP 服务器可能有问题。
尝试使用 GMAIL 设置,如果邮件正在使用 GMAIL 服务器,那么很可能您的邮件服务器存在问题。
看起来您正在使用 POP3 或 IMAP 服务器而不是 SMTP 服务器,请检查您的服务器配置
static void Main(string[] args)
{
var client = new SmtpClient("smtp.gmail.com", 587)
{
Credentials = new NetworkCredential("[email protected]", "mypwd"),
EnableSsl = true
};
client.Send("[email protected]", "[email protected]", "test", "testbody");
Console.WriteLine("Sent");
Console.ReadLine();
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)