Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sending multiple email with CDO 1

Status
Not open for further replies.

Mighty

Programmer
Feb 22, 2001
1,682
US
Guys,

I am trying to send an email to multiple users but I don't want to just Bcc them on all the mail as some users use Hotmail and this automatically puts the email in the junk folder if you are Bcc'ed. Therefore, I set up the following code:

Dim objCDO

' Create an email object
Set objCDO = Server.CreateObject("CDONTS.NewMail")

' Set the generic email options
objCDO.Mailformat=0
objCDO.Bodyformat=0
objCDO.Subject = Request.Form("Subject")
objCDO.From = myEmail

' Send the email to each user
do while not rs.EOF
objCDO.Body = MailBody(rs("UserName")) line 221
objCDO.To = rs("Email")
objCDO.Send
Recipients = Recipients & rs("Email") & ", "
rs.MoveNext
loop

set objCDO = nothing

Using the Recipients variable, I can see that it is generating the email addresses correctly. However, when I run this code, it always sends the email to the first person and then fails with the following error:

error '80040108'
/intranet/admin/sendEmail.asp, line 221

Can I send emails like this using CDO?? Mise Le Meas,

Mighty :)
 
Try creating and destroying the object in the loop... I've had problems before trying to replace existing information about the object, and the re-sending.


do while not rs.EOF
Set objCDO = Server.CreateObject("CDONTS.NewMail")

' Set the generic email options
objCDO.Mailformat=0
objCDO.Bodyformat=0
objCDO.Subject = Request.Form("Subject")
objCDO.From = myEmail

' Send the email to each user
objCDO.Body = MailBody(rs("UserName")) line 221
objCDO.To = rs("Email")
objCDO.Send
Recipients = Recipients & rs("Email") & ", "
rs.MoveNext
set objCDO = nothing
loop

:)
paul
penny1.gif
penny1.gif
 
Thanks Paul,

That worked a treat!! Mise Le Meas,

Mighty :)
 
This is how I do it, feel free to hack and borrow.

Do While Not rsMail.EOF
For Each Field in rsmail.Fields
If Field.name="Guest_ID" then txtname = Field.Value
If Field.name="Guest_Email" then txtemail = Field.Value
Next
name=txtname
senderEmail=strFrom
subject=strSubject
recipient=txtemail
body=strBody
set msg=Server.CreateOBject("JMail.Message")
msg.Logging=true
msg.silent=true
msg.From=strEmailFrom
msg.FromName=strFrom
msg.AddRecipient recipient
msg.Subject=strSubject
strSentTo = vbcrlf&vbcrlf& "Message sent to: "&rsMail.Fields("Guest_Email").Value
strSentTo = strSentTo &vbcrlf&"ID Number: "&rsMail.Fields("Guest_ID").Value
strSentTo = strSentTo &vbcrlf&vbcrlf&" &Request.ServerVariables("SERVER_NAME")&"/mailsend/unsubscribe.asp?ID="& rsMail.Fields("Guest_ID").Value &"&Email="& rsMail.Fields("Guest_Email").Value
msg.body=strBody & strSentTo
strTo=rsMail.Fields("Guest_Email").Value
If strTo<>&quot;&quot;then
msg.AddRecipient strTo
if not msg.Send(strHost)then
Response.Write&quot;<font face=Arial size=2>Send Failure...Error was &quot;&msg.log&&quot; User: &quot;&strTo&&quot;</font><BR>&quot;
iFail=iFail+1
else
Response.Write&quot;<font face=Arial size=2>Message sent to: &quot;&strTo&&quot;</font><BR>&quot;
iSuccess=iSuccess+1
end if
end if
rsMail.MoveNext
Set msg=Nothing
Loop Tim Russell
 
Tim,

One question - what does the following line do??

msg.silent=true

Is it possible to get a read/delivery notification when you send an email using CDO? Mise Le Meas,

Mighty :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top