.net - Validating an email Address in C# -
.net - Validating an email Address in C# -
i trying send email using c# using next code.
mailmessage mail service = new mailmessage(); mail.from = new mailaddress(fromaddress, friendlyname); mail.to.add(toaddress); mail.cc.add(ccaddress); //set content mail.subject = emailsubject; mail.body = emailheader + "\n" + emailbody; //send message smtpclient smtp = new smtpclient(serveraddress); smtp.credentials = credentialcache.defaultnetworkcredentials; mail.isbodyhtml = true; smtp.send(mail);
now "toaddress" string function recieves might contain single address, or might have many, comma delimited addresses.
now problem that, in case of multiple comma delimited addresses, 1 or 2 of them might of wrong email address format.
so when seek send email using code, exception:
"the specified string not in form required e-mail address."
is there way validate comma delimited email addresses? had read somewhere way validate email address send email it, because regular expressions validate email addreess can surprisingly huge.
also, have no command on design, or on how address string comes function,i can't add together email validation in ui, helpless there...
my problem email not delivered all addresses in comma delimited string, though some of addresses of wrong format.
is there way validate email addresses in .net? there way weed out bad email addresses , send mail service ones?
you split email string on comma , validate each email address using simple (or huge) email regex. or, seek creating mailaddress
object; supports basic validation of address too.
c# .net email
Comments
Post a Comment