Click here to Skip to main content
15,903,203 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
hi all,
please help me ia m getting this exception.

Format Exception:
The specified string is not in the form required for an e-mail address.

in my project when i am scheduling trainings the i am giving tow faculty names at a time separated by comma then i am getting this exception.i am giving the correct format of email addresses but i am facing.

please anuone helpppp me.
Posted
Updated 3-Jan-12 5:17am
v2
Comments
Nigam Patel 3-Jan-12 7:10am    
can you please post the code so we have better idea.

Without the relevant code fragments, we have to make guesses...
You can't separate email addresses with a comma - if you want to send the same message to different people, then
1) Send it to one of them and CC (or BCC) the other
2) Send the message twice.
3) Use the MailMessage.To.Add method for two different new MailAddress instances.
 
Share this answer
 
I faced this problem while sending email to multiple email address. I used the delimiter ";" to separate the email addresses. As outlook uses the same format of separating multiple email addresses. But it didnot worked.Instead of using the ";" we should use the "," for separating the multiple emails. And this worked for me.
For more details :
visit: http://kopila.com.np/
 
Share this answer
 
v2
Comments
Member 12105881 6-Nov-15 2:30am    
I am using code like below,but I am getting error like -
the smtp server requires a secure connection or the client was not authenticated.
Failure sending mail.
smtp.port=80
smtp.UseDefaultCredentials = false;

So can any one please help me..

Thanks in Advance
You can add several addresses using a comma separated list. For example the following should work fine:
C#
System.Net.Mail.MailMessage mm = new System.Net.Mail.MailMessage();
mm.To.Add("aaa@bbb.ccc, ddd@eee.fff");

However if there's even one invalid address, you'll get an exception. Also note that the exception isn't necessarily coming from the recipient address, it could also come from the sender address.

So without seeing the actual code the best option is to debug through the code and see what's going wrong.

Also note that what OriginalGriff wrote, it would be best to add a single recipient at a time. When done in a loop using a proper try..catch block you can decide what to do when an invalid address is encountered. If you add them all together, it'll be harder to catch the problematic address and to continue with other addresses if that's needed.
 
Share this answer
 
Comments
tariquekhurshid 28-Nov-12 1:25am    
i am trying to send an email with attachment but i am getting an exception:-
The specified string is not in the form required for an e-mail address.

Exception Details: System.FormatException: The specified string is not in the form required for an e-mail address.
Source Error:
MailMessage message = new MailMessage();
message.From = new MailAddress(txtfrom.Text); -> in this line i am getting an exception.
message.To.Add(new MailAddress(txtto.Text));
message.Body = txtbody.Text;
here is code:-
MailMessage message = new MailMessage();
message.From = new MailAddress(txtfrom.Text);
message.To.Add(new MailAddress(txtto.Text));
message.Body = txtbody.Text;
message.IsBodyHtml = true;
message.Subject = txtsub.Text;
if (FileUpload1.PostedFile != null)
{
HttpPostedFile attFile = FileUpload1.PostedFile;
int attachFileLength = attFile.ContentLength;
if (attachFileLength > 0)
{
filenametoattach = Path.GetFileName(FileUpload1.PostedFile.FileName);
FileUpload1.PostedFile.SaveAs(Server.MapPath(filenametoattach));
message.Attachments.Add(new Attachment(Server.MapPath(filenametoattach)));
}
}

SmtpClient emailWithAttach = new SmtpClient();
emailWithAttach.Host = "localhost";
emailWithAttach.DeliveryMethod = SmtpDeliveryMethod.Network;
emailWithAttach.UseDefaultCredentials = true;
emailWithAttach.Send(message);
}
anyone please help me out.
PrakashJoshi 9-Apr-15 6:02am    
I have the same problem the error I found is in web config file
kindly check your web config file if you have the following like code, comment or delete it. this works for me.
< mailsettings>
< smtp from="TEST">
< network host="smtp.gmail.com" port="587" username="youremailID" password="password" defaultcredentials="false">
< /smtp>

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