The Samples
The following VB Script samples interface with an Access
database that contains the e-mail addresses. The second
sample also interfaces with an XML
file that contains the phrases typically found in bounced
messages. The downloadable code
includes the source code shown below along
with the Access and XML files. The samples listed on this
page vary slightly from the downloadable code, as the code below
has been edited to fit the newsletter format.
SAMPLE 1: Constructing and sending the message...
In this sample, we will send a message with a friendly address
in the From: header, and our bounce address specified as the
reverse-path. This example uses VB Script and the EasyMail
SMTP object. The The SMTP object contains a FromAddr property,
and by default the SMTP object will use the value specified by
this property for both the reverse-path and automatic creation of
the From: header. We will override this behavior by setting
the OptionFlags property to 1 which turns off the automatic
creation of the From: header. We will then create the From:
header ourselves with the AddCustomHeader() method.
'To do: Set the following variables:
strLicenseKey = "Newsletter Sample/02V4BFDSFFDFSD62"
strMailServer="mail.yourdomain.com"
strBounceBoxDomain="yourdomain.com"
strFriendlyFromName="Joe Sender"
strFriendlyFromAddress="joe.sender@domain.com"
'End To Do
Dim objSMTP, Data, RS, nRetVal
'create EasyMail SMTP object and set basic properties
Set objSMTP = CreateObject("EasyMail.SMTP")
objSMTP.LicenseKey = strLicenseKey
objSMTP.MailServer = strMailServer
objSMTP.OptionFlags = 1
objSMTP.AddCustomHeader "From", _
"""" & strFriendlyFromName & """" &_
" <" & strFriendlyFromAddress & ">"
objSMTP.Subject = "Subject..."
objSMTP.BodyText = "Message text"
'setup database and select addresses.
'This sample uses a access database.
Set cnnData = CreateObject("ADODB.Connection")
strConnection = "DBQ=email_database.mdb"
cnnData.Open "DRIVER=" &_
"{Microsoft Access Driver (*.mdb)};" &_
strConnection
Set RS = CreateObject("ADODB.RecordSet")
RS.Open "SELECT hard_bounces,id, name, address" &_
" FROM email_table" &_
" where hard_bounces < 2" &_
" and soft_bounces < 4", cnnData, 1, 3"
'send to each address selected
Do While RS.EOF = False
'encode record id in from address
objSMTP.FromAddr = "bounce_" & RS("id") &_
"@" & strBounceBoxDomain
objSMTP.AddRecipient RS("name"), RS("address"), 1
nRetVal = objSMTP.Send
'if the recipients address fails right
'away then we mark it as a hard bounce now.
If nRetVal = 8 Then
RS("hard_bounces") = RS("hard_bounces") + 1
End If
'remove the recipients
objSMTP.Clear 1
RS.MoveNext
Loop
'free remaining resources
RS.Close
cnnData.Close
Page Navigator:
<< Back,
1,
2,
3,
4,
5,
Next >>
|
 |
|