ASP.net中的SendEmail显示语法错误,命令无法识别.服务器响应是:Dovecot准备好了

Ehs*_*bar 2 asp.net

我想用这段代码使用ASP.NET发送邮件:

 public void Semail(string subject, string messageBody, string toAddress)
    {
        MailMessage mail = new MailMessage();
        mail.To.Add(toAddress);
        //mail.To.Add("amit_jain_online@yahoo.com");
        mail.From = new MailAddress("noreplykaramaoozi@eesharif.edu");
        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
            ("noreplykaramaoozi@eesharif.edu", "******");
        //Or your Smtp Email ID and Password
        smtp.EnableSsl = true;
        smtp.Send(mail);
    }
Run Code Online (Sandbox Code Playgroud)

但执行后我得到了这个错误:

 Syntax error, command unrecognized. The server response was: Dovecot ready.
Run Code Online (Sandbox Code Playgroud)

这是堆栈跟踪

[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
Run Code Online (Sandbox Code Playgroud)

Nip*_*tha 8

SMTP服务器可能存在问题.

尝试使用GMAIL设置,如果邮件正在使用GMAIL服务器,那么很可能是您的邮件服务器存在问题.看起来您使用的是POP3或IMAP服务器而不是SMTP服务器,请检查您的服务器的配置

static void Main(string[] args)
        {
            var client = new SmtpClient("smtp.gmail.com", 587)
            {
                Credentials = new NetworkCredential("myusername@gmail.com", "mypwd"),
                EnableSsl = true
            };
            client.Send("myusername@gmail.com", "myusername@gmail.com", "test", "testbody");
            Console.WriteLine("Sent");
            Console.ReadLine();
        }
Run Code Online (Sandbox Code Playgroud)


小智 8

当使用 gmail smtp 服务器和 ssl 时,请务必使用 587 端口而不是 465,这解决了我的问题。