Reshma Reshma - 1 month ago 39
C# Question

The server response was: 5.7.57 SMTP; Client was not authenticated to send anonymous mail during MAIL FROM

I have to send mail using my web application. Given below code showing

The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.57 SMTP; Client was not authenticated to send anonymous mail during MAIL FROM
error.
Help me to find a proper solution. Thank you.

Code:

protected void btnsubmit_Click(object sender, EventArgs e)
{

Ticket_MailTableAdapters.tbl_TicketTableAdapter tc;
tc = new Ticket_MailTableAdapters.tbl_TicketTableAdapter();
DataTable dt = new DataTable();
dt = tc.GetEmail(dpl_cate.SelectedValue);
foreach (DataRow row in dt.Rows)
{
string eml = (row["Emp_Email"].ToString());
var fromAddress = "emailAddress";
var toAddress = eml;
const string fromPassword = "*****";
string body = "Welcome..";
// smtp settings
var smtp = new System.Net.Mail.SmtpClient();
{
smtp.Host = "smtp.office365.com";
smtp.Port = 587;
smtp.EnableSsl = true;

smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
smtp.Credentials = new NetworkCredential(fromAddress, fromPassword);
smtp.UseDefaultCredentials = false;
smtp.Timeout = 600000;
}
// Passing values to smtp object
smtp.Send(fromAddress, toAddress, subject, body);
}
}
}

Answer

I might not be a good programmer, but you seem to be passing the From address as "emailAddress" which is not a proper email address and for Office365 the from needs to be a real address on the Office365 system.

You can validate that if you hardcode your email address as the from and your office 365 password. Don't leave it there though of course.