Net::SMTP::TLS(3pm)

πŸ“¦
version 0.12 Β· 3 versions
, in debian trixie, ubuntu resolute, ubuntu stonking

πŸ’Œ Net::SMTP::TLS β€” the manual page, bestie edition ✨

okay so you're reading the Net::SMTP::TLS(3pm) page from the User Contributed Perl Documentation? good. sit down. get a snack. πŸ“


🌸 NAME 🌸

Net::SMTP::TLS β€” an SMTP client that supports TLS and AUTH. yes, both. she's versatile like that. πŸ’…


✨ VERSION ✨

Version 0.12 πŸŽ€


πŸ“œ SYNOPSIS πŸ“œ

here's the whole vibe in one code block, no edits, exactly as it lives:

use Net::SMTP::TLS;
my $mailer = new Net::SMTP::TLS(
       'your.mail.host',
       Hello   =>      'some.host.name',
       Port    =>      25, #redundant
       User    =>      'emailguy',
       Password=>      's3cr3t');
$mailer->mail('emailguy@your.mail.host');
$mailer->to('someonecool@somewhere.else');
$mailer->data;
$mailer->datasend("Sent thru TLS!");
$mailer->dataend;
$mailer->quit;

that's literally it. that's the whole send-an-email arc. main character energy from start to finish. πŸ‘‘


πŸ’– DESCRIPTION πŸ’–

Net::SMTP::TLS is a TLS-capable and AUTH-capable SMTP client, and she serves an interface that you'll already recognize if you've ever hung out with Net::SMTP. it implements a subset of the methods that module gives you β€” so like, not (yet) a full mirror image of that API, bestie. it's giving "little sister who's still growing into her powers." πŸ¦‹

the methods Net::SMTP::TLS supports are the ones used in the example up above ☝️. mostly self-explanatory honestly, but if you're sitting there like "...what", go read the perldoc for Net::SMTP. it's all there.

and here's where the methods differ, so listen up:

  • the mail method does not take the options list that Net::SMTP takes.
  • the to method also does not take options, and it is the only method available for setting the recipient β€” unlike the many synonyms Net::SMTP provides. one method. one job. she's focused. ✨
  • the constructor takes a limited number of Net::SMTP's parameters. and for Net::SMTP::TLS, the constructor takes the following β€” plus the hostname of the mail server, which must be the first parameter and is not explicitly named:
    • NoTLS β€” in the unlikely event that you need to use this class to do non-TLS SMTP (and honestly? you ought to be using Net::SMTP itself for that...), this turns TLS off when you supply it a true value. ⚠️ warning tho: this will most often cause an error related to authentication when you use it on a server that requires TLS. so. iykyk.
    • Hello β€” the hostname used in the EHLO command.
    • Port β€” the port to connect to the SMTP service (defaults to 25).
    • Timeout β€” timeout for the initial socket connection (defaults to 5, passed directly to IO::Socket::INET).
    • User β€” username for SMTP AUTH.
    • Password β€” password for SMTP AUTH.

πŸ” TLS and AUTHentication πŸ”

when you construct a Net::SMTP::TLS instance, the whole login process happens right then and there. not later. immediately. no waiting around. 😭

the full sequence goes like this:

  1. send EHLO to the server first.
  2. initiate a TLS session through STARTTLS.
  3. once that's done, the module attempts to log in using the credentials you gave the constructor β€” if you gave them.

the AUTH method it picks depends on the features the server returns after the EHLO command. based on that, the order of preference is:

  1. CRAM-MD5 β€” used if available.
  2. LOGIN β€” next in line.
  3. PLAIN β€” the fallback.
important tea β˜•: LOGIN is the only authentication method that has been tested. the CRAM-MD5 and PLAIN login functionality was taken directly from the script mentioned down in the acknowledgements, but it has not been tested personally. so like, if those don't work, that's... a known thing. πŸ™ˆ

🚨 ERROR HANDLING 🚨

this module will croak whenever an SMTP error happens. that's it, that's the whole thing, it does not sugarcoat. πŸ’€

if you want to handle it gracefully in your app, wrap your mail transmission in an eval {} block and check $@ afterward. that's the move. that's the escape hatch. 🫢


πŸ™ ACKNOWLEDGEMENTS πŸ™

real talk: this code was blatantly plagiarized from Michal Ludvig's smtp-client.pl script. see http://www.logix.cz/michal/devel/smtp for his excellent work. credit where credit is due, always. πŸ’œ


πŸ‘‘ AUTHOR πŸ‘‘

Alexander Christian Westholm, awestholm at verizon dawt net

Improvements courtesy of Tomek Zielinski 🌟


and that's the page, bestie!! perl v5.40.1, dated 2025-05-07 β€” now go send that email the secure way πŸ’–βœ¨πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from