Mail::Send(3)

πŸ’Œ Mail::Send(3) β€” like, the whole manual page, bestie

Okay so this is Mail::Send(3), from the User Contributed Perl Documentation crew β€” yes, a real Perl manpage, and yes, we're gonna get through it together. Grab a strawberry drink πŸ“, we're going in.


✨ NAME ✨

Mail::Send β€” a simple electronic mail interface. That's it, that's the whole vibe. πŸ’…


πŸŽ€ SYNOPSIS πŸŽ€

Like, here's the whole thing in code, no cap, character for character:

  require Mail::Send;

  $msg = Mail::Send->new;
  $msg = Mail::Send->new(Subject => 'example', To => 'timbo');

  $msg->to('user@host');
  $msg->to('user@host', 'user2@example.com');
  $msg->subject('example subject');
  $msg->cc('user@host');
  $msg->bcc('someone@else');

  $msg->set($header, @values);
  $msg->add($header, @values);
  $msg->delete($header);

  # Launch mailer and set headers. The filehandle returned
  # by open() is an instance of the Mail::Mailer class.
  # Arguments to the open() method are passed to the Mail::Mailer
  # constructor.

  $fh = $msg->open;   # some default mailer
  $fh = $msg->open('sendmail'); # explicit
  print $fh "Body of message";
  $fh->close          # complete the message and send it
      or die "couldn't send whole message: $!\n";

I know, I know β€” that or die "couldn't send whole message: $!\n" is giving main character energy. Obsessed. πŸ”₯


🌸 DESCRIPTION 🌸

So Mail::Send builds e-mail messages without using any of the Mail::Header knowledge. Which means… yeah. All the escaping and folding? That's on you, bestie. 😭

Also: do not forget to escape leading dots. Simplicity has its price, and the price is your own sanity. πŸ’€

When you have time (and honestly, make time), take a look at Mail::Transport, which is part of the MailBox suite. It's giving ✨upgrade✨, iykyk.


πŸ¦‹ METHODS πŸ¦‹

🌈 Constructors 🌈

  • Mail::Send->new(PAIRS) β€” You can pass a list of header fields (as key-value PAIRS) to initialize the object, but it's lowkey limited to just the few that exist as methods: "to", "subject", "cc", and "bcc". For any other header fields? Use add(). That's the whole rule. 🫢

πŸ’œ Header fields πŸ’œ

  • $obj->add($fieldname, @values) β€” Adds values onto the list of already-defined values for the $fieldname. It stacks, it doesn't replace. πŸ’…

Then the little squad that hangs out together:

  • $obj->bcc(@values)
  • $obj->cc(@values)
  • $obj->delete($fieldname)
  • $obj->set($fieldname, @values) β€” the @values here will replace the old values for the $fieldname. And what comes back to you? The LIST of values after the modification. Cute, right? 🎁
  • $obj->subject(@values)
  • $obj->to(@values)

πŸ‘‘ Sending πŸ‘‘

  • $obj->open(%options) β€” The %options get used to initiate a mailer object via Mail::Mailer::new(). Then Mail::Mailer::open() is called with all the knowledge collected in this Mail::Send object. Teamwork, honestly. 🫢
⚠️ Be warned, bestie: this module implements raw smtp, which means you have to escape any lines that start with a dot β€” by adding one in front. Not me forgetting that and then crying about it. πŸ™ˆ

⭐ SEE ALSO ⭐

This module is part of the MailTools distribution: http://perl.overmeer.net/mailtools/ β€” bookmark it, it's iconic.


🧚 AUTHORS 🧚

The MailTools bundle was developed by Graham Barr. Later, Mark Overmeer took over maintenance β€” without commitment to further development, so, like, no promises. 😌

  • Mail::Cap by Gisle Aas <aas@oslonett.no>
  • Mail::Field::AddrList by Peter Orbaek <poe@cit.dk>
  • Mail::Mailer and Mail::Send by Tim Bunce <Tim.Bunce@ig.co.uk>
  • For other contributors, see ChangeLog. πŸ‘€

πŸ’– LICENSE πŸ’–

Copyrights 1995-2000 Graham Barr <gbarr@pobox.com> and 2001-2024 Mark Overmeer <perl@overmeer.net>.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See http://www.perl.com/perl/misc/Artistic.html for the details, bestie. πŸŽ€


Okay that's the whole page! Slay. πŸ’…βœ¨

Signing off with love: this is from perl v5.42.0, dated 2024-12-12 β€” and it's literally Mail::Send(3), periodt. πŸ¦‹πŸ‘‘

πŸ“¦ where this page comes from