Edit: I'm able to send mail without attachment
Getting this error while trying to send mail:
System.Net.Mail.SmtpException: The operation has timed out.
Following is my code:
public static void SendMailMessage(string to, string subject, string body, List<string> attachment)
{
MailMessage mMailMessage = new MailMessage();
// string body; --> Compile time error, body is already defined as an argument
mMailMessage.From = new MailAddress("[email protected]");
mMailMessage.To.Add(new MailAddress(to));
mMailMessage.Subject = subject;
mMailMessage.Body = body;
foreach (string s in attachment)
{
var att = new Attachment(s);
mMailMessage.Attachments.Add(att);
}
// Set the format of the mail message body as HTML
mMailMessage.IsBodyHtml = true;
// Set the priority of the mail message to normal
mMailMessage.Priority = MailPriority.High;
using (SmtpClient mSmtpClient = new SmtpClient())
{
mSmtpClient.Send(mMailMessage);
}
}
Web Config
<system.net>
<mailSettings>
<smtp from="mailid">
<network host="smtp.gmail.com" port="587" enableSsl="true" userName="username" password="pass" />
</smtp>
</mailSettings>
Note : Attachments not exceeding its limit(below than 25 mb)
What can I do to solve this problem, or what am I missing?
Next to To..., type the e-mail address you want to send to. Click on the icon of the paperclip to attach message or go to Insert->File This will bring up a window where you can browse your folders and select the file(s) you want to attach.
So basically we discovered during the chat that the problem occurs because the upload of the attachments takes to long.
One way to solve it is to increase the timeout value of the SmtpClient:
mSmtpClient.Timeout = int.MaxValue;
Note: Use int.MaxValue for testing but use a more realistic value for the deployed solution.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With