I try to send email using 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.Port = 587; smtp.Credentials = new System.Net.NetworkCredential ("[email protected]", "*******"); //Or your Smtp Email ID and Password smtp.EnableSsl = false; smtp.Send(mail); } But after executing i got this error:
The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Authentication required Stack Trace :
[SmtpException: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Authentication required] System.Net.Mail.MailCommand.CheckResponse(SmtpStatusCode statusCode, String response) +2162008 System.Net.Mail.MailCommand.Send(SmtpConnection conn, Byte[] command, String from) +287 System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, SmtpFailedRecipientException& exception) +137 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 Best regards
smtp.EnableSsl=true;?telnet, it is working and responding, which means SMTP server is OK. Probably your credentials are NOT valid. You can try withtelnet, see this link technet.microsoft.com/en-us/library/aa995718(v=exchg.65).aspx