Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SendEmail in ASP.net shows me Syntax error, command unrecognized. The server response was: Dovecot ready

Tags:

asp.net

I want to send mail using ASP.NET with this code:

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

But after executing i got this error :

 Syntax error, command unrecognized. The server response was: Dovecot ready.

This is the stacktrace

[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
like image 570
Ehsan Akbar Avatar asked May 03 '14 06:05

Ehsan Akbar


2 Answers

There might be issue with SMTP Server.

Try with GMAIL Settings, if mail is working with GMAIL server, then most probably there is issue with your Mailing Server. It looks like you are using POP3 or IMAP server not SMTP Server, please check configuration of your Server

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();
        }
like image 180
Nipun Ambastha Avatar answered Nov 03 '22 07:11

Nipun Ambastha


When using gmail smtp server and ssl be sure to use 587 port instead of 465, this solved the issue for me.

like image 42
José Polanco Avatar answered Nov 03 '22 08:11

José Polanco