i have to send mail with attachments.my code works only for files smaller than 4mb.
I have already checked everything on net but everyone suggest the same soolution.That is to change httpruntime attributes in webconfig which i have already done.
<httpRuntime maxRequestLength="10000" executionTimeout="1500" />
i have changed everything that has “timeout” attribute in web config.Also made a change in KeepAlive in application configuration in IIS but even after doing all this changes the problem still remain in my application.everytime i try to upload files larger than 4mb the connection timeout after exactly 1.5 minutes.
Code in click event
protected void btnSend_Click(object sender, EventArgs e)
{
MailMessage msg = new MailMessage();
SmtpClient smtp = new SmtpClient();
string strFrom = txtFrom.Text;
string strTo = txtTo.Text;
string strSubject= ddlTemplate.SelectedItem.Text.ToString();
string strBody =txtBody.Text;
string strCC =txtCC.Text;
string strBCC =txtBCC.Text;
if (this.fuAttachments.HasFile)
{
Attachment at = new Attachment(fuAttachments.PostedFile.InputStream,fuAttachments.PostedFile.ContentType);
at.ContentDisposition.FileName = this.fuAttachments.FileName;
msg.Attachments.Add(at);
}
smtp.EnableSsl = true;
msg.From = new MailAddress(strFrom);
msg.To.Add(strTo);
msg.Subject = strSubject;
msg.Body = strBody;
//smtp = new SmtpClient("localhost");
//smtp.UseDefaultCredentials = true;
try
{
smtp.Send(msg);
}
catch (SmtpException Ex)
{
throw;
}
if (msg.Attachments.Count > 0)
{
//Clear the attachments and delete the sessionid folder from tempFiles
msg.Attachments.Dispose();
}
}
I have found the culprit in my application.It is smtp client’s timeout property that was stopping the process after around 1.5minutes.Default value for this property is 100 seconds which i changed to 1500 seconds(1500000ms as this property takes values in ms) and successfully mailed with attachment.
see this for more info.
by the way i tested it with 21mb attachment.