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


- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- 输入按键事件处理程序 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01