发送电子邮件时,我在进度条上有错误

时间:2017-07-27 00:04:33

标签: c# winforms visual-studio-2013

我希望在发送自动生成的电子邮件时有一个进度条但我收到错误。请帮我解决这个问题。任何类型的回应都非常感谢。

我不知道自己是否走在正确的道路上,我是C#的初学者,只是依赖在线指南。

此行有错误

private void btnSend_Click(object sender, EventArgs e) { //Cursor.Current = Cursors.WaitCursor; try { MailMessage loginInfo = new MailMessage(); string em = "angelicasarimo15@gmail.com"; loginInfo.To.Add(em.ToString()); loginInfo.From = new MailAddress("vicserna1997@gmail.com"); loginInfo.Subject = "Requesting Supplies"; loginInfo.Body = "We want another supplies for blah blah blah" + System.Environment.NewLine + "This is a system generated email."; loginInfo.IsBodyHtml = true; SmtpClient smtp = new SmtpClient(); smtp.Host = "smtp.gmail.com"; smtp.Port = 587; smtp.EnableSsl = true; smtp.Credentials = new System.Net.NetworkCredential("vicserna1997@gmail.com", "*Pass*"); smtp.Send(loginInfo); MessageBox.Show("Email has been sent!", "Sent", MessageBoxButtons.OK); progressBar1.Visible = true; progressBar1.Style = ProgressBarStyle.Marquee; System.Threading.Thread thread = new System.Threading.Thread(new System.Threading.ThreadStart(btnSend_Click)); thread.Start(); } catch { MessageBox.Show("Message not sent please check you internet connection", "Not Sent", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); } }

String getBaseUrl(HttpServletRequest req) {
    return req.getScheme() + "://" + req.getServerName() + ":" + req.getServerPort() + req.getContextPath();
}

1 个答案:

答案 0 :(得分:2)

使用SendAsync并订阅SendCompleted。这将通知您发送过程已完成。我不相信它可以获得发送电子邮件的进展。