SMTP_auth(3pm)

πŸ“¦
version 0.08 Β· 2 versions
  • 0.08 Β· debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking (latest)
  • 0.08 Β· ubuntu jammy
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’Œ SMTP_auth β€” the manual, but make it cute

okay so bestie, welcome to SMTP_auth(3pm), aka the Perl module that lets you slide into an SMTP server's DMs, prove who you are, and send mail like a certified main character. Let's get into it πŸ’–


✨ NAME ✨

Net::SMTP_auth β€” Simple Mail Transfer Protocol Client with AUTHentication. It's giving "I send mail AND I authenticate", and honestly? Iconic. πŸ’…


πŸŽ€ SYNOPSIS πŸŽ€

use Net::SMTP_auth;

# Constructors
$smtp = Net::SMTP_auth->new('mailhost');
$smtp = Net::SMTP_auth->new('mailhost', Timeout => 60);

Look at her. Two whole constructors. Lowkey the easiest part of your whole day. πŸ¦‹


🌸 DESCRIPTION 🌸

So this module implements a client interface to the SMTP and ESMTP protocol AUTH service extension, which means it lets a perl5 application talk to SMTP servers and authenticate against them. No cap. 🫢

Heads up though: this doc assumes you already know the SMTP protocol concepts described in RFC821 and the AUTH service extension described in RFC2554. iykyk β€” if you don't, maybe go read those first, bestie, because this page is not gonna hold your hand through the whole protocol.

A new Net::SMTP_auth object must be created with the new method. Once you've done that, all SMTP commands are accessed through this object. She's the main character and everything routes through her. ✨

And the family tree?? Genealogy is immaculate: the Net::SMTP_auth class is a subclass of Net::SMTP, which itself is a subclass of Net::Cmd and IO::Socket::INET. Four generations of networking royalty πŸ‘‘.


πŸ”₯ EXAMPLES πŸ”₯

This example authenticates via CRAM-MD5 and sends a small message to the postmaster at the SMTP server known as mailhost:

#!/usr/bin/perl -w

use Net::SMTP_auth;

$smtp = Net::SMTP_auth->new('mailhost');
$smtp->auth('CRAM-MD5', 'user', 'password');

$smtp->mail($ENV{USER});
$smtp->to('postmaster');

$smtp->data();
$smtp->datasend("To: postmaster\n");
$smtp->datasend("\n");
$smtp->datasend("A simple test message\n");
$smtp->dataend();

$smtp->quit;

Not her running the whole mail pipeline in like twelve lines. Ate. No crumbs. πŸ’€βœ¨


🧚 CONSTRUCTOR 🧚

  • new Net::SMTP_auth [ HOST, ] [ OPTIONS ] β€” this is the constructor for a brand new Net::SMTP_auth object. It's taken from Net::SMTP, same as all the other methods (except auth and auth_types) are, too. So yeah β€” she inherited the whole wardrobe. πŸ‘‘

πŸ’… METHODS πŸ’…

Ground rules first, bestie: unless otherwise stated, all methods return either a true or false value, where true means the operation was a success. And when a method says it returns a value, failure comes back as undef or an empty list. So always check your returns, okay?? πŸ™ˆ

  • auth_types () β€” returns the AUTH methods supported by the server, either as an array or as a space separated string. That string is exacly the line given by the SMTP server after the "EHLO" command containing the keyword "AUTH". (Yes, the original says "exacly" and we're keeping that typo because it's part of her lore now. 🫢)
  • auth ( AUTH, USER, PASSWORD ) β€” authenticates the user "USER" via the authentication method "AUTH" and the password "PASSWORD". Returns true if successful and false if the authentication failed. Important: remember that the connection is not closed if the authentication fails β€” so you may issue a different authentication attempt. But here's the catch: if you once are successfully authenticated, you cannot send the "AUTH" command again. One shot at the crown, bestie. πŸ‘‘

Also: the "AUTH" method "NTLM" is supported via Authen::NTLM (thanks to James Fryman). πŸ’œ


🌈 SEE ALSO 🌈

Net::SMTP and Net::Cmd β€” go read those too, they're the ancestors and they're both serving. ✨


πŸ’– AUTHOR πŸ’–

Alex Pleiner <alex@zeitform.de>, zeitform Internet Dienste. Thanks to Graham Barr <gbarr@pobox.com> for Net::SMTP. NTLM authentication code provided by James Fryman <jfryman@gmail.com>. Shoutout to the whole squad for making this happen. 🫢


Copyright (c) 2001, 2003, 2006 zeitform Internet Dienste. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Free software, free vibes, legally binding cuteness. πŸ’…


One last thing, bestie: this whole page is from perl v5.36.0, dated 2022-11-19, and it's the SMTP_auth(3pm) manual page. Now go authenticate something and slay. πŸ’–βœ¨πŸ¦‹
πŸ“¦ where this page comes from