使用C#发送带有23 MB附件的电子邮件 [英] Send Email with attachment of 23 MBusing C#

查看:75
本文介绍了使用C#发送带有23 MB附件的电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,


我发送的电子邮件带有22 MB的附件,并且代码最终出现错误,即操作超时".此代码适用于1 MB的文件.

这是ME使用的代码:

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 :

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 ?

推荐答案



我认为超时是因为您直接访问PostedFile输入流.
您是否已先尝试将文件加载到MemoryStream中,并且已读取所有内容,然后使用填充的MemoryStream发送电子邮件?

我从未发送过这么大的电子邮件,但这应该不是问题(请确保您的电子邮件提供商和收件人提供商必须支持如此大的文件).

希望这会有所帮助!

致以诚挚的问候,祝您编程愉快,
克里斯
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


这篇关于使用C#发送带有23 MB附件的电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆