Hi @Gani_tpt,
It depends on network speed + sending server load + receiving server load.
You could try using async.Or you could consider popping up a notification stating that the email has been sent to the user later, rather than forcing them to wait.
The following code example demonstrates sending an email message asynchronously.
protected void SendAsyncEmail(object sender, EventArgs e)
{
string to = txtTo.Text;
string from = txtEmail.Text;
string password = txtPassword.Text;
string subject = txtSubject.Text;
string body = txtBody.Text;
Thread email = new Thread(delegate()
{
SendEmail(to, from, password, subject, body);
});
email.IsBackground = true;
email.Start();
ClientScript.RegisterStartupScript(GetType(), "alert", "alert('Email sent.');", true);
}
private void SendEmail(string to, string from, string password, string subject, string body)
{
using (MailMessage mm = new MailMessage(from, to))
{
mm.Subject = subject;
mm.Body = body;
mm.IsBodyHtml = false;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.EnableSsl = true;
NetworkCredential NetworkCred = new NetworkCredential(from, password);
smtp.UseDefaultCredentials = true;
smtp.Credentials = NetworkCred;
smtp.Port = 587;
smtp.Send(mm);
}
}
Best regards,
Lan Huang
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.