c# - SMTP SendEmail hung without any error our response -


i using smtpclient send email attachment. send email method below

  public static void sendemail(string subject, string messagebody, string toemailid, list<string> attachments=null, list<string> cc = null, bool isbodyhtml = false)     {         try         {              var fromaddress = new mailaddress("email@email.com");             var toaddress = new mailaddress(toemailid);             const string frompassword = "password";               var smtp = new smtpclient             {                 host = "smtp.gmail.com",                 port = 587,                 enablessl = true,                 deliverymethod = smtpdeliverymethod.network,                 usedefaultcredentials = false,                 credentials = new networkcredential(fromaddress.address, frompassword),                 timeout= 1000 * 60             };               using (var message = new mailmessage(fromaddress, toaddress)             {                  subject = subject,                 body = messagebody,                 isbodyhtml = isbodyhtml               })             {                 if (cc != null)                 {                     foreach (string s in cc)                         message.cc.add(s);                 }                  if (attachments != null)                 {                     foreach (string attachment in attachments)                     {                         message.attachments.add(new attachment(attachment));                      }                 }                    console.writeline("email sending");                 smtp.send(message);                  //clean attachments                 foreach (attachment attachment in message.attachments)                 {                     attachment.dispose();                 }              }          }          catch (exception ex)         {             throw ex;         }      } 

i able send email without attachment above smtp config. when use attachment program hangs after smtp.send(message) without giving response/error.

the same code runs fine on local machine when upload server , run dont' response. have tried following steps on server.

  1. opened port 587 on server.
  2. gave permission attachment folder.

there firewall installed on server , blocking emails attachment of size more 1 mb. blocking smtp connections.


Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -