SMTP.Send() 在电子邮件发送会话之后(或期间)返回?
此 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
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.