sending mail using smtp is too slow in

Ankit tewari
Ankit t...
40 Points
20 Posts

when i am sending email (with attached 7 mb image) then it is taking approx 50 seconds. So I am using this code. but still not working.

Thread email = new Thread(delegate ()
SendMail("a", splitMailCC);
email.IsBackground = true;
Views: 700
Total Answered: 1
Total Marked As Answer: 0
Posted On: 14-May-2019 03:41

Share:   fb twitter linkedin
Use SmtpClient.SendAsync instead of using your own custom code
 - Stevan  14-May-2019 10:38
Rahul Maurya
Rahul M...
1244 Points
217 Posts

I think you are trying to send email in separate thread to avoid blocking the requested thread.

My suggestion is, you should use SmtpClient.SendAsync method. This method does not block the calling thread.

public void SendAsync (System.Net.Mail.MailMessage message, object userToken);


public static class EmailService
        static bool mailSent = false;
        private static void SendCompletedCallback(object sender, AsyncCompletedEventArgs e)
             String token = (string)e.UserState;

            if (e.Cancelled)
            if (e.Error != null)
                //Message sent
            mailSent = true;
        public static void Send()
            SmtpClient client = new SmtpClient("");
            MailAddress from = new MailAddress("fromemailaddress");
            MailAddress to = new MailAddress("toemailaddress");
            MailMessage message = new MailMessage(from, to);
            message.Body = "This is a nice test email message sent. ";
            message.Subject = "test message";
            Attachment attachment = new Attachment("");
            client.SendCompleted += new
            string userState = "test message1";
            client.SendAsync(message, userState);

In the above example following line is for handling call back when send email completed:

client.SendCompleted += new

If you don't want this then you can skip this part by commenting it.

Posted On: 14-May-2019 10:12
Ankit, Have u resolved your issue?
 - Rahul Maurya  29-May-2019 10:40
 Log In to Chat