# ****************************************************** # * # * Name: tst-send-mail.pl # * # * Design Phase: # * Author: John Miner # * Date: 06/05/2012 # * Purpose: A test program to send email messages. # * # ****************************************************** # Declare all variables use strict; # Include defined module (CPAN) use Mail::Sender; # # Just text email # sub mail_simple_text { # Adjust sender, recipient and your SMTP mailhost my $from_address = 'donotreply@craftydba.com'; my $to_address = 'jminer@craftydba.com'; my $mail_host = 'mail.corp.craftydba.com'; # Adjust subject and body message my $subject = "Send Email Program - Test 1"; my $message_body = "This is simple text message."; # Create object to send mail my $sender = new Mail::Sender {smtp => $mail_host, from => $from_address}; # Send message $sender->MailMsg({to => $to_address, subject => $subject, msg => $message_body}); }; # # Play with priority settings # sub mail_important_text { # Adjust sender, recipient and your SMTP mailhost my $from_address = 'donotreply@craftydba.com'; my $to_address = 'jminer@craftydba.com'; my $mail_host = 'mail.corp.craftydba.com'; # Adjust subject and body message my $subject = "Send Email Program - Test 2"; my $message_body = "This is important text message."; # Create object to send mail my $sender = new Mail::Sender {smtp => $mail_host, from => $from_address}; # Priority (1 = highest, 2 = high, 3 = normal, 4 = low, 5 = lowest) # Send message $sender->MailMsg({to => $to_address, subject => $subject, msg => $message_body, priority =>2}); }; # # Add a file to the mix # sub mail_with_attachment { # Adjust sender, recipient and your SMTP mailhost my $from_address = 'donotreply@craftydba.com'; my $to_address = 'jminer@craftydba.com'; my $mail_host = 'mail.corp.craftydba.com'; # Adjust subject and body message my $subject = 'Send Email Program - Test 3'; my $message_body = 'This is not an important message with attachment.'; # Create object to send mail my $sender = new Mail::Sender {smtp => $mail_host, from => $from_address}; # Send message $sender->MailFile({to => $to_address, subject => $subject, msg => $message_body, priority =>4, file => 'C:\\perl-depot\\mail\\Abraham-Lincoln.jpg'}); }; # # Create html body with image # sub mail_complex_html { eval { (new Mail::Sender) ->OpenMultipart({ to => 'jminer@craftydba.com', smtp => 'mail.corp.craftydba.com', from => 'donotreply@craftydba.com', subject => 'Send Email Program - Test 4', boundary => 'boundary-test-1', type => 'multipart/related' }) ->Attach({ description => 'html body', ctype => 'text/html; charset=us-ascii', encoding => '7bit', disposition => 'NONE', file => 'C:\perl-depot\mail\tst-send-mail.html' }) ->Attach({ description => 'Test gif', ctype => 'image/gif', encoding => 'base64', disposition => "inline; filename=\"Abraham-Lincoln.jpg\";\r\nContent-ID: ", file => 'C:\\perl-depot\\mail\\Abraham-Lincoln.jpg' }) ->Close() } or die "Cannot send mail: $Mail::Sender::Error\n"; }; # # Four ways to send email # # Run test 1 &mail_simple_text; # Run test 2 &mail_important_text; # Run test 3 &mail_with_attachment; # Run test 4 &mail_complex_html;