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