c# - trying to send email from database value -
i have method returning email address string chunk of code sends email, i'm getting error: "the specified string not in form required e-mail address."
here's method returns email address:
public static string getsignerbyid(int signerid) { using (dbpsrentities10 myentities = new dbpsrentities10()) { var thisid = myentities.refauthsigners.where(x => x.refauthsignerid == signerid).select(x => x.networkemail).tolist(); var formattedvalue = thisid.tostring(); return formattedvalue; } }
here's code sends email:
//method send approved email public static void sendapprovedemail(string contactfirstname, string contactlastname, string contactemail, int signer) { //email 1 string filename = httpcontext.current.server.mappath("~/app_data/approvedemail.txt"); string mailbody = file.readalltext(filename); mailbody = mailbody.replace("##contactfirstname##", contactfirstname); mailbody = mailbody.replace("##contactlastname##", contactlastname); mailmessage mymessage = new mailmessage(); mymessage.subject = "psr has been approved"; mymessage.body = mailbody; string signeremailaddress = getsignerbyid(signer); mymessage.from = new mailaddress("no-reply@test.com", "no-reply@test.com"); mymessage.to.add(new mailaddress(contactemail)); mymessage.to.add(new mailaddress(signeremailaddress));// email address database errors out. smtpclient mysmtpclient = new smtpclient(); mysmtpclient.send(mymessage); }
any idea why variable "signeremailaddress" wouldn't work? value int database varchar(50) , valid email address. thanks!
thisid
relturn list of network emails:
var thisid = myentities.refauthsigners .where(x => x.refauthsignerid == signerid) .select(x => x.networkemail) .tolist();
calling tostring()
return list's type name. like:
"system.collections.generic.list`1[namespace.networkemail]"
which not looks email address. possibly want use firstordefault()
instead of tolist()
. return network address of first signer provided id. should check whether returned value not null, , call tostring()
(if have tostring()
overridden on network email type).
Comments
Post a Comment