Click here to Skip to main content
15,867,704 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
C#
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
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
[no name] 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 <customerrors> tag within a "web.config" configuration file located in the root directory of the current web application. This <customerrors> tag should then have its "mode" attribute set to "Off".


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

<configuration>
<system.web>
<customerrors mode="Off">




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 <customerrors> configuration tag to point to a custom error page URL.


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

<configuration>
<system.web>
<customerrors mode="RemoteOnly" defaultredirect="mycustompage.htm">

bbirajdar 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
[no name] 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

Read this: MailMessage.To[^]

You do:
C#
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.
 
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