Persits Software, Inc. Knowledge Base Articles

HOWTO: Sending messages to multiple recipients with AspEmail

Problem Description

The methods AddAddress, AddBcc, AddCC and AddReplyTo of AspEmail 4.5 (and all earlier versions) do not accept comma-separated lists of email addressed, therefore the following code snippet is incorrect:

' Incorrect for AspEmail 4.5 and earlier
Addr = ",,"
Mail.AddAddress Addr


To send email to multiple recipients, you must not use comma-separated lists of addresses. Instead, you must call the AddAddress (AddBCC, AddCC, AddReplyTo) method individually on each email address, as follows:

' Correct
Mail.AddAddress ""
Mail.AddAddress ""
Mail.AddAddress ""

If your application stores email addresses as comma-separated lists, you must extract individual addresses from it and pass them to AspEmail one by one.

The following code snippet extracts individual email addresses from a comma-separated string Addresses, and feeds them to AspEmail. The last address in the list is fed via the method AddAddress, the others via the method AddCC.

Set Mail = Server.CreateObject("Persits.MailSender")

Mail.Host = ""
Mail.From = ""
Mail.Subject = "Hello!"

Addresses = ",,"

   NextComma = InStr(Addresses, ",")
   If NextComma = 0 Then
      Mail.AddAddress Trim(Addresses)
      Exit Do
   End If

   Address = Left(Addresses, NextComma - 1)
   Mail.AddCC Trim(Address)

   Addresses = Mid(Addresses, NextComma + 1)