3

I am trying to send very large emails out, usually are in the range of 3 MB but can be larger. The problem is that our adsl line isn't always very stable in terms of performance and our email hosting changed from a local solution to a remote one. This means that by using the normal C# send method I keep reaching the timeout reached exception. And I do not want to just increase the timeout. For a 3Mb email to upload succeed I need a timeout of 400 sec.

Following answer here now I can get the emails to send via the local smtp service, but only if I don't attach an attachment. If the attachment is in the area of 3Mb its fails outright. If it's small it fails when I try to pull the email down with outlook.

I did remove the max file attachment size from the smtp service. Any other setting or so I could have gotten wrong?

And if it helps the pc that runs is smtp service is a virtual machine running win 2008 on a pc running win 7.

Community
  • 1
  • 1
blackwolfsa
  • 327
  • 3
  • 14
  • Why don't you break your big message into several messages? – Dennis Sep 11 '12 at 13:36
  • 1
    You could either chunk the data in smaller messages, or reconsider your approach and host your files in a storage area mailing out links instead. Moving around megabytes via emails is just asking for trouble in the long run (at some point, the smtp server *will* blow up. And what about email backups ?) – Alex Sep 11 '12 at 13:37
  • you could drop the file into a dropbox and just pop in a link to it in your email. – d4v3y0rk Sep 11 '12 at 13:57
  • The link will not work since the data is not for another program. We just use the email as an transfer medium. As to backups, we backup the data at both ends where applicable. This data does not need backing up since 4 hours later it is of no use anymore and there is new data. – blackwolfsa Sep 12 '12 at 05:36
  • 3 MB isn't very large by today's standards. Are you in a very recluse location (Antarctica? Rural Savo?) or should you be seriously investigating how this can take more than 400 seconds? – tripleee Sep 12 '12 at 06:33
  • 2mpbs line, upload speed of 769kbps. We live in south africa and we have a monopoly on adsl. The problem is here the line is of really bad. And will drop to much lower speeds most of the time. We are due for a diginet line with 2mbps upload, so will see how that goes. – blackwolfsa Sep 12 '12 at 07:02
  • I don't think there is any basic difference between sending by local smtp service and sending directly. The only difference is the smtp service may help you to retry some times. If your adsl is not stable, you should send small mail to improve success rate by only sending the sharing file URL. otherwise, I don't think you can make it with the poor ADSL. – Tony Zhu Oct 03 '12 at 23:33
  • Have you solved this issue? An alternative is to split up the message 4 ways and drop that into SQL ( your favorite flavor ). At that point you can send it in quarters, retrying each time until all 4 parts make it through. – Taersious Oct 08 '12 at 21:22
  • If you've got an automated routine for sending emails and generating your 3MB of data, maybe compression would help? you can get C# library files for creating zip files automatically such as ICSharpCode, SharpZipLib (presumably you've already considered this?) It's worth mentioning. Or maybe consider another internet service, such as automated FTP upload to a server. – Phill Oct 17 '12 at 13:25

2 Answers2

0

If it's just about transferring data and e-mail is only the medium, why not drop the whole email-solution, and host a webservice at the remote connection, that can accept chunks and assemble the file once all chuncks are received? Or even simpler, as Phill suggests, use an FTP or something with resume-upload capabilities already in place? - The problem isn't your system and I don't think you're gonna find any kind of config for e-mail that resolves this. Your connection seems to be as fast (and as stable) as the internet of the 90's. A solution for transferring larger amounts of data from that time may be the simplest way to solve your issue.

Arno Peters
  • 675
  • 5
  • 13
0

I fixed it using SendAsync, and used it as follows

I put all my emails in a Fifo list. After I added new emails I remove one and try to send it. This is my send function

public void Sender()
    {
        if (Globalcls.Message_list.Count == 0)
            return;
        SmtpClient client = new SmtpClient();
        client.Credentials = new System.Net.NetworkCredential(Globalcls.settings.username, Globalcls.settings.password);
        client.Port = Convert.ToInt32(Globalcls.settings.portS);


        client.Host = "smtp.xdsl.co.za";

        client.SendCompleted += new SendCompletedEventHandler(MailSendCallback);

        if (Globalcls.Message_list.Count > 0)
        {
            try
            {
                client.SendAsync(Globalcls.Message_list[0].msg, "1");


            }
            catch (Exception ex)
            {
                //do exception stuff here, only cut here to make post shorter
            }
        }

 static void MailSendCallback(object sender, AsyncCompletedEventArgs arg)
    {
        // oncomllete event for async send.
        if (arg.Error != null)
        {
            //mail did not send, here I do not remove it and increment an counter so  to delete a mail that keeps failing
        }
        else
        {

            Form1 frm1 = new Form1(); 
            frm1.que("email sent to " + Globalcls.projects[Globalcls.Message_list[0].project].name);
            frm1.Dispose();
            Globalcls.Message_list[0].msg.Dispose();
            foreach (string meh in Globalcls.Message_list[0].files)
                File.Delete(meh);
            Globalcls.Message_list.RemoveAt(0);
        }
        if (Globalcls.Message_list.Count > 0)
        {
            Form1 frm2 = new Form1();
            frm2.Sender();
            frm2.Dispose();
    }
blackwolfsa
  • 327
  • 3
  • 14