G-Lock EasyMail and External Scripting Languages
G-Lock EasyMail supports very powerful scripting languages: Microsoft
Visual Basic, JavaScript, Perl, and PHP, all driven by
components within the operating system (for VBasic and Javascript) or in a
separate installation (for Perl and PHP).
JavaScript and Visual Basic are included as components with
Internet Explorer, which should be installed already on your computer.
PerlScript requires download and installation of
ActivePerl
To use the PHPScript, you must download and install
PHP 5.2.0 installer
Installing PHPScript
After having downloaded the PHP installer, double click the mouse on the
php-5.2.0-win32-installer.msi file to begin the installation.
During the installation process select the items to install: Activescript
(required).
You can also select other features if you want. Click Next.

After having all the files installed, you must register the DLL on your
system. To
achieve this:
1. Click on the Start menu and open a Command Prompt window.
2. Type regsvr32 C:\PHP\ext\php5activescript.dll.
3. Click OK.
Now you can use the PHPScript in G-Lock EasyMail.

Writing Script in G-Lock EasyMail
To write a script in G-Lock EasyMail:
1. Click on the Tools menu and select Script Repository.

2. Click Add button in the Script Repository.
3. On the Microsoft Windows Script screen enter a script name. It can be
any name describing what the script is doing.
4. Select the script language: VBScript, JScript, PerlScript, or PHPScript.
5. Select the mode to execute the script:
Before the start of email campaign - the script will be executed before
the email campaign starts
Before sending email to every recipient - the script will be executed
before every email is sent
After sending email to every recipient - the script will be executed
after every email is sent
After the email campaign is complete - the script will be executed after
the email campaign is complete
6. Write the script and click on the Test button to test the script.

Click on the image to enlarge it
Script Samples
Sample 1
If the First_Name field for the recipient has no value in the Address Book, the
script
inserts "Friend" instead of the first name.
Script Name: replace empty first name
Language: VBScript
Execute script: Before sending email to every recipient
function main()
if Recipient.FieldByName("First_Name") = "" then
Recipient.FieldByName("First_Name") = "Friend"
end if
'msgbox Recipient.FieldByName - remove the comment to test the script
end function
_____________________________________________________________________
Sample 2 If the recipient's first name begins from the
lower case letter in the Address
Book, the script changes it to the upper case letter.
Script Name: write first name from the upper case letter
Language: VBScript
Execute script: Before sending email to every recipient
function main
' Recipient.AddField "First_Name", "alex" - remove the
comment to test the script Temp = Recipient.FieldByName("First_Name")
Temp = UCase(Mid(Temp,1,1))+ Mid(temp,2, Len(Temp))
Recipient.FieldByName("First_Name") = Temp
' msgbox Recipient.FieldByName("First_Name") - remove the
comment to test the script
end function
_____________________________________________________________________
Sample 3
The script stops the sending campaign after 100 emails are processed.
Script Name: stop sending after 100 emails
Language: VBScript
Execute script: Before sending email to every recipient
function main
if CInt(Message.ProcessedInSession) >= 100 then
Message.StopSending = 1
end if
end function
____________________________________________________________
Sample 4 The script writes sent and not delivered emails to different files.
The email addresses, to which the message was successfully sent are saved to
this file c:\Sent Items.txt. The email addresses, to which the delivery failed
are saved to this file c:\Not Delivered.txt.
Script Name: save sent and not delivered emails to the files
Language: VBScript
Execute script: After sending email to every recipient
function main
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim fso, f
if Recipient.Status = 0 then
FileName = "c:\Sent Items.txt"
else
FileName = "c:\Not Delivered.txt"
end if
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile(FileName, ForAppending, True)
f.WriteLine Recipient.FieldByName("Email") & ", " & Recipient.ServerResponse
' or f.WriteLine Recipient.FieldByName("Email") if you
don't want to save the mail server response
f.Close
end function
____________________________________________________________ Sample 5
The script saves sent and not delivered email addresses to
separate files: Sent
Items.txt and Not Delivered.txt. Plus, not delivered emails are separated into
different files based on reply codes: 452 4.2.1, 451, 550 5.7.1, and 550 5.1.1.
Script Name: separate not delivered emails based on reply codes
Language: VBScript
Execute script: After sending email to every recipient
function main
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim fso, f
if Recipient.Status = 0 then
FileName = "c:\Sent Items.txt"
else
FileName = "c:\Not Delivered.txt"
end if
if InStr(Recipient.ServerResponse, "452") and
InStr(Recipient.ServerResponse,
"4.2.1") <> 0 then
FileName = "c:\452 4.2.1.txt"
end if
if InStr(Recipient.ServerResponse, "451") <> 0 then
FileName = "c:\451.txt"
end if
if InStr(Recipient.ServerResponse, "550") <> 0 and
InStr(Recipient.ServerResponse, "5.7.1") <> 0 then
FileName = "c:\550 5.7.1.txt"
end if
if InStr(Recipient.ServerResponse, "550") <>0 and
InStr(Recipient.ServerResponse, "5.1.1") <> 0 then
FileName = "c:\550 5.1.1.txt"
end if
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile(FileName, ForAppending, True)
f.WriteLine Recipient.FieldByName("Email") & ", " & Recipient.ServerResponse
f.Close
end function |