Send email through code

A

Annette

I have a table that I loop through to get record selection criteria
and email addresses. Within this loop I send an email consisting of a
pdf file attachment. When I use Outlook I get the pesky "sending on
behalf of" message so I changed to use cdo. Here is the problem (see
code below). When I use outlook, each email gets the file attachment
with the pdf report according to the record selection criteria. When I
use CDO, each email gets a file attachment with the same data. It is
as if it can't understand the record selection criteria. Each WITH was
is placed in the same place in the Do Until section. I thought of
killing the file but it doesn't appear that it ever gets deleted. Why
would the outlook way attach correct output file when CDO doesn't
appear to be getting the new outcome. It is as iff CDO didn't allow
for the replacement of the file with the newly created pdf. The path
location of AttachmentPath is something like this:"C:\This Folder\Then
this folder\DailyReport.pdf". I have one hair left. Please help!

'With objOutlookMsg
' 'add the to recipients to the email message
' Set objOutlookRecip = .Recipients.Add(TheAddress)
' objOutlookRecip.Type = olTo
' 'set the subject
' .Subject = "This is the email subject" & MuniName
' 'add attachment
' If Not IsMissing(AttachmentPath) Then
' Set objOutlookAttach = .Attachments.Add(AttachmentPath)
' End If
' 'windows will probably complain here with that pesky
send on behalf message
' .Send
'End With




'This option will use CDO which doesn't give that pesky send on
behalf message
Set objMessage = CreateObject("CDO.Message")
With objMessage
.Subject = "This is the subject " & MuniName
.From = "(e-mail address removed)-croix.wi.us"
.To = TheAddress
.TextBody = "For your review."
Set objattachment = objMessage.AddAttachment(AttachmentPath)
.Send
End With
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top