Click here to Skip to main content
15,910,980 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,


I am sending email with an attachment of 22 MB and code ends up with an error i,e " The operation was time-out". This code works fine with files of 1 MB.

Here is the code used by ME :

C#
try
{
    mail = new MailMessage();
    mail.To.Add(ConfigurationManager.AppSettings["PaypalEmail2"].ToString());
    mail.From = new MailAddress("abc@gmail.com");
    mail.Subject = "File Downloaded to VAM";
    mail.Body = "Name : " + txtName.Text + "\n Contact Details : " + txtPhone.Text + "\n Email ID :" + txtEmail.Text + "\n";
    mail.IsBodyHtml = true;

    if (flpFile.HasFile)
    {
        mail.Attachments.Add(new Attachment(flpFile.PostedFile.InputStream, flpFile.FileName));
    }
    smtp = new SmtpClient();
    smtp.Host = "smtp.gmail.com";
    smtp.Credentials = new System.Net.NetworkCredential("abc@gmail.com", "sample");
    smtp.EnableSsl = true;
    smtp.Send(mail);

    txtEmail.Text = txtName.Text = txtPhone.Text = string.Empty;
}
catch (Exception ex)
{
          // so something 
}
finally
{
    mail = null;
    smtp = null;
}



Any suggestions ?
Posted
Comments
Mahendra Dhande 16-May-13 10:02am    
same problem me please help

1 solution

Hi,

I think the timeout is because you directly access the PostedFile input stream.
Did you already tried first to load the file into a MemoryStream and if everything was read you send the email using the filled MemoryStream?

I never sent emails this big, but this should not be a problem (sure, your Email provider and the recipient provider must support such big files).

Hope this helps!

Best regards and happy coding,
Chris
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900