Click here to Skip to main content
12,359,751 members (64,313 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: ASP.NET SQL
hi
we are create a gmail code and it rum successfully in local host but we are host this page and send email this time we get error plz help me what's problem in this code
MailMessage loginInfo = new MailMessage();
loginInfo.To.Add(txt_email.Text.ToString());
loginInfo.From = new MailAddress("my email id");
loginInfo.Subject = "Contact Detail";
loginInfo.Body = "Message: " + txt_message.Text; 
loginInfo.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.Port = 587;
smtp.EnableSsl = true;
smtp.Credentials = new System.Net.NetworkCredential("my user name", "My password");
smtp.Send(loginInfo);
Posted 6-Feb-13 0:19am
Updated 6-Feb-13 0:39am
v2
Comments
Orcun Iyigun 6-Feb-13 6:42am
   
What is the exception? Can you give the details please
Ripal Merakinfoway 6-Feb-13 6:50am
   
Runtime Error
Description: An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine.

Details: To enable the details of this specific error message to be viewable on remote machines, please create a tag within a "web.config" configuration file located in the root directory of the current web application. This tag should then have its "mode" attribute set to "Off".


<!-- Web.Config Configuration File -->








Notes: The current error page you are seeing can be replaced by a custom error page by modifying the "defaultRedirect" attribute of the application's configuration tag to point to a custom error page URL.


<!-- Web.Config Configuration File -->





aspnet_regiis -i 6-Feb-13 6:59am
   
I faced the same problem..I fixed the error and it started working...
joe_j 6-Feb-13 7:07am
   
The seetings in your webconfig is set to not allow you to see the actual error.
Inside the add this . After that open the website again. This time you should be able to see the error. Copy it and paste it here please
Ripal Merakinfoway 6-Feb-13 23:25pm
   
hi joe_i

this is error

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
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Net.Mail.SmtpException: 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

Source Error:


Line 32: smtp.EnableSsl = true;
Line 33: smtp.Credentials = new System.Net.NetworkCredential("my email id", "my pwd");
Line 34: smtp.Send(loginInfo);
Line 35: }
Line 36: }

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Read this: MailMessage.To[^]

You do:
loginInfo.To.Add(txt_email.Text.ToString());
loginInfo.From = new MailAddress("my email id");


But the TO Adrress requires the New MailAddress() object in stead of the FROM.
  Permalink  

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.160621.1 | Last Updated 6 Feb 2013
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