Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
//Name space:
using System.Net.Mail;

//button click:
string fr = "ABC AGENCIES";
string to = "jaheenajamal@gmail.com";
string sub = "GREETINGS!!!....";
string body = "<html><head><title>Untitled Page</title></head><body><p>Congratulation User Your accunt confirmed </p></body></html>";
SmtpClient smtpclient = new SmtpClient();
MailMessage message = new MailMessage(fr,to,sub,body);
smtpclient.Host = "localhost";
message.IsBodyHtml = true;

try
{
  smtpclient.Send(message);
  Response.Write("Mail has been send successfully");
}
catch (Exception ex)
{
  Response.Write("Mail sending failure:" + ex.Message);
}

Error:

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:
SmtpClient smtpclient = new SmtpClient();<br />
MailMessage message = new MailMessage(fr,to,sub,body);


Stack Trace:

[FormatException: The specified string is not in the form required for an e-mail address.]
   System.Net.Mime.MailBnfHelper.ReadMailAddress(String data, Int32&amp; offset, String&amp; displayName) +1334
   System.Net.Mail.MailAddress.ParseValue(String address) +246
   System.Net.Mail.MailAddress..ctor(String address, String displayName, Encoding displayNameEncoding) +78
   System.Net.Mail.Message..ctor(String from, String to) +107
   System.Net.Mail.MailMessage..ctor(String from, String to) +111
   System.Net.Mail.MailMessage..ctor(String from, String to, String subject, String body) +14
   fulldet.sendmail() in c:\Documents and Settings\Capsule01\Desktop\lottery agencies2 sample item\admin\fulldet.aspx.cs:700
   fulldet.Button1_Click(Object sender, EventArgs e) in c:\Documents and Settings\Capsule01\Desktop\lottery agencies2 sample item\admin\fulldet.aspx.cs:160
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +75
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +97
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4919

Please give reason & solution for this error. Please.

Thanks in advance
Posted
Updated 7-Mar-11 22:01pm
v4
Comments
Dalek Dave 8-Mar-11 4:02am    
Edited for Readability.

string fr = &amp;quot;ABC AGENCIES&am p;quot;; is in corrent format the Format for the mail string is

name@gmail.com
 
Share this answer
 
string fr = "ABC AGENCIES";

string fr = Enter email Id not company name
 
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