Show progress bar with smtpClient.send

I use this function to send letters through gmail.

private bool uploadToGmail(string username, string password , string file , 
    string backupnumber)
{
    MailMessage mail = new MailMessage();
    SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
    mail.From = new MailAddress("jain@gmail.com");
    mail.To.Add("jain@gmail.com");
    mail.Subject = "Backup mail- Dated- " + DateTime.Now + " part - " + 
        backupnumber;
    mail.Body = "Hi self. This mail contains \n backup number- " + 
        backupnumber + " \n Dated- " + DateTime.Now ;

    System.Net.Mail.Attachment attachment;
    attachment = new System.Net.Mail.Attachment(file);
    mail.Attachments.Add(attachment);

    SmtpServer.Port = 587;
    SmtpServer.Credentials = 
        new System.Net.NetworkCredential("jain@gmail.com", "password");
    SmtpServer.EnableSsl = true;

    SmtpServer.Timeout = 999999999;
    SmtpServer.Send(mail);
    //  MessageBox.Show("mail Sent");
    return true;
}

Now I want to show a progress bar (in the case of a large attachment) to show the download. Is it possible? I think I know how to use the progress bar, but I don’t know how to use it with Smtpclient.send ().

any help?

thank

+3
source share
1 answer

You must use SendAsync and sign up for SendCompleted to know when your mail has finished sending. It is not possible to get the progress of the sending process, though ...

+3
source

Source: https://habr.com/ru/post/1794136/


All Articles