Running the SMTP Relay

Today, I want to talk about sending email using SMTP relay host. The topic of a SMTP relay is an mportant one that you will come across in your career. A open mail relay allows a PERL script to send mail messages from a mail box that you can name and does not have to exist on the mail server.

In todays information world, it is very important to stay connected via emails. Emails can be used for many different purposes in your PERL scripts.

  • Alerting when system thresholds or conditions are met.
  • Notification when automated tasks complete or fail.
  • Delivery of custom reports and messages to users.

I down loaded and installed the email package (Mail::Sender) from CPAN to create and send emails. This package does a awesome job in encapsulating all the methods you will ever need. I will touch upon a few important methods that you will use in PERL scripts.

The complete test program bellow will show you how to do the following:

  1. Send plain text email message.
  2. Send email message with attachment.
  3. Send email message with different priorities.
  4. Send html encoded email message.

The code snipet below solves the first problem. Standard information like from address, to address, mail host, subject and message body are given to an instance of the object. The MailMsg() method sends the plain text email message.

The table below has starter code that you can use in your next PERL Script.

mail.cmd Mail Batch File Sample Mail Program
tst-send-mail.html Sample HTML Message
Wikipedia Image Sample Mail Attachment





The screen shot below shows the resulting emails stored in a PERL folder in MS Outlook.



In summary, sending simple or very complex emails is very easy with the CPAN perl module.

Related posts

Leave a Comment