Click here to Skip to main content
16,017,986 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
When I run this code to send Mail, I am getting error like this:
"
C#
The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required"





using System.Net.Mail;
using System.Text;

public partial class _Default : System.Web.UI.Page
{
    /*User Crediatials by which Mail would sent */
    private const String FROM = "my email";
    private const String userName = FROM;
    private const String PassWord = "password of 8 chars";
    private String MailTitle = "";
    private String MailBody = "";
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        try {
            SmtpClient client = new SmtpClient();
            client.Port = 587;
            client.Host = "smtp.gmail.com";
            client.EnableSsl= true;
            client.Timeout = 1000000;
            client.DeliveryMethod = SmtpDeliveryMethod.Network;
            client.UseDefaultCredentials = true;
            client.Credentials = new System.Net.NetworkCredential(userName,PassWord);
           
            MailTitle = "Test Mail Notification !";
            MailBody = "This is a Simple Mail Tester !";
            MailMessage mm = new MailMessage(FROM,TextBox3.Text,MailTitle,"<h1><u>"+ MailBody+"</u></h1>");
            mm.IsBodyHtml = true;/*TO sebd HTML Formatted Data !*/
            mm.BodyEncoding = UTF8Encoding.UTF8;
            mm.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;

            client.Send(mm);
            Response.Write("Mail Sent Successfully");
        }
        catch (Exception ex) {
            Response.Write(ex.Message);

        
        }


What I have tried:

I tried above code but i says "
C#
The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required

"
Posted
Updated 20-Oct-16 20:13pm
Comments
manu_dhobale 21-Oct-16 2:05am    
Try UseDefaultCredentials = false

1 solution

 
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