Click here to Skip to main content
12,455,701 members (79,135 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: ASP.NET
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
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 28-Aug-13 18:46pm
Updated 28-Aug-13 19:06pm
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,
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Look at:
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).
  Permalink  
Comments
ProgramFOX 29-Aug-13 2:41am
   
+5!
Member 7796801 16-Jun-16 0:20am
   
Thank you!!!! This is exactly what I needed.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

Very Strong Password is needed,
I changed my Account's Password to somthing like: %TGB6yhn^YHN5tgb and it works perfect.
  Permalink  
Comments
Member 10492994 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 ..
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

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
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 5

Msg.From = new MailAddress(txtemail.Text);

smtp.Credentials = new System.Net.NetworkCredential("txtemail", "Password");
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 6

I had the same problem. After turning off the two steps verification, it worked like a charm.
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 7

  Permalink  
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160826.1 | Last Updated 10 Jan 2015
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100