How to send dynamic EMail AutoReply with Perl Rule

How to send dynamic EMail AutoReply

 

Goal :

Send an dynamic AutoReply for ERMS Service based on From Address with custom Data from an ODBC Database.

 

Prerequisites:

Voxtron Communication Center 2016 installed with Perl runtime as known in VCC2016 System Reference Guide.

 

 

Solution:

  • Goto VCCWebCenter.
  • Select ERMS Instance
  • Select your Mailbox and navigate to Routing Rules.

 Screenshot

  • Add new Routing Rule and select “Type in a free expression email rule”

Screenshot

Copy the example to the wizard and save.

Screenshot

 

Example Perl Rule:

 

###################################################

use DBI;

use utf8;

use Encode;

use MIME::Base64;

use Net::SMTP;

 

#Declare Database Connection Settings

my $host     = SQLServer\Instance’;

my $database = ‘Voxtron10’;

my $user     = ‘SQLUser’;

my $auth     = ‘SQLPassword’;

 

# set SMTP credentials

my $smtpserver = ‘127.0.0.1’;

my $smtpport = 25;

my $smtpuser   = ”;

my $smtppassword = ”;

 

#Connect to Database

my $dsn = “dbi:ODBC:Driver={SQL Server};Server=$host;Database=$database”;

my $dbh = DBI->connect($dsn, $user, $auth)

or die(“\n\nCONNECT ERROR:\n\n$DBI::errstr”);

 

#Prepare SQL Statement

my $sth = $dbh->prepare(”

SELECT

title

                                         ,LastName

,TicketNumber

FROM CustomerDatabase

WHERE Email = ?

“)

or die(“\n\nPREPARE ERROR:\n\n$DBI::errstr”);

 

#Execute the query

$sth->execute($From)

or die(“\n\nQUERY ERROR:\n\n$DBI::errstr”);;

 

# Read the matching records and print them out     

while (@data = $sth->fetchrow_array()) {

$title = $data[0];

$LastName = $data[1];

$TicketNumber = $data[2];

$Matched = “1”;

}

 

#Close sth Command

$sth->finish();

 

#Disconnect from Database

$dbh->disconnect;

 

#create Mail title

if ($title eq “Mr”) {

$Header = “Dear Mr. $LastName”;

} elsif ($title eq “Mrs”) {

$Header = “Dear Mrs. $LastName”;

} else {

$Header = “Dear Sender”;

$Matched = “1”;

}

 

# set mail properties

my $mail_subject = “Auto Reply – $Subject”;

my $mail_headers = “From: $From\n”.

“To: @To\n”.

“Subject: “.encode(‘MIME-Header’,$mail_subject).”\n”.

“MIME-Version: 1.0\n”.

“Content-type: text/plain; charset=UTF-8\n”.

“Content-Transfer-Encoding: base64\n\n”;

 

my $mail_body = “$Header\n”.

“\n”.

“Thank you for submitting your request.\n”.

“We have queued your request with Ticketnumber $TicketNumber and one of our helpdesk engineers will handle it as soon as possible.\n”.

“\n”.

“Best Regards,\n”.

“The Helpdesk”;

 

 

# send the email

my $smtp = Net::SMTP->new($smtpserver, Port=>$smtpport, Timeout => 10, Debug => 1);

die “Could not connect to server!\n” unless $smtp;

$smtp->auth($smtpuser, $smtppassword);

$smtp->mail(@To);

$smtp->to($From);

$smtp->data();

$smtp->datasend(“From: @To\n”);

$smtp->datasend(“To: $From\n”);

$smtp->datasend($mail_headers);

$smtp->datasend(encode_base64(encode(‘utf8’,$mail_body)));

$smtp->dataend();

$smtp->quit;

 

 

###################################################

Leave a Reply