logo_michael-thomas.jpg (3143 bytes)

Perl Script using Net::SMTP

This page has examples of using Perl Scripts module Net::SMTP.  If your web sever has this module loaded you can download the source and play with the code.

Download Perl Source - Download a zip file with this HTML file and all of the Perl source code used on this web page.  Feel free to modify the code and change the programmers name to your name!  Enjoy Success and have fun!

Examples

  • Domain Name - ex_perl_smtp_domain.pl - Part of the source download. This Perl script will show the remote SMTP server's  domain name.  
  • ex_perl_smtp_helloworld.pl - Part of the source download.  This Perl script will email "Hello World" to an email address.  This is a very simple striped down script you can use to learn from.
    Please do not click this link. It will send me a test email. In the source code you download you can modify the Perl code to send you a test email.

Email a Form
(using Net::SMTP - Unix & Win NT compatible)

For your application, you may also want to add additional validation checking in the JavaScript of the form page or in the Perl script.  The only Perl validation checking function I've written is for the email address.  Currently, the only field I validate is the TO field which is the only maditory field that must be populated.

Notes: 

  • You may have multiple email address for the: To, Cc, & Bc.  Just insert a comma (",") between the email address.
  • Also, in the TO,CC, or BC you may send emails that show a name rather than the email address.
    (ex: John Doe<jd@michael-thomas.com> ) Do not try this with the 'From' because populating the full name will automatically do the same.
  • "Your Name" will appear in the From field.  Reply to will be the "Email-From". 
  • "Thank You Message" - this can be an html message or a link to a file.
    • When making a link: (At my site, #1 will work, but  #2 & #3 will not - web host rules.).
      1)  URL must be the full link.  (ie: http://www.michael-thomas.com/cgi/perl/ex_perl_smtp_thanks.htm). 
      2) If the html file is in the perl source directory, then use './' (ex: ./ex_perl_smtp_thanks.thm)
      3) If the html file is referenced from the perl source directory then use '../' and so on.
    • When making an HTML message:
      Just enter in the HTML code you want displayed.
  • To implement this email solution  on your site:
    • Load Perl's standard modules (must include CGI.pm & Net::SMTP)
    • Download the source (link above) and place the source in you "cgi-bin" directory.  Check with your web host.  Also make sure the file is "executable" (Unix-chmod 755).
    • Next create a form.  You may use this one as an example.  The following fields must exist and can be type "text" or "hidden":  mail_fullname, mail_from, mail_to, mail_cc, mail_bc, mail_subject, mail_body, mail_thanks
    • Make sure the form's 'action' property points to the CGI Perl Script.  View this form's <form> tag for an example.

Your Name
Email - From
Email - To
Email - Cc
Email - Bc
Subject
Message
Thank You Message