{"id":2126,"date":"2012-06-06T14:09:47","date_gmt":"2012-06-06T14:09:47","guid":{"rendered":"http:\/\/craftydba.com\/?p=2126"},"modified":"2024-02-17T14:29:07","modified_gmt":"2024-02-17T14:29:07","slug":"running-the-smtp-relay-2","status":"publish","type":"post","link":"https:\/\/craftydba.com\/?p=2126","title":{"rendered":"Running the SMTP Relay"},"content":{"rendered":"<p>Today, I want to talk about sending email using <a href=\"http:\/\/en.wikipedia.org\/wiki\/SMTP_relay\">SMTP relay<\/a> 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.<\/p>\n<p>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.<\/p>\n<ul>\n<li>Alerting when system thresholds or conditions are met.<\/li>\n<li>Notification when automated tasks complete or fail.<\/li>\n<li>Delivery of custom reports and messages to users.<\/li>\n<\/ul>\n<p>I down loaded and installed the email package (<a href=\"http:\/\/search.cpan.org\/~jenda\/Mail-Sender-0.8.21\/Sender.pm\">Mail::Sender<\/a>) 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.<\/p>\n<p>The complete test program bellow will show you how to do the following:<\/p>\n<ol>\n<li>Send plain text email message.<\/li>\n<li>Send email message with attachment.<\/li>\n<li>Send email message with different priorities.<\/li>\n<li>Send html encoded email message.<\/li>\n<\/ol>\n<p>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 <span style=\"color: #008000; font-size: small;\">MailMsg()<\/span> method sends the plain text email message.<\/p>\n<pre class=\"lang:PERL theme:familiar mark:1,2-3\" title=\"perl code - send email\">\r\n# Declare all variables\r\nuse strict;\r\n\r\n# Include defined module (CPAN)\r\nuse Mail::Sender;\r\n\r\n# Adjust sender, recipient and your SMTP mailhost\r\nmy $from_address = 'donotreply@craftydba.com';\r\nmy $to_address = 'jminer@craftydba.com';\r\nmy $mail_host = 'mail.corp.craftydba.com';\r\n\r\n# Adjust subject and body message\r\nmy $subject = \"Send Email Program - Test 1\";\r\nmy $message_body = \"This is simple text message.\";\r\n\r\n# Create object to send mail\r\nmy $sender = new Mail::Sender {smtp => $mail_host, from => $from_address};        \r\n\r\n# Send message\r\n$sender->MailMsg({to => $to_address, subject => $subject, msg => $message_body});\r\n<\/pre>\n<\/p>\n<p>The table below has starter code that you can use in your next PERL Script.<\/p>\n<table border=\"1\" cellspacing=\"1\" cellpadding=\"1\" width=\"600\" align=\"left\">\n<tbody>\n<tr>\n<td style=\"border: thin solid gray;\"><a href='https:\/\/craftydba.com\/wp-content\/uploads\/2012\/06\/mail.cmd_.txt'>mail.cmd<\/a>\n<\/td>\n<td style=\"border: thin solid gray;\">Mail Batch File<\/td>\n<\/tr>\n<tr>\n<td style=\"border: thin solid gray;\"><a href='https:\/\/craftydba.com\/wp-content\/uploads\/2012\/06\/tst-send-mail.pl_.txt'>tst-send-mail.pl<\/a>\n<\/td>\n<td style=\"border: thin solid gray;\">Sample Mail Program<\/td>\n<\/tr>\n<tr>\n<td style=\"border: thin solid gray;\"><a href='https:\/\/craftydba.com\/wp-content\/uploads\/2012\/06\/tst-send-mail.html'>tst-send-mail.html<\/a>\n<\/td>\n<td style=\"border: thin solid gray;\">Sample HTML Message<\/td>\n<\/tr>\n<tr>\n<td style=\"border: thin solid gray;\"><a href=\"http:\/\/en.wikipedia.org\/wiki\/Abraham_Lincoln\">Wikipedia Image<\/a><\/td>\n<td style=\"border: thin solid gray;\">Sample Mail Attachment<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>The screen shot below shows the resulting emails stored in a PERL folder in MS Outlook.<\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/craftydba.com\/wp-content\/uploads\/2012\/06\/perl-outlook-folder.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/craftydba.com\/wp-content\/uploads\/2012\/06\/perl-outlook-folder.jpg\" alt=\"\" title=\"perl-outlook-folder\" width=\"1022\" height=\"725\" class=\"alignleft size-full wp-image-2147\" srcset=\"https:\/\/craftydba.com\/wp-content\/uploads\/2012\/06\/perl-outlook-folder.jpg 1022w, https:\/\/craftydba.com\/wp-content\/uploads\/2012\/06\/perl-outlook-folder-300x212.jpg 300w\" sizes=\"auto, (max-width: 1022px) 100vw, 1022px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>In summary, sending simple or very complex emails is very easy with the CPAN perl module.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[441,15,444,443,23],"class_list":["post-2126","post","type-post","status-publish","format-standard","hentry","category-other","tag-cpan-perl-modules","tag-john-f-miner-iii","tag-mailsender","tag-perl-script-2","tag-smtp-relay"],"_links":{"self":[{"href":"https:\/\/craftydba.com\/index.php?rest_route=\/wp\/v2\/posts\/2126","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/craftydba.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/craftydba.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/craftydba.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/craftydba.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2126"}],"version-history":[{"count":0,"href":"https:\/\/craftydba.com\/index.php?rest_route=\/wp\/v2\/posts\/2126\/revisions"}],"wp:attachment":[{"href":"https:\/\/craftydba.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2126"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/craftydba.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2126"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/craftydba.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2126"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}