使用smtpClient.send显示进度条 [英] Show Progress bar with smtpClient.send

查看:96
本文介绍了使用smtpClient.send显示进度条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用此功能通过gmail发送邮件。

I am using this function to send mails via 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;
}

现在我想显示一个进度条(万一有一个大的附件)显示上传。这可能吗 ?我想我知道如何使用进度条,但不知道如何使用Smtpclient.send()。

Now I want to show a progress bar (in case there is a large attachment) to show the upload . Is this possible ? I think I know how to use a progress bar, but don't know how to use it with Smtpclient.send() .

任何帮助?

谢谢

推荐答案

你应该使用 SendAsync 并订阅 SendCompleted ,知道发送完邮件的时间。没有办法获得发送过程的进度,但...

You should use SendAsync and subscribe to SendCompleted, to know, when the sending your mail completed. There is no way to get the progress of the send process, though...

这篇关于使用smtpClient.send显示进度条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆