# phpman > perldoc > mail

## Found in /usr/share/perl/5.34/pod/perlfaq2.pod
  What mailing lists are there for Perl?
    A comprehensive list of Perl-related mailing lists can be found at
    <<http://lists.perl.org/>>

## Found in /usr/share/perl/5.34/pod/perlfaq9.pod
  How do I parse a mail header?
    Use the [Email::MIME](https://www.chedong.com/phpMan.php/perldoc/Email%3A%3AMIME/markdown) module. It's well-tested and supports all the
    craziness that you'll see in the real world (comment-folding whitespace,
    encodings, comments, etc.).

      use [Email::MIME](https://www.chedong.com/phpMan.php/perldoc/Email%3A%3AMIME/markdown);

      my $message = [Email::MIME](https://www.chedong.com/phpMan.php/perldoc/Email%3A%3AMIME/markdown)->new($rfc2822);
      my $subject = $message->header('Subject');
      my $from    = $message->header('From');

    If you've already got some other kind of email object, consider passing
    it to [Email::Abstract](https://www.chedong.com/phpMan.php/perldoc/Email%3A%3AAbstract/markdown) and then using its cast method to get an
    [Email::MIME](https://www.chedong.com/phpMan.php/perldoc/Email%3A%3AMIME/markdown) object:

      my $abstract = [Email::Abstract](https://www.chedong.com/phpMan.php/perldoc/Email%3A%3AAbstract/markdown)->new($mail_message_object);
      my $email_mime_object = $abstract->cast('[Email::MIME](https://www.chedong.com/phpMan.php/perldoc/Email%3A%3AMIME/markdown)');

  How do I check a valid mail address?
    (partly contributed by Aaron Sherman)

    This isn't as simple a question as it sounds. There are two parts:

    a) How do I verify that an email address is correctly formatted?

    b) How do I verify that an email address targets a valid recipient?

    Without sending mail to the address and seeing whether there's a human
    on the other end to answer you, you cannot fully answer part *b*, but
    the [Email::Valid](https://www.chedong.com/phpMan.php/perldoc/Email%3A%3AValid/markdown) module will do both part *a* and part *b* as far as you
    can in real-time.

    Our best advice for verifying a person's mail address is to have them
    enter their address twice, just as you normally do to change a password.
    This usually weeds out typos. If both versions match, send mail to that
    address with a personal message. If you get the message back and they've
    followed your directions, you can be reasonably assured that it's real.

    A related strategy that's less open to forgery is to give them a PIN
    (personal ID number). Record the address and PIN (best that it be a
    random one) for later processing. In the mail you send, include a link
    to your site with the PIN included. If the mail bounces, you know it's
    not valid. If they don't click on the link, either they forged the
    address or (assuming they got the message) following through wasn't
    important so you don't need to worry about it.

  How do I find the user's mail address?
    Ask them for it. There are so many email providers available that it's
    unlikely the local system has any idea how to determine a user's email
    address.

    The exception is for organization-specific email (e.g.
    <foo@yourcompany.com>) where policy can be codified in your program. In
    that case, you could look at $ENV{USER}, $ENV{LOGNAME}, and getpwuid($<)
    in scalar context, like so:

      my $user_name = getpwuid($<)

    But you still cannot make assumptions about whether this is correct,
    unless your policy says it is. You really are best off asking the user.

  How do I send email?
    Use the [Email::Stuffer](https://www.chedong.com/phpMan.php/perldoc/Email%3A%3AStuffer/markdown) module, like so:

      # first, create your message
      my $message = [Email::Stuffer](https://www.chedong.com/phpMan.php/perldoc/Email%3A%3AStuffer/markdown)->from('<you@example.com>')
                                  ->to('<friend@example.com>')
                                  ->subject('Happy birthday!')
                                  ->text_body("Happy birthday to you!\n");

      $message->send_or_die;

    By default, [Email::Sender::Simple](https://www.chedong.com/phpMan.php/perldoc/Email%3A%3ASender%3A%3ASimple/markdown) (the "send" and "send_or_die" methods
    use this under the hood) will try "sendmail" first, if it exists in your
    $PATH. This generally isn't the case. If there's a remote mail server
    you use to send mail, consider investigating one of the Transport
    classes. At time of writing, the available transports include:

    [Email::Sender::Transport::Sendmail](https://www.chedong.com/phpMan.php/perldoc/Email%3A%3ASender%3A%3ATransport%3A%3ASendmail/markdown)
        This is the default. If you can use the [mail(1)](https://www.chedong.com/phpMan.php/man/mail/1/markdown) or [mailx(1)](https://www.chedong.com/phpMan.php/man/mailx/1/markdown) program
        to send mail from the machine where your code runs, you should be
        able to use this.

    [Email::Sender::Transport::SMTP](https://www.chedong.com/phpMan.php/perldoc/Email%3A%3ASender%3A%3ATransport%3A%3ASMTP/markdown)
        This transport contacts a remote SMTP server over TCP. It optionally
        uses TLS or SSL and can authenticate to the server via SASL.

    Telling [Email::Stuffer](https://www.chedong.com/phpMan.php/perldoc/Email%3A%3AStuffer/markdown) to use your transport is straightforward.

      $message->transport($email_sender_transport_object)->send_or_die;

  How do I use MIME to make an attachment to a mail message?
    [Email::MIME](https://www.chedong.com/phpMan.php/perldoc/Email%3A%3AMIME/markdown) directly supports multipart messages. [Email::MIME](https://www.chedong.com/phpMan.php/perldoc/Email%3A%3AMIME/markdown) objects
    themselves are parts and can be attached to other [Email::MIME](https://www.chedong.com/phpMan.php/perldoc/Email%3A%3AMIME/markdown) objects.
    Consult the [Email::MIME](https://www.chedong.com/phpMan.php/perldoc/Email%3A%3AMIME/markdown) documentation for more information, including
    all of the supported methods and examples of their use.

    [Email::Stuffer](https://www.chedong.com/phpMan.php/perldoc/Email%3A%3AStuffer/markdown) uses [Email::MIME](https://www.chedong.com/phpMan.php/perldoc/Email%3A%3AMIME/markdown) under the hood to construct messages,
    and wraps the most common attachment tasks with the simple "attach" and
    "attach_file" methods.

      [Email::Stuffer](https://www.chedong.com/phpMan.php/perldoc/Email%3A%3AStuffer/markdown)->to('<friend@example.com>')
                    ->subject('The file')
                    ->attach_file('stuff.csv')
                    ->send_or_die;

  How do I read email?
    Use the [Email::Folder](https://www.chedong.com/phpMan.php/perldoc/Email%3A%3AFolder/markdown) module, like so:

      use [Email::Folder](https://www.chedong.com/phpMan.php/perldoc/Email%3A%3AFolder/markdown);

      my $folder = [Email::Folder](https://www.chedong.com/phpMan.php/perldoc/Email%3A%3AFolder/markdown)->new('/path/to/email/folder');
      while(my $message = $folder->next_message) {
        # next_message returns [Email::Simple](https://www.chedong.com/phpMan.php/perldoc/Email%3A%3ASimple/markdown) objects, but we want
        # [Email::MIME](https://www.chedong.com/phpMan.php/perldoc/Email%3A%3AMIME/markdown) objects as they're more robust
        my $mime = [Email::MIME](https://www.chedong.com/phpMan.php/perldoc/Email%3A%3AMIME/markdown)->new($message->as_string);
      }

    There are different classes in the [Email::Folder](https://www.chedong.com/phpMan.php/perldoc/Email%3A%3AFolder/markdown) namespace for
    supporting various mailbox types. Note that these modules are generally
    rather limited and only support reading rather than writing.

