views:

62

answers:

1

I’ve gone through this link. (http://connect.microsoft.com/VisualStudio/feedback/details/544562/cannot-send-e-mails-with-large-attachments-system-net-mail-smtpclient-system-net-mail-mailmessage)

It is not possible to send an e-mail with an attachment larger than 4 MB in .NET Framework 4.0. The same code works for small and large files if you set the target platform from .NET Framework 4.0 to .NET Framework 3.5. So this cannot be a problem with our mail-configuration! I get no error if I attach e.g. 10 files of 2 MB! I searched through Google but I didn’t get it.

Workaround solution is not working fine as expected. After using this workaround for a while, I found that some files are corrupted. So this is not a solution for this bug.

We’ve applied that Microsoft patch and we’re still seeing the issue?
Can someone tell me how to fix this?

A: 

Possible workaround using SMTP Pickup Directory

I don't know if the bug is in code which sends the message via SMTP or in serialization MailMessage with large attachments. If it's in the sending and serialization is ok you might try to overcome it by using sending via the Pickup Directory.

Something like this:

        //create the mail message
        MailMessage mail = new MailMessage();

        //set the addresses
        mail.From = new MailAddress("[email protected]");
        mail.To.Add("[email protected]");

        //set the content
        mail.Subject = "This is an email";
        mail.Body = "this is the body content of the email.";

        //if we are using the IIS SMTP Service, we can write the message
        //directly to the PickupDirectory, and bypass the Network layer
        SmtpClient smtp = new SmtpClient();
        smtp.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;
        smtp.Send(mail);

You would need a running Microsoft SMTP server (Microsoft IIS, Microsoft Exchange) on the same machine as your code runs.

Alternative solution:

Using a third party SMTP component which does not have attachment size limitation might be a way to go (our Rebex Secure Mail .NET component is example of such SMTP library).

Martin Vobr