使用 smtpClient.send 显示进度条

Show Progress bar with smtpClient.send(使用 smtpClient.send 显示进度条)
本文介绍了使用 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 
 backup number- " + 
        backupnumber + " 
 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 显示进度条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)