c# - System.Net.Mail.SmtpException: Failure sending mail.System.Net.WebException: The remote name could not be resolved -
c# - System.Net.Mail.SmtpException: Failure sending mail.System.Net.WebException: The remote name could not be resolved -
web application give error after sending few mails: system.net.mail.smtpexception: failure sending mail.system.net.webexception: remote name not resolved when send mail service c#.net code. application hosted on cloud server , error raise after time, when restart application pool work again.
public void sendmail(string toemailid, string ccemailid, string subject, string body, system.collections.arraylist _attachments = null) mailmessage mm = null; smtpclient smtp = null;
seek { string strpath = ""; string strreplacepath = ""; if (system.web.httpcontext.current != null && system.web.httpcontext.current.request != null) { strpath = system.web.httpcontext.current.request.url.tostring(); strreplacepath = system.web.httpcontext.current.request.url.pathandquery; strpath = strpath.replace(strreplacepath, "/"); } else if (!string.isnullorempty(system.configuration.configurationmanager.appsettings["domainname"])) { strpath = system.configuration.configurationmanager.appsettings["domainname"]; } body = body.replace("@@logo@@", getimage(strpath, "content/images/logo.jpg")); body = body.tostring().replace("@@year@@", datetime.now.year.tostring()); mm = new mailmessage(); mm.subject = subject; mm.body = body; mm.isbodyhtml = true; mm.to.add(toemailid); if (!string.isnullorempty(ccemailid)) mm.cc.add(ccemailid); mm.bcc.add("my email address"); if (_attachments != null && _attachments.count > 0) { (int = 0; < _attachments.count; i++) { mm.attachments.add((attachment)_attachments[i]); } } smtp = new smtpclient(); smtp.enablessl = true; smtp.timeout = 25000; smtp.send(mm); } { foreach (attachment attachment in mm.attachments) { attachment.dispose(); } if (_attachments != null) _attachments.clear(); if (mm != null) mm.dispose(); if (smtp != null) smtp.dispose(); mm = null; smtp = null; _attachments = null; } }
i have used smtp.gmail.com , port 587 used.
c# asp.net .net asp.net-mvc email
Comments
Post a Comment