Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6158427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:57:20+00:00 2026-05-23T20:57:20+00:00

using System; using System.Collections.Generic; using System.Text; using System.Diagnostics; using System.IO; using System.Net; using System.Net.Mail;

  • 0
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 < 10) command = command.Replace("%MONTH%", "0" + t1.Month);
            else command = command.Replace("%MONTH%", "" + t1.Month);

            if (t1.Day < 10) command = command.Replace("%DAY%", "0" + t1.Day);
            else command = command.Replace("%DAY%", "" + t1.Day);

            if (t1.Hour < 10) command = command.Replace("%HOUR%", "0" + t1.Hour);
            else command = command.Replace("%HOUR%", "" + t1.Hour);

            if (t1.Minute < 10) command = command.Replace("%MINUTES%", "0" + t1.Minute);
            else command = command.Replace("%MINUTES%", "" + t1.Minute);

            if (t1.Second < 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);
        }
    }
}

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?

EDIT :

I made another test

            var ts1 = DateTime.Now;
            smtpClient.Send(mailMsg);
            var ts2 = DateTime.Now;

and it confirmed that smtpClient.Send(mailMsg); is responsible for slowing. Any idea why?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T20:57:20+00:00Added an answer on May 23, 2026 at 8:57 pm

    I faced the same problem, It seems that the SMTP server is doing some kind of checking before sending the mail.

    I Solved my problem by sending the mail in async way using a new thread as shown below.

    private void SendMail(string from, string to)
    {
        //your logic to send the mail
    }
    

    to send the mail in async way.

    ThreadStart threadStart = delegate() { SendMail(from, to); };
    Thread thread = new Thread(threadStart);
    thread.Start();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

using System; using System.Collections.Generic; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication1 { class Program {
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace GenericCount { class Program {
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Xml.Linq; namespace ConsoleApplication2 { class
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Runtime.Caching; namespace ConsoleApplication4 { class
using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.Text; namespace ConsoleApplication1 { public
Consider the following snippet: using System; using System.Collections.Generic; using System.Linq; using System.Net; namespace ForumLogins
This is my problem: using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication1
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.ComponentModel.DataAnnotations; namespace Entities.EntityExtensions { [MetadataType(typeof(IncomeDeclaration_Validation))]
I have a C# class the returns a List, using System.Collections.Generic Lists not F#
With a model such as ... using System; using System.Collections.Generic; using System.Linq; using System.Text;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.