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("<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="fa9b97938ea5909b9394a595949693949fba839b929595d4999597">[email protected]</a>");
mail.From = new MailAddress("<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="cea0a1bcabbea2b7a5afbcafa3afa1a1b4a78eababbda6afbca7a8e0abaabb">[email protected]</a>");
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
("<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="bad4d5c8dfcad6c3d1dbc8dbd7dbd5d5c0d3fadfdfc9d2dbc8d3dc94dfdecf">[email protected]</a>", "******");
//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
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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("<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="44293d313721362a252921042329252d286a272b29">[email protected]</a>", "mypwd"),
EnableSsl = true
};
client.Send("<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6d0014181e081f030c00082d0a000c0401430e0200">[email protected]</a>", "<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="721f0b070117001c131f1732151f131b1e5c111d1f">[email protected]</a>", "test", "testbody");
Console.WriteLine("Sent");
Console.ReadLine();
}
Method 2
When using gmail smtp server and ssl be sure to use 587 port instead of 465, this solved the issue for me.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0