【问题标题】:Show Progress bar with smtpClient.send使用 smtpClient.send 显示进度条
【发布时间】:2011-02-23 13:20:06
【问题描述】:

我正在使用此功能通过 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() 一起使用。

有什么帮助吗?

谢谢

【问题讨论】:

    标签: c# email smtp


    【解决方案1】:

    您应该使用SendAsync 并订阅SendCompleted,以了解发送邮件的时间。但是,无法获取发送过程的进度...

    【讨论】:

    • 除此之外,指示一封邮件的进度是非常无用的,因为将数据发送到邮件服务器只是总时间的一小部分。剩下的时间都在等待服务器响应请求和发送邮件后等待服务器响应。
    • 视情况而定。我认为对于大附件,将邮件提交到服务器会花费大部分时间。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-25
    • 2012-03-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多