• Register
0 votes
255 views

Problem :

I want to send mails using my web application. But my below code is showing me the below error:

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.

Below is my Code:

protected void mybtnsubmit_Click(object mysender, EventArgs e)
 {
Ticket_MailTableAdapters.tbl_TicketTableAdapter tc; 
mytc = new Ticket_MailTableAdapters.tbl_TicketTableAdapter();
   DataTable mydt = new DataTable();
   mydt = mytc.GetEmail(dpl_cate.SelectedValue);
   foreach (DataRow row in mydt.Rows)
    {
    string myeml = (row["Emp_Email"].ToString());
    var myfromAddress = "emailAddress";
    var mytoAddress = myeml;
    const string myfromPassword = "*****";
    string mybody = "Welcome..";
 // smtp settings
    var mysmtp = new MySystem.Net.Mail.SmtpClient();
       {
         mysmtp.Host = "smtp.office365.com";
         mysmtp.Port = 587;
         mysmtp.EnableSsl = true;
         mysmtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
         mysmtp.Credentials = new NetworkCredential(myfromAddress, myfromPassword);
         mysmtp.UseDefaultCredentials = false;
         mysmtp.Timeout = 600000;
       }
  // Passing values to smtp object
     mysmtp.Send(myfromAddress, mytoAddress, mysubject, mybody);
     }
  } 

 }

6 5 3
7,540 points

Please log in or register to answer this question.

1 Answer

0 votes

Solution :

In case you have not found the solution yet, then follow below things that to solve the same issue.

1.  Please make sure that NetworkCredentials you are setting must be correct. For example in my case since it was the office SMTP, user id must be used in the NetworkCredential along with domain name and not the actual email id.

2.  Also you need to set the "UseDefaultCredentials" to false first and after that set Credentials. If you try to set "UseDefaultCredentials" after that it will reset the NetworkCredential to null.

Hope it will solve your issue.

9 7 4
38,600 points

Related questions

0 votes
1 answer 13 views
0 votes
1 answer 56 views
56 views
Problem : I am using a SmtpClient library to send the emails using a below code : SmtpClient smtpclient = new SmtpClient(); smtpclient.Host = "hostname"; smtpclient.Port = 465; smtpclient.DeliveryMethod = SmtpDeliveryMethod.Network; smtpclient.UseDefaultCredentials = false; smtpclient. ... port opens just fine between a client and a server. I am not sure at all what else could throw above error.
asked Jan 29, 2020 jwilliam 3.9k points
0 votes
1 answer 80 views
80 views
Problem: I am trying to send the email to my gmail address but it keeps on showing below error: "SMTP -> ERROR: Failed to connect to server: Connection timed out (110)SMTP Connect() failed. Message was not sent.Mailer error: SMTP Connect() failed." Please find ... ;             } else {             echo 'Message has been sent.';            } How can I fix above error message related to PHPMail?
asked Jul 31, 2020 Raphael Pacheco 4.9k points
0 votes
1 answer 38 views
38 views
Problem Hi Kodlogs, How am having following error while sending mails using PHP: mailer error: could not instantiate mail function Need help fixing please
asked Nov 3, 2020 hashq 1.1k points
0 votes
1 answer 2.4K views
2.4K views
Problem : I got stuck on below error I am trying to configure my SMTP mail on laravel “Expected response code 250 but got code "530", with message "530 5.7.1 authentication required "” Below is the configuration on .env MAIL_DRIVER=smtp MAIL_HOST=smtp.mailtrap.io ... I have tried to authenticate my SMTP on the env but I keep facing the above error so for now I am stuck on that error.
asked Feb 4, 2020 jwilliam 3.9k points
0 votes
1 answer 412 views
412 views
Problem : I am trying to create the test app using unity but facing following issue: readpixels was called to read pixels from system frame buffer, while not inside drawing frame.
asked Nov 14, 2019 peterlaw 6.9k points
0 votes
1 answer 6 views
6 views
Help me to solve this.
asked 4 days ago TeamScript 11.1k points
0 votes
1 answer 5 views
5 views
Please help me to resolve this.
asked 4 days ago TeamScript 11.1k points