Click here to Skip to main content
15,907,281 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi friends,


i was getting the following error as in mail sending coding.
The specified string is not in the form required for an e-mail address.
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.FormatException: The specified string is not in the form required for an e-mail address.

Source Error:

Line 80: 
Line 81: 
Line 82:         MailMessage objEmail = new MailMessage();
Line 83: 
Line 84:         objEmail.Sender = new MailAddress("sanjithbtech@gmail.com");


Source File: c:\inetpub\vhosts\cegonsoftfaq.com\httpdocs\ContactUs.aspx.cs    Line: 82

Stack Trace:

[FormatException: The specified string is not in the form required for an e-mail address.]
   System.Net.Mail.MailAddressParser.ReadCfwsAndThrowIfIncomplete(String data, Int32 index) +1252393
   System.Net.Mail.MailAddressParser.ParseDomain(String data, Int32& index) +118
   System.Net.Mail.MailAddressParser.ParseAddress(String data, Boolean expectMultipleAddresses, Int32& index) +94
   System.Net.Mail.MailAddressParser.ParseAddress(String data) +23
   System.Net.Mail.MailAddress..ctor(String address, String displayName, Encoding displayNameEncoding) +245
   System.Net.Mail.MailMessage..ctor() +133
   Feedback.Button1_Click(Object sender, EventArgs e) in c:\inetpub\vhosts\cegonsoftfaq.com\httpdocs\ContactUs.aspx.cs:82
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +118
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +112
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5563



the coding is
C#
MailMessage objEmail = new MailMessage();

        objEmail.Sender = new MailAddress("sanjithbtech@gmail.com");
        objEmail.To.Add(new MailAddress("sanjithbtech@gmail.com"));

        objEmail.Subject = "Contact Us mail from Cegonsoft Development website";
        objEmail.Body = TextBox5.Text;
        objEmail.From = new MailAddress(TextBox2.Text);
        objEmail.IsBodyHtml = false;


        SmtpClient objSmtpClient = new SmtpClient();
        objSmtpClient.Host = "smtp.gmail.com";
        objSmtpClient.Port = 25;
        objSmtpClient.EnableSsl = true;

        objSmtpClient.UseDefaultCredentials = false;


        objSmtpClient.Credentials = new System.Net.NetworkCredential("sanjithbtech@gmail.com", "xxxxxxxxxxx");

        objSmtpClient.Send(objEmail);

i want to know the above coding is correct to send an email.

Pl give me the reply with correct solution
Posted
Updated 10-Oct-11 3:34am
v4
Comments
Uday P.Singh 10-Oct-11 8:47am    
what is the error message?
Member 7976636 10-Oct-11 8:48am    
sorry uday,now i was updated.pl give the solution

1 solution

Not sure whether your SMTP port is correct..

Gmail SMTP port: 465 ?

Refer

http://email.about.com/od/accessinggmail/f/Gmail_SMTP_Settings.htm[^]
 
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