• Register
0 votes
315 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 18 views
18 views
Problem: Please help me … how can I solve this that client was not authenticated to send anonymous mail during mail from?
asked Mar 18 Ifra 37.2k points
1 vote
1 answer 14 views
14 views
Problem : I created a project for sending emails.The Code works correctly in my local Machine. But on Production server i am getting the error message : Gmail Error :The SMTP server requires a secure connection or the client was not authenticated. The server ... . This person was using an application such as an email, client or mobile device…… Can someone please help fix this ?
asked Apr 17 Sabbir Hossain 14.6k points
0 votes
1 answer 12 views
12 views
Problem: Gmail Error:The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required
asked Mar 20 ummesalma 29.2k points
0 votes
1 answer 4 views
4 views
Problem: Please help me fix this dilemma “The smtp server requires a secure connection or the client was not authenticated 5.5.1”?
asked Mar 29 tuhin1 48.9k points
1 vote
1 answer 27 views
27 views
Problem: Why this authentification is getting failed? Javax.mail.authenticationfailedexception: 535-5.7.8 username and password not accepted.
asked Mar 30 PkGuy 23.5k points
0 votes
1 answer 2 views
2 views
Problem: I am in trouble while solving it .. please help me .. The server response was: 5.5.1 authentication required.
asked 4 days ago Ifra 37.2k points
0 votes
1 answer 2 views
2 views
Problem: I need someone to understand this problem and find out the solution. The server response was: 5.5.1 authentication required
asked Apr 26 Ifra 37.2k points
0 votes
1 answer 6 views
6 views
Problem: The server response was 5.5.1 authentication required. help me to clear this issue.
asked Mar 21 charles mathews 5.5k points
0 votes
1 answer 12 views
12 views
Problem: Can anyone please justify it with the simplest > Javax.mail.messagingexception: could not connect to smtp host: smtp.gmail.com, port: 465
asked Apr 24 ummeshani 10.8k points
0 votes
1 answer 2 views
2 views
Question: I have created an chrome extension for gmail which loads some data as gallery when user compose new mail.after selecting the data,data gets loaded into body and subject. But when i want to send that mail from his/her account,i need to personalize the ... js/jquery so far for doing all above stuff. Now i am looking forward to sending part after personalization. Thanks for stopping by!!
asked Apr 13 Atik03 26.5k points