Saturday 22 July 2023

Perl script to send html file as an attachment in email | How to send cucumber report or newman html extra report as a notification after automation run with dummy email

Below Perl script  with MIME::Lite utility in Cents OS is does the job of sending an email with html attachment. This is one of the basic techniques used to send an automation report after execution with out providing actual user email or password. 

1) Should have Cent OS 
2) Should be installed MIME:Lite utility 

References: 

Perl file name: cucumber-report-email-notification.pl

Perl file execution : 
perl cucumber-report-email-notification.pl

#Author: Sadakar Pochampalli

#use strict;
use warnings;
use MIME::Lite;

my $to = 'ABCProjectTeam@email.com';
my $cc = 'test@email.com';
my $bcc ='test2@email.com';
my $from = 'AutomationTeam@email.com';
my $subject = "Regression Testing Results";
my $message = "<p>Hi, <br>Test Project Automation Report</p> <br>Thank you <br> Testing Team";

my $msg = MIME::Lite->new(
		 From	=> $from,
                 	 To     => $to,
 		 Cc   => $cc,
		 Subject => $subject,
                 Type    => 'multipart/related'
                 );
$msg->attach(
		Type => 'TEXT/html',
		Data =>  $message
             );
$msg->attach(
		Type => 'image/text',
   		Path => '/home/sadakar/AutomationProject/sadakar-logo.jpg',
                Filename => 'sadakar.jpg',
                Disposition => 'attachment'
             );
$msg->attach(
		Type => 'file',
   		Path => '/home/sadakar/AutomationProject/RegressionTests.html',
                Filename => 'RegressionTests.html',
                Disposition => 'attachment'
             );
$msg->send;
print "Email Sent\n";


No comments:

Post a Comment