5.7.57 SMTP - Client was not authenticated to send

2019-01-08 01:30发布

I have to send mails using my web application. Given the 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.

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

标签: c# smtp timeout
11条回答
戒情不戒烟
2楼-- · 2019-01-08 02:10

I use to have the same problem.

Add the domain solved it..

mySmtpClient.Credentials = New System.Net.NetworkCredential("email@domain.com", "password", "domain.com")
查看更多
Ridiculous、
3楼-- · 2019-01-08 02:12

In my case, 2 Factor Authentication was turned on for the FROM account in Office 365. Once that was turned off, the email sent successfully.

查看更多
Ridiculous、
4楼-- · 2019-01-08 02:21

I changed the Office365 password and then tried to send a test email and it worked like a charm for me.

I used the front end (database mail option) and settings as smtp.office365.com port number 587 and checked the secure connection option. use basic authentication and store the credentials. Hope this turns out useful for someone.

查看更多
Rolldiameter
5楼-- · 2019-01-08 02:23

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.

查看更多
姐就是有狂的资本
6楼-- · 2019-01-08 02:24

Started working after adding property:

mail.smtp.starttls.enable=true

Using:

mail.smtp.host=smtp.office365.com
mail.smtp.port=587
mail.transport.protocol=smtp
mail.smtp.auth=true
mail.smtp.starttls.enable=true
mail.smtp.user=xxx@example.com
mail.smtp.password=xxx
mail.smtp.from=yyy@example.com
查看更多
登录 后发表回答