Click here to Skip to main content
15,894,539 members
Please Sign up or sign in to vote.
1.24/5 (3 votes)
See more:
when working in the application it is working fine and receiving mail. when it is hosted message sending failed and i am getting the error like "The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at" please help me

my code is
C#
try
{
    MailMessage Msg = new MailMessage();
    // Sender e-mail address.
    Msg.From = new MailAddress(txtemail.Text);
    // Recipient e-mail address.
    Msg.To.Add("manojmuraliconnect@gmail.com");
    Msg.Subject = "Enquiry";
    Msg.Body = "Sender : " + txtemail.Text + "\n" + "Name : " + txtname.Text + "\n" + "Phone : " + txtphone.Text + "\n" + "Address:" + txtaddress.Text + "\n" + "Enquiry:" + txtenquiry.Text;
    // your remote SMTP server IP.
    SmtpClient smtp = new SmtpClient();
    smtp.Host = "smtp.gmail.com";
    smtp.Port = 587;
    smtp.Credentials = new System.Net.NetworkCredential("manojmuraliconnect@gmail.com", "Password");
    smtp.EnableSsl = true;
    smtp.Send(Msg);
    ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "ASET", "<script type='text/javascript'>alert('Your Message Has Been Send ');</script>", false);
    CleaContents();
}
catch (Exception ex)
{
    lbltext.Text = ex.Message;
}
Posted
Updated 6-May-19 23:34pm
v3
Comments
Prasad Khandekar 29-Aug-13 1:10am    
Hello Manoj,

Please have a look at this thread. (http://stackoverflow.com/questions/704636/sending-email-through-gmail-smtp-server-with-c-sharp)

Regards,

Look at:
C#
Msg.From = new MailAddress(txtemail.Text);
...
smtp.Credentials = new System.Net.NetworkCredential("manojmuraliconnect@gmail.com",

If txtemail.Text is different from "manojmuraliconnect@gmail.com", Google will not accept that message: you must not send an email on behalf of someone else (many mail servers are configured in this way: no provider likes spammers).
 
Share this answer
 
Comments
Thomas Daniels 29-Aug-13 2:41am    
+5!
Member 7796801 16-Jun-16 0:20am    
Thank you!!!! This is exactly what I needed.
Very Strong Password is needed,
I changed my Account's Password to somthing like: %TGB6yhn^YHN5tgb and it works perfect.
 
Share this answer
 
Comments
Amir Dabaghian Anbarani 20-Jan-14 3:57am    
I tested this method, but I can't get any result.
Venkata Sailendra Kumar 30-Jun-14 5:03am    
Thanks mate!!! I tried a lot with different options but changing the password strongly works perfectly for me...
Vikas Kumar 28-Sep-14 16:34pm    
Thanks! I got my solution using Account password change
Vishwajeet Awasthi 19-Feb-15 6:27am    
It was really helpful, Thanks ..
Member 13585410 13-Jan-20 14:01pm    
Tnx a lot. Only this solved to me
there is a very simple solutin for this

instead of using manojmuraliconnect@gmail.com gmail addresss

use email address that is created on the server on which you are hosting your application

this problem causes because gmail server prevents to send email through gmail server
 
Share this answer
 
Msg.From = new MailAddress(txtemail.Text);

smtp.Credentials = new System.Net.NetworkCredential("txtemail", "Password");
 
Share this answer
 
I had the same problem. After turning off the two steps verification, it worked like a charm.
 
Share this answer
 
 
Share this answer
 
Comments
Tomas Takac 11-Jan-15 6:15am    
Please note that the question is from August 2013 i.e. it's 1.5 years old! Do not answer old question like this. First it doesn't make sense and secondly you expose yourself to the risk of being downvoted.
sudip singh 30-Aug-15 7:27am    
The answer is more than a year old. So I guess the answer makes a lot of sense. If it helps upvote else it is all up to the people viewing this answer. Thank you.

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