Skip to content

Instantly share code, notes, and snippets.

@jettero
Forked from anonymous/mailx-thingy.pl
Created January 21, 2010 20:18
Show Gist options
  • Save jettero/283156 to your computer and use it in GitHub Desktop.
Save jettero/283156 to your computer and use it in GitHub Desktop.
Net::SMTP demo for some solaris people... yonder ...
my $smtp = Net::SMTP->new("mail.gateway.company.com",
Hello=>"sending-hostname.company.com", Debug=>1)
or croak $!;
# This is the SMTP Return path. It's the actual return path of the
# mail and should be real. It's used in the accept/deny decision
# (sometimes) and populates the return-path: header in the email. It's
# the MAIL FROM SMTP command.
$smtp->mail('real-sender@company.com');
# This is is the RCPT part of the SMTP session. The recipients of the
# mail are decided from this command. The body of the message (e.g.,
# the To: header below) is not used to decide recipients. That's part
# of the story you tell the recipient. All TO:, BCC: and CC:
# recipients must be listed here. the only difference between a BCC
# and a CC is that the BCC won't appear in the body of the message
# below.
$smtp->to("recipient1@company.com", "recp2@company.com", "r3@company.com");
# send SMTP command to start start the body of the message
$smtp->data;
# The rest of this can be as fictional as you like. The from: and to:
# headers are used by mail clients to show the sender, but the mail
# servers don't normally care about them at all.
$smtp->datasend("From: \"My Real Name\" <realname@company.com>\n");
$smtp->datasend("To: \"someone cool\" <cool@company.com>\n");
$smtp->datasend("Subject: whatever...\n");
$smtp->datasend("Reply-To: whatever\n");
# skip one line before the message contents. This tells mail clients
# the headers are done and the message is beginning.
$smtp->datasend("\n");
# The format of the message headers and the blank line is in RFC2822
# aka Internet Message Format.
$smtp->datasend($msg);
# end the body of the message and start sending SMTP commands again
$smtp->dataend;
# SMTP QUIT
$smtp->quit;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment