SMTP and gmail using SSL time out while sending file

I use the following code to send and email with an attachment

it works when sending a small attachment at 300 MB but when trying to send 4-5 MB file et times out.

so my question is, doanybody knows why

public void SendEmailSsl(MyMailMessage msg)

{

try

{

System.Net.Mail.MailMessage mm = new System.Net.Mail.MailMessage();

mm.From = new System.Net.Mail.MailAddress(msg.EmailFrom);

mm.Body = msg.EmailMessage;

mm.Subject = msg.EmailSubject;

mm.IsBodyHtml = false;

foreach (object o in msg.EmailTo)

{

mm.To.Add(new System.Net.Mail.MailAddress((string)o));

}

foreach (object o in msg.Attachments)

{

mm.Attachments.Add(new System.Net.Mail.Attachment((string)o));

}

System.Net.Mail.SmtpClient sc = new System.Net.Mail.SmtpClient(_serverSmtp, _portSmtp);

sc.Credentials = new NetworkCredential(_userSmtp, _passwordSmtp);

sc.EnableSsl = true;

sc.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;

sc.Send(mm);

}

catch (Exception err) { throw new SmtpException(err.Message); }

}



Answer this question

SMTP and gmail using SSL time out while sending file

  • Solitaire

    The request may be taking more than 100 seconds whicn is the default timeout for a syncronous send.  You need to increase the value of SmtpClient.Timeout to something larger than the default value.

  • lalle

    I have another question.

    when trying sending a mail using the code above with the timeout set to 20 minutes, i get instant timeouts i don't know why but i let it run and after 2-16 tries it get through and send the mail, but how come it starts with timeouts

    regards

    splyf


  • Hermes 68

    sure its milliseconds
  • ripern

    Thanks a lot, just the missing part i needed, i thought the timeout was a function for timing out a missing reply, and not the total time for sending
  • Shuang Ma - ?爽

    Just to make sure...The value you are setting is in milliseconds, right

  • SMTP and gmail using SSL time out while sending file