Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy does sending an email take so long?
    primarykey
    data
    text
    <pre><code>using System; using System.Collections.Generic; using System.Text; using System.Diagnostics; using System.IO; using System.Net; using System.Net.Mail; using System.Threading; namespace MGR_Backuper { class Program { static void Main(string[] args) { string file = "D:\\Programy\\WinRAR\\rar.exe"; string command = "C:\\Users\\Pawel\\Desktop\\Praca magisterska back\\mgrback-%YEAR%-%MONTH%-%DAY%-%HOUR%-%MINUTES%-%SECONDS%.rar"; string arg = "a \"%FILENAME%\" \"C:\\Users\\Pawel\\Desktop\\Praca magisterska\\*\" -m5 -ep1 -hppasspass -rr5 -inul -r0"; var t1 = DateTime.Now; command = command.Replace("%YEAR%", "" + t1.Year); if (t1.Month &lt; 10) command = command.Replace("%MONTH%", "0" + t1.Month); else command = command.Replace("%MONTH%", "" + t1.Month); if (t1.Day &lt; 10) command = command.Replace("%DAY%", "0" + t1.Day); else command = command.Replace("%DAY%", "" + t1.Day); if (t1.Hour &lt; 10) command = command.Replace("%HOUR%", "0" + t1.Hour); else command = command.Replace("%HOUR%", "" + t1.Hour); if (t1.Minute &lt; 10) command = command.Replace("%MINUTES%", "0" + t1.Minute); else command = command.Replace("%MINUTES%", "" + t1.Minute); if (t1.Second &lt; 10) command = command.Replace("%SECONDS%", "0" + t1.Second); else command = command.Replace("%SECONDS%", "" + t1.Second); arg = arg.Replace("%FILENAME%", command); var t2 = DateTime.Now; Process proc = new System.Diagnostics.Process(); proc.EnableRaisingEvents = false; proc.StartInfo.FileName = file; proc.StartInfo.Arguments = arg; proc.Start(); while (!proc.HasExited) Thread.Sleep(50); var t3 = DateTime.Now; try { MailMessage mailMsg = new MailMessage(); mailMsg.To.Add("email@email.com"); // From MailAddress mailAddress = new MailAddress("email@email.com", "Sender"); mailMsg.From = mailAddress; // Subject and Body mailMsg.Subject = "MGR"; mailMsg.Body = "Backup magisterki"; mailMsg.Attachments.Add(new Attachment(command)); SmtpClient smtpClient = new SmtpClient("server.serv.com", 587); NetworkCredential credentials = new NetworkCredential("login", "password"); smtpClient.Credentials = credentials; smtpClient.Timeout = Int32.MaxValue; smtpClient.Send(mailMsg); } catch (Exception ex) { Console.WriteLine(ex.ToString()+"\n"); } var t4 = DateTime.Now; Console.WriteLine("Czas kompresji: \t{0:0.00}s", (t3 - t2).TotalSeconds); Console.WriteLine("Czas wysyłania: \t{0:0.00}s", (t4 - t3).TotalSeconds); Console.WriteLine("Czas całkowity: \t{0:0.00}s", (t4 - t1).TotalSeconds); Console.ReadKey(true); } } } </code></pre> <p>This is a simple program for backing up some data important to me by sending it to my email address. The created archive is around 1.5 MB. Sending email takes about 7-8 minutes. This is not because of bad connection because when I try to send the same file by email program or webmail it takes 5-6 seconds. Why is sending email this way is so slow?</p> <p><strong>EDIT :</strong> </p> <p>I made another test</p> <pre><code> var ts1 = DateTime.Now; smtpClient.Send(mailMsg); var ts2 = DateTime.Now; </code></pre> <p>and it confirmed that <code>smtpClient.Send(mailMsg);</code> is responsible for slowing. Any idea why?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload