am using system.net.mail to send email as shown below, but its too slow. it takes about a minute to send, whats wrong with my code. Am calling the code below in backgroundworker_dowork.
[edit]: is there a faster alternative, maybe free or open source code
' 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
Leave it up to the SMTP server to distribute the email to the recipients.
Use the Bcc property if you don’t want the recipient to see the other names.