上午使用system.net.mail發送郵件如下圖所示,但它太慢了。發送大約需要一分鐘,我的代碼有什麼問題。我在backgroundworker_dowork中調用下面的代碼。system.net.mail太慢了
[編輯]:有沒有更快的替代方案,也許免費或開源代碼
' send the email '
Dim smtp As SmtpClient = New SmtpClient()
Dim mail As New MailMessage()
Dim i As Long = 0
' SMTP settings '
With smtp
.Host = Trim$(sSMTP)
.Port = Trim$(iPort)
.UseDefaultCredentials = False
.Credentials = New System.Net.NetworkCredential(sUserID, sPword)
.EnableSsl = bSSL
End With
' create the mail '
With mail
If sAttachment <> vbNullString Then
.Attachments.Add(New Net.Mail.Attachment(sAttachment))
End If
.From = New MailAddress(sFromEmail, sFromName)
.ReplyTo = New MailAddress(sReplyTo)
.Subject = sSubject
.IsBodyHtml = True
.Body = sMessage
End With
For i = 0 To lstRecipients.Count - 1
mail.To.Add(lstRecipients(i))
Debug.Print(lstRecipients(i))
Try
smtp.Send(mail)
lSent += 1
bwrkMain.ReportProgress(CInt(100 * (i + 1)/iTotalRecipients))
SetStatus("Sent:" & lstRecipients(i))
Catch ex As Exception
bwrkMain.ReportProgress(CInt(100 * (i + 1)/iTotalRecipients))
SetStatus("Not Sent:" & lstRecipients(i))
End Try
mail.To.Clear()
Next
電子郵件不一定發送即時。通過互聯網發送和接收數據需要時間。爲什麼你認爲花1分鐘發送意味着它不能正常工作? – 2011-03-12 18:35:33
有多少個收件人?你是否以附件的形式發送文件?你的代碼似乎沒問題,也許郵件服務器有問題。 – 2011-03-12 18:35:47
@Jorge Villuendas我正在循環收件人列表,但爲了測試,我只使用兩個收件人。在測試中沒有任何提示,但我也希望對此進行測試。我正在使用谷歌smtp服務器進行測試 – Smith 2011-03-12 18:42:19