Click here to Skip to main content
15,885,885 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I have to send mail using my web application. Given below code showing error. The error is : 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. Help me to find a proper solution. Thank you.

C#
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);
     }
  } 
 }
Posted
Updated 24-Dec-20 1:14am
Comments
Sinisa Hajnal 22-May-15 4:13am    
Sounds like your credentials are not accepted...or your from is not valid e-mail.
Member 12242067 5-Jan-16 23:44pm    
i have used this solution but mail not recieved... help me to solve the error
Member 12242067 6-Jan-16 2:18am    
I found my mistake. Thank you for solution :)
Member 11897598 17-Mar-16 9:08am    
hey please share solution i have facing same issue
y.reezvi 9-Sep-19 9:03am    
use a valid email address in from address

Put smtp.UseDefaultCredentials = false; above the smtp.Credentials assignment.
 
Share this answer
 
Also, be sure you're using the actual office365 email address for the account. You can find it by clicking on the profile button in Outlook365. I wrestled with authentication until I realized the email address I was trying to use for authentication wasn't the actual mailbox email account. it may have the form of: account@company.onmicrosoft.com.
 
Share this answer
 
In my case after I tried all this suggestion without luck, I contacted Microsoft support, and their suggestion was to simply change the password.
This fixed my issue.
Note that the password wasn't expired, because I logged on office365 with success, however the reset solved the issue.
 
Share this answer
 
simply change the password fixed this issue.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900