c# - SmtpException While sending mails in a bulk of 3 or more -
i using smtpclient
send emails.i using same code last 2years,but last day when send 3 or more emails 1 of them fail.when sent failed 1 again sent out.please me using aibn.com mail server.
public bool sendmail(string p_strfrom, string p_strdisplayname, string p_strto, string p_strsubject, string p_strmessage , string strfilename) { try { p_strdisplayname = _displayname; string smtpserver = _smtpserver; smtpclient smtpclient = new smtpclient(); mailmessage message = new mailmessage(); mailaddress fromaddress = new mailaddress(_from,_displayname); smtpclient.host = _smtpserver; smtpclient.port = convert.toint32(_port); string strauth_username = _username; string strauth_password = _password; if (strauth_username != null) { system.net.networkcredential smtpuserinfo = new system.net.networkcredential(strauth_username, strauth_password); smtpclient.usedefaultcredentials = false; if (_ssl) { smtpclient.enablessl = true; } smtpclient.credentials = smtpuserinfo; } message.from = fromaddress; message.subject = p_strsubject; message.isbodyhtml = true; message.body = p_strmessage; message.to.add(p_strto); try { smtpclient.send(message); log.writespeciallog("smtpclient mail sending first try success", ""); } catch (exception ee) { log.writespeciallog("smtpclient mail sending first try failed : " + ee.tostring(), ""); return false; } return true; } catch (exception ex) { log.writelog("smtpclient mail sending overall failed : " + ex.tostring()); return false; } }
got following error message
smtpclient mail sending failed : system.net.mail.smtpexception: failure sending mail. system.nullreferenceexception: object reference not set instance of object. @ system.net.mail.smtpconnection.getconnection(string host, int32 port) @ system.net.mail.smtpclient.send(mailmessage message) --- end of inner exception stack trace --- @ system.net.mail.smtpclient.send(mailmessage message)
i have changed mail server , working fine.may depends mail service restriction prevent flooding and/or spam.
Comments
Post a Comment