Freigeben über


Workflow problem in sending Email attachments of large file size

When a large file size ( typically > 1 MB ) is sent as an Email attachment through Workflow, we might see timed out exception. The exact error message is “System.Net.Mail.SmtpException: The operation has timed out. at System.Net.Mail.SmtpClient.Send(MailMessage)”

To overcome this, rather than just sending email via SMTP, pickup directory can be used in which case the IIS takes the responsibility of delivering the emails with attachment.

 SmtpClient client = new SmtpClient();
 client.Host = "hostname";
 client.Port = 2095;
 client.Credentials = new System.Net.NetworkCredential("username", "password");
 client.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;  
 MailAddress from = new MailAddress(“FromEmailID”);
 MailAddress to = new MailAddress("ToEmailID”);
 // Specify the file location
 Attachment att1 = new Attachment("

c:\\Test.doc");

 MailMessage msg = new MailMessage(from, to);
 msg.Subject = "

Mail Test Success...";

 msg.Attachments.Add(att1);
 msg.Body = "

some text for message body";

 try
 {
      client.Send(msg);
      MessageBox.Show("

Mail Was Sent Successfully...");

 }
 catch (Exception ex)
 {
      //Exception Handling Mechanism
 }

Comments