SMTP.Send() 在电子邮件发送会话之后(或期间)返回?

发布于 2024-11-06 04:09:52 字数 677 浏览 0 评论 0原文

此 vb.net 代码似乎运行时才起作用...并且在看到“电子邮件已发送”消息后,我将程序再打开 5-10 秒。如果我等待 0-1 秒,然后关闭 prg,电子邮件将无处可去。

SMTP.Send() 是在电子邮件完全发送后返回...还是在电子邮件开始发出时返回? (有时电子邮件正文和/或文件附件可能长达 10k,并且需要一段时间。)

Dim myMailMessage As New Net.Mail.MailMessage()
myMailMessage.From = New Net.Mail.MailAddress(fromEmail)
myMailMessage.To.Add(toEmail)
myMailMessage.Subject = strSubject
myMailMessage.Body = strBody
myMailMessage.IsBodyHtml = True

Dim SMTP As New Net.Mail.SmtpClient("smtp.gmail.com")
SMTP.Port = 587
SMTP.EnableSsl = True
SMTP.Credentials = New System.Net.NetworkCredential(fromEmail, password)
SMTP.Send(myMailMessage)
call MsgBox("Email is completely done sending")

This vb.net code seems to work ONLY if run... and I keep the program open for an additional 5-10 secs AFTER I see the "email sent" message. If I instead wait 0-1 secs, and then close the prg, the email goes nowhere.

Does SMTP.Send() return AFTER the email is completely sent... or just when the email BEGINS to go out? (Sometimes the email body and/or file attachment might be 10k long, and take a while.)


Dim myMailMessage As New Net.Mail.MailMessage()
myMailMessage.From = New Net.Mail.MailAddress(fromEmail)
myMailMessage.To.Add(toEmail)
myMailMessage.Subject = strSubject
myMailMessage.Body = strBody
myMailMessage.IsBodyHtml = True

Dim SMTP As New Net.Mail.SmtpClient("smtp.gmail.com")
SMTP.Port = 587
SMTP.EnableSsl = True
SMTP.Credentials = New System.Net.NetworkCredential(fromEmail, password)
SMTP.Send(myMailMessage)
call MsgBox("Email is completely done sending")

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

末骤雨初歇 2024-11-13 04:09:52

http://msdn.microsoft.com/en-us/library/swas0fwc.aspx

这不是异步调用,因此它仅在电子邮件发送后返回。

http://msdn.microsoft.com/en-us/library/swas0fwc.aspx

It's not an asynchronous call, so it only returns after the e-mail has been sent.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文