Email Forwarding Service
Event Scripts
|
|
POPREP have got a built in scripting host capable
of executing VBScript or JScript. You can configure the connector to call an Event script
for each mail before it is being sent to the SMTP Server.
Event scripts are very powerful as they allow you to extend the functionality of the
POP3 Replication Service. Example usage for event scripts are; Spam filter, Virus Scanning or conditional forwarding,
etc. NOTE: Any changes to the event script will take
effect immediately, so be careful if modifying the script whilst the service is
running.
The event script can have any name, but it's file extension
(type) is used to determine what scripting language it's written in, so for VBScript
it must end with ".vbs" and for JScript ".js".
OnSend
If an event script has been configured for the
connector, the service will call the method OnSend immediately before sending
the email, and once the mail has been sent - or if the attempt to send
the mail failed, the service will call the method OnSent. The service will NOT
send the mail if the OnSend method is missing, or if the script threw an
exception when OnSend was called.
The OnSend
method can return an instruction to the service of what to do with the mail. The
2nd argument us used for this purpose.
0 |
Send Mail: (Default) The email should be forwarded on
to the SMTP server. The return status will be changed from 0 to 3 if the SendTo
property is set to no recipients. |
1 |
Bad Mail: The mail will be moved to a folder a BadMail folder and it will be flagged as delivered |
2 |
Kill Mail: The mail will be deleted and it will be flagged as Delivered. |
3 |
Skip Mail: The mail will NOT be delivered and
it will remain in the spool folder. The return status will be changed from 0 to 3 if there
is an error whilst executing the event script or the SendTo property is set
to no recipients. |
OnSend also allows you to control who to send the email to via the
Mail Object.
Two properties are used for this purpose, Mail.Sendto and Mail.CopyTo.
The Mail Object exposes a number of methods that
allows you to access properties of the email.
' Function : OnSend(ByVal Msg)
' Purpose : Called for every Mail that is to be Sent
' Argument : [in] Msg - Message Object
' Return : 0=SendMail(Default), 1=BadMail, 2=Delete, 3=Skip
Function OnSend(ByVal Msg)
Dim strFrom, strTo, strSubject
OnSend = 0' By default we want to send this mail
strFrom = Msg.GetField("From:")
strTo = Msg.GetField("To:")
strSubject =
Msg.GetField("Subject:")
'
' Check for Spam
'
If InStr(1, strSubject,"someword", vbTextCompare) <> 0 Then
OnSend = 1 ' BadMail
Exit Function
End If
'
' Conditional forwarding of email from example.com to abc@example.com
'
If InStr(1, strTo,"example.com", vbTextCompare) <> 0
Then
Msg.CopyTo = "abc@example.com"
Exit
Function
End
If
End
Sub
OnSent
OnSent is called once the mail has
been sent - or failed to be sent to the SMTP Server.
'
Sub : OnSent(ByVal Msg, ByVal SentStatus)
' Purpose : Called for every Mail after it is Sent/Failed to send
' Argument : [in] Mail Message Object
' Argument :
[in] SentStatus 0=SentMail, 1=BadMail, 2=Delete, 3=Skipped
Sub OnSent(ByVal Mail, ByVal SentStatus)
' Perform some post sent operation.
End
Sub
JScript Example
function OnSend(Msg)
{
var strFrom, strTo, strSubject, strMessageId;
strFrom = Msg.GetField("From:");
strTo = Msg.GetField("To:");
strSubject = Msg.GetField("Subject:");
strMessageId = Msg.GetField("Message-Id:");
Msg.CopyTo = "abc@example.com";
return 0x1; // Send the Mail
}
function OnSent(Msg, SentStatus)
{
}