How to Send and Receive Email with Perl

Perl is a versatile and powerful programming language that can be used for various tasks, including sending and receiving email. In this article, we will explore some of the modules and methods that can help you accomplish this goal.

There are different ways to send email with Perl. One way is to use the Email::MIME module to create and parse email messages, and the Email::Sender module to send them using various transports, such as SMTP or Sendmail. Another way is to use the Mail::Send module to create…

Sending a simple email

To have a secure SMTP delivery, use Email::Sender. Mail::Sendmail uses SMTP for transport and there's no other type of transport. It does not support SMTP authentication, which my SMTP server now requires even for access from localhost. From what I read and tried once or twice in the past, the current "best practice" or recommended way is to use Email::Sender. Here's an incantation to send mail using sendmail:

Saving Perl packages through local

In Perl there is an expression local. It substitutes the specified value with undef until the end of the block. The values can be global hashes, arrays and scalars, as well as elements or slices of hashes and scalars. The problem is that package hashes are not saved by local. By package hashes I mean a hash with a colon at the end (%Package::) which stores the package symbols (GLOB).

package A {
  sub fn {}
  $x = 10;
  @x = qw(1 2);

use DDP;
p %A::  # -> {
        #    fn   *A::fn  (layers: ),
        #    x    *A::x  (layers: )
        # }…