Mail::Sender(3)
๐ฆ Mail::Sender(3) ๐ฆ
User Contributed Perl Documentation
๐ NAME ๐
Mail::Sender โ (DEPRECATED) module for sending mails with attachments through an SMTP server
๐ DEPRECATED ๐
okay so real talk bestie: Mail::Sender is deprecated. ๐ญ Email::Sender is the go-to choice when you need to send Email from Perl. Go there, be happy! โจ
โจ SYNOPSIS โจ
use Mail::Sender;
my $sender = Mail::Sender->new({
smtp => 'mail.yourdomain.com',
from => 'your@address.com'
});
$sender->MailFile({
to => 'some@address.com',
subject => 'Here is the file',
msg => "I'm sending you the list you wanted.",
file => 'filename.txt'
});
like... look at that. it's giving "effortless" ๐
๐ธ DESCRIPTION ๐ธ
Mail::Sender is deprecated. Email::Sender is the go-to choice when you need to send Email from Perl. Go there, be happy! ๐ (yes, they said it twice. they mean it.)
Mail::Sender provides an object-oriented interface to sending mails. It directly connects to the mail server using IO::Socket. no cap, it just talks straight to the server itself ๐ฅ
๐ ATTRIBUTES ๐
Mail::Sender implements the following attributes.
- read this one, i'm begging ๐ฅบ Please note that altering an attribute after object creation is best handled with creating a copy using
$sender = $sender->new({attribute => 'value'}). To obtain the current value of an attribute, break all the rules and reach in there!my $val = $sender->{attribute};
๐ auth
# mutating single attributes could get costly!
$sender = $sender->new({auth => 'PLAIN'});
my $auth = $sender->{auth}; # reach in to grab
The SMTP authentication protocol to use to login to the server. currently the only ones supported are LOGIN, PLAIN, CRAM-MD5 and NTLM. Some protocols have module dependencies. CRAM-MD5 depends on Digest::HMAC_MD5 and NTLM on Authen::NTLM. ๐ฆ
You may add support for other authentication protocols yourself. main character energy, honestly ๐
๐ auth_encoded
# mutating single attributes could get costly!
$sender = $sender->new({auth_encoded => 1});
my $auth_enc = $sender->{auth_encoded}; # reach in to grab
If set to a true value, Mail::Sender attempts to use TLS (encrypted connection) whenever the server supports it and you have IO::Socket::SSL and Net::SSLeay. ๐ก๏ธ
The default value of this option is true! This means that if Mail::Sender can send the data encrypted, it will. so like... it's secure by default, we love to see it ๐
๐ authdomain
# mutating single attributes could get costly!
$sender = $sender->new({authdomain => 'bar.com'});
my $domain = $sender->{authdomain}; # reach in to grab
The domain name; used optionally by the NTLM authentication. Other authentication protocols may use other options as well. They should all start with auth though. ๐
๐ชช authid
# mutating single attributes could get costly!
$sender = $sender->new({authid => 'username'});
my $username = $sender->{authid}; # reach in to grab
The username used to login to the server.
๐๏ธ authpwd
# mutating single attributes could get costly!
$sender = $sender->new({authpwd => 'password'});
my $password = $sender->{authpwd}; # reach in to grab
The password used to login to the server. keep it secret, keep it safe bestie ๐
๐ bcc
# mutating single attributes could get costly!
$sender = $sender->new({bcc => 'foo@bar.com'});
$sender = $sender->new({bcc => 'foo@bar.com, bar@baz.com'});
$sender = $sender->new({bcc => ['foo@bar.com', 'bar@baz.com']});
my $bcc = $sender->{bcc}; # reach in to grab
Send a blind carbon copy to these addresses. sneaky sneaky, love that for you ๐คซ
โ๏ธ boundary
# mutating single attributes could get costly!
$sender = $sender->new({boundary => '--'});
my $boundary = $sender->{boundary}; # reach in to grab
The message boundary. You usually do not have to change this, it might only come in handy if you need to attach a multi-part mail created by Mail::Sender to your message as a single part. Even in that case any problems are unlikely. honestly? just leave it alone, it's fine ๐ง
๐ค cc
# mutating single attributes could get costly!
$sender = $sender->new({cc => 'foo@bar.com'});
$sender = $sender->new({cc => 'foo@bar.com, bar@baz.com'});
$sender = $sender->new({cc => ['foo@bar.com', 'bar@baz.com']});
my $cc = $sender->{cc}; # reach in to grab
Send a carbon copy to these addresses. ๐
๐ค charset
# mutating single attributes could get costly!
$sender = $sender->new({charset => 'UTF-8'});
my $charset = $sender->{charset}; # reach in to grab
The charset of the single part message or the body of the multi-part one.
๐ป client
# mutating single attributes could get costly!
$sender = $sender->new({client => 'localhost.localdomain'});
my $client = $sender->{client}; # reach in to grab
The name of the client computer.
During the connection you send the mail server your computer's name. By default Mail::Sender sends (gethostbyname 'localhost')[0]. If that is not the address your needs, you can specify a different one. ๐ฅ๏ธ
โ confirm
# only delivery, to the 'from' address
$sender = $sender->new({confirm => 'delivery'});
# only reading, to the 'from' address
$sender = $sender->new({confirm => 'reading'});
# both: to the 'from' address
$sender = $sender->new({confirm => 'delivery, reading'});
# delivery: to specified address
$sender = $sender->new({confirm => 'delivery: my.other@address.com'});
my $confirm = $sender->{confirm}; # reach in to grab
Whether you want to request reading or delivery confirmations and to what addresses.
Keep in mind that confirmations are not guaranteed to work. Some servers/mail clients do not support this feature and some users/admins may have disabled it. So it's possible that your mail was delivered and read, but you won't get any confirmation! ๐ญ literally the "seen at 3:47pm" of email. don't count on it fr fr
๐ createmessageid
# mutating single attributes could get costly!
$sender = $sender->new({createmessageid => sub {
my $from = shift;
my ($sec, $min, $hour, $mday, $mon, $year) = gmtime(time);
$mon++;
$year += 1900;
return sprintf "<%04d%02d%02d_%02d%02d%02d_%06d.%s>", $year, $mon, $mday,
$hour, $min, $sec, rand(100000), $from;
}});
my $cm_id = $sender->{createmessageid}; # reach in to grab
This option allows you to overwrite the function that generates the message IDs for the emails. The option gets the "pure" sender's address as it's only parameter and is supposed to return a string. See the MessageID in Mail::Sender method. ๐ง
If you want to specify a message id you can also use the messageid parameter for the Open in Mail::Sender, OpenMultipart in Mail::Sender, MailMsg in Mail::Sender or MailFile in Mail::Sender methods.
๐ ctype
# mutating single attributes could get costly!
$sender = $sender->new({ctype => 'text/plain'});
my $type = $sender->{ctype}; # reach in to grab
The content type of a single part message or the body of the multi-part one.
Please do not confuse these two. ThemultipartinMail::Senderparameter is used to specify the overall content type of a multi-part message (for example any HTML document with inlined images) whilectypeis an ordinary content type for a single part message or the body of a multi-part message. โ ๏ธ like, they are NOT the same thing bestie, do not mix them up ๐
๐ debug
# mutating single attributes could get costly!
$sender = $sender->new({debug => '/path/to/debug/file.txt'});
$sender = $sender->new({debug => $file_handle});
my $debug = $sender->{debug}; # reach in to grab
All the conversation with the server will be logged to that file or handle. All lines in the file should end with CRLF (the Windows and Internet format). ๐
If you pass the path to the log file, Mail::Sender will overwrite it. If you want to append to the file, you have to open it yourself and pass the filehandle:
open my $fh, '>>', '/path/to/file.txt' or die "Can't open: $!";
my $sender = Mail::Sender->new({
debug => $fh,
});
overwrite warning!! pass a path and your old log is GONE. open it in append mode yourself if you're attached to it ๐ซถ
๐ debug_level
# mutating single attributes could get costly!
$sender = $sender->new({debug_level => 1});
# 1: only log server communication, skip all msg data
# 2: log server comm. and message headers
# 3: log server comm., message and part headers
# 4: log everything (default behavior)
my $level = $sender->{debug_level}; # reach in to grab
Only taken into account if the debug attribute is specified. (no debug, no vibes ๐ฆ)
๐งฌ encoding
# mutating single attributes could get costly!
$sender = $sender->new({encoding => 'Quoted-printable'});
my $encoding = $sender->{encoding}; # reach in to grab
Encoding of a single part message or the body of a multi-part message.
If the text of the message contains some extended characters or very long lines, you should use encoding => 'Quoted-printable' in the call to Open in Mail::Sender, OpenMultipart in Mail::Sender, MailMsg in Mail::Sender or MailFile in Mail::Sender.
If you use some encoding you should either useSendEncinMail::Senderor encode the data yourself! ๐ don't skip this step, it's giving "corrupted email" otherwise ๐ฌ
๐ฎ ESMPT
# mutating single attributes could get costly!
$sender = $sender->new({
ESMTP => {
NOTIFY => 'SUCCESS,FAILURE,DELAY',
RET => 'HDRS',
ORCPT => 'rfc822;my.other@address.com',
ENVID => 'iuhsdfobwoe8t237',
},
});
my $esmtp = $sender->{ESMTP}; # reach in to grab
This option contains data for SMTP extensions. For example, it allows you to request delivery status notifications according to RFC1891. If the SMTP server you connect to doesn't support this extension, the options will be ignored. You do not need to worry about encoding the ORCPT or ENVID parameters. โจ
ENVIDโ Used to propagate an identifier for this message transmission envelope, which is also known to the sender and will, if present, be returned in any Delivery Status Notifications issued for this transmission.NOTIFYโ To specify the conditions under which a delivery status notification should be generated. Should be eitherNEVERor a comma-separated list ofSUCCESS,FAILUREandDELAY.ORCPTโ Used to convey the original (sender-specified) recipient address.RETโ To request that Delivery Status Notifications containing an indication of delivery failure either return the entire contents of a message or only the message headers. Must be eitherFULLorHDRS.
๐ญ fake_cc
# mutating single attributes could get costly!
$sender = $sender->new({fake_cc => 'foo@bar.com'});
my $fake_cc = $sender->{fake_cc}; # reach in to grab
The address that will be shown in headers. If not specified, the cc in Mail::Sender attribute will be used. ๐
๐ฌ fake_from
# mutating single attributes could get costly!
$sender = $sender->new({fake_from => 'foo@bar.com'});
my $fake_from = $sender->{fake_from}; # reach in to grab
and that's where this stretch of the page hands off, bestie โ the vibe check continues ๐ฆ
Thanks for sticking around bestie, we're deep in the attribute list now and honestly? This is where the lore gets good ๐
The address that's gonna show up in the headers, okay? And if you don't set it, the from in the Mail::Sender attribute gets used instead. Easy.
๐ fake_to
# mutating single attributes could get costly!
$sender = $sender->new({fake_to => 'foo@bar.com'});
my $fake_to = $sender->{fake_to}; # reach in to grab
This is the recipient address that gets shown in the headers. If you don't specify it, the to in the Mail::Sender attribute is used. โจ
Real talk: if the list of people you're sending to is like, embarrassingly long, or if you simply do not want the recipients seeing each other's addresses โ set fake_to to some informative-but-bogus address, or to the address of your mailing/distribution list. Privacy slay ๐
๐ฆ from
# mutating single attributes could get costly!
$sender = $sender->new({from => 'foo@bar.com'});
my $from = $sender->{from}; # reach in to grab
The sender's email address. That's it, that's the whole vibe.
๐ธ headers
# mutating single attributes could get costly!
$sender = $sender->new({headers => 'Content-Type: text/plain'});
$sender = $sender->new({headers => {'Content-Type' => 'text/plain'}});
my $headers = $sender->{headers}; # reach in to grab
Use this parameter to slide custom headers into your message ๐ and like, it's flexible โ it can be either a string holding the headers in the right format, or a hash holding the headers and their values. Both ate.
๐ keepconnection
# mutating single attributes could get costly!
$sender = $sender->new({keepconnection => 1);
$sender = $sender->new({keepconnection => 0});
my $keepcon = $sender->{keepconnection}; # reach in to grab
Set this to a true value and Mail::Sender keeps the connection open for several messages. Iconic for batching, ngl.
The connection gets closed if you call Close in Mail::Sender with a true value, or if you call Open in Mail::Sender, OpenMultipart in Mail::Sender, MailMsg in Mail::Sender or MailFile in Mail::Sender with the smtp attribute.
Which literally means: if you want the object to keep the connection, pass thesmtpeither tonewin Mail::Sender, or only to the firstOpenin Mail::Sender,OpenMultipartin Mail::Sender,MailMsgin Mail::Sender orMailFilein Mail::Sender! Don't be out here handing outsmtpto every call and then wondering why the connection ghosted you ๐ญ
๐ง multipart
# mutating single attributes could get costly!
$sender = $sender->new({multipart => 'Mixed'});
my $multi = $sender->{multipart}; # reach in to grab
This is the MIME subtype for the whole message (Mixed/Related/Alternative). You might need to change it if you're sending an HTML body with some inline images, or if you want to post the message in plain text as well as HTML (alternative). Very versatile of you โจ
๐ on_errors
# mutating single attributes could get costly!
$sender = $sender->new({on_errors => 'undef'}); # return undef on error
$sender = $sender->new({on_errors => 'die'}); # raise an exception
$sender = $sender->new({on_errors => 'code'}); # return the negative error code (default)
# -1 = $smtphost unknown
# -2 = socket() failed
# -3 = connect() failed
# -4 = service not available
# -5 = unspecified communication error
# -6 = local user $to unknown on host $smtp
# -7 = transmission of message failed
# -8 = argument $to empty
# -9 = no message specified in call to MailMsg or MailFile
# -10 = no file name specified in call to SendFile or MailFile
# -11 = file not found
# -12 = not available in singlepart mode
# -13 = site specific error
# -14 = connection not established. Did you mean MailFile instead of SendFile?
# -15 = no SMTP server specified
# -16 = no From: address specified
# -17 = authentication protocol not accepted by the server
# -18 = login not accepted
# -19 = authentication protocol is not implemented
# -20 = all recipients were rejected by the server
# -21 = file specified as an attachment cannot be read
# -22 = failed to open the specified debug file for writing
# -23 = STARTTLS failed (for SSL or TLS encrypted connections)
# -24 = IO::Socket::SSL->start_SSL failed
# -25 = TLS required by the specified options, but the required modules are not available. Need IO::Socket::SSL and Net::SSLeay
# -26 = TLS required by the specified options, but the server doesn't support it
# -27 = unknown encoding specified for the mail body, part or attachment. Only base64, quoted-printable, 7bit and 8bit supported.
my $on_errors = $sender->{on_errors}; # reach in to grab
say $Mail::Sender::Error; # contains a textual description of last error.
Okay so this option is literally how you control the way Mail::Sender reports errors ๐ค and here's the sweet part: all methods return the $sender object if they succeed. So success is chill.
$Mail::Sender::Error, "$sender->{'error'}" and "$sender->{'error_msg'}" are set in all cases. No cap, every single time.
๐ port
# mutating single attributes could get costly!
$sender = $sender->new({port => 25});
my $port = $sender->{port}; # reach in to grab
The TCP/IP port used form the connection. By default it's getservbyname('smtp', 'tcp')||25. You should only need this if your mail server is being extra and waiting on a nonstandard port ๐
๐ฅ priority
# mutating single attributes could get costly!
$sender = $sender->new({priority => 1});
# 1. highest
# 2. high
# 3. normal
# 4. low
# 5. lowest
my $priority = $sender->{priority}; # reach in to grab
The message priority number. Pick your fighter from the list above ๐
๐ replyto
# mutating single attributes could get costly!
$sender = $sender->new({replyto => 'foo@bar.com'});
my $replyto = $sender->{replyto}; # reach in to grab
The reply to address. So people reply to the right person, bestie, it's basic manners ๐
๐ skip_bad_recipients
# mutating single attributes could get costly!
$sender = $sender->new({skip_bad_recipients => 1);
$sender = $sender->new({skip_bad_recipients => 0});
my $skip = $sender->{skip_bad_recipients}; # reach in to grab
If this is set to false, or you just don't specify it, Mail::Sender stops trying to send as soon as the first recipient's address fails. Like, immediate give-up energy.
Set it to a true value and it skips the bad addresses and tries to send the message at least to the good ones ๐ซถ If literally all the addresses get rejected by the server, it reports a All recipients were rejected message.
And if any addresses got skipped, $sender->{'skipped_recipients'} will be a reference to a hash containing the failed address and the server's response. Receipts! โจ
โญ smtp
# mutating single attributes could get costly!
$sender = $sender->new({smtp => 'smtp.bar.com'});
my $smtp = $sender->{smtp}; # reach in to grab
The IP address or domain of your SMTP server. The main character of this whole operation, fr fr.
๐ ssl_...
The ssl_version, ssl_verify_mode, ssl_ca_path, ssl_ca_file, ssl_verifycb_name, ssl_verifycn_schema and ssl_hostname options (if you specify them) are all passed to start_SSL in IO::Socket::SSL. The default version is TLSv1 and the verify mode is IO::Socket::SSL::SSL_VERIFY_NONE.
Heads up ๐ if you changessl_verify_modetoSSL_VERIFY_PEER, you may need to specify thessl_ca_file. And if you have Mozilla::CA installed, setting it toMozilla::CA::SSL_ca_file()may help. iykyk
๐ฆ subject
# mutating single attributes could get costly!
$sender = $sender->new({subject => 'An email is coming!'});
my $subject = $sender->{subject}; # reach in to grab
The subject of the message. Make it good, make it clickable, make it hers ๐
๐ธ tls_allowed
# mutating single attributes could get costly!
$sender = $sender->new({tls_allowed => 1}); # true, default
$sender = $sender->new({tls_allowed => 0}); # false
my $tls = $sender->{tls_allowed}; # reach in to grab
Set it true and Mail::Sender will attempt to use TLS (that's the encrypted connection, bestie ๐) whenever the server supports it. Requires that you have IO::Socket::SSL and Net::SSLeay installed, so like, check that first.
๐ง tls_required
# mutating single attributes could get costly!
$sender = $sender->new({tls_required => 1}); # true, require TLS encryption
$sender = $sender->new({tls_required => 0}); # false, plain. default
my $required = $sender->{tls_required};
Set this to a true value and the module will straight-up fail if it can't use TLS. No plaintext fallback, no plan B, no vibes. Periodt. ๐
๐ to
# mutating single attributes could get costly!
$sender = $sender->new({to => 'foo@bar.com'});
$sender = $sender->new({to => 'foo@bar.com, bar@baz.com'});
$sender = $sender->new({to => ['foo@bar.com', 'bar@baz.com']});
my $to = $sender->{to}; # reach in to grab
The recipient's addresses ๐ซถ and this parameter is flexible โ it can be either a comma separated list of email addresses, or a reference to a list of addresses. Either way, you're getting that message out there.
โจ METHODS โจ
okay bestie, Mail::Sender implements the following methods, and the roster is genuinely stacked. Let's go through every single one, no skips, no cap. ๐
Attach ๐
# set parameters in an ordered list
# -- description, ctype, encoding, disposition, file(s)
$sender = $sender->Attach(
'title', 'application/octet-stream', 'Base64', 'attachment; filename=*', '/file.txt'
);
$sender = $sender->Attach(
'title', 'application/octet-stream', 'Base64', 'attachment; filename=*',
['/file.txt', '/file2.txt']
);
# OR use a hashref
$sender = $sender->Attach({
description => 'some title',
charset => 'US-ASCII', # default
encoding => 'Base64', # default
ctype => 'application/octet-stream', # default
disposition => 'attachment; filename=*', # default
file => ['/file1.txt'], # file names
content_id => '#', # for auto-increment number, or * for filename
});
This one sends a file as a separate part of the mail message. Important vibe check: it only works in multi-part mode. ๐ฆ
Body ๐ธ
# set parameters in an ordered list
# -- charset, encoding, content-type
$sender = $sender->Body('US-ASCII', '7BIT', 'text/plain');
# OR use a hashref
$sender = $sender->Body({
charset => 'US-ASCII', # default
encoding => '7BIT', # default
ctype => 'text/plain', # default
msg => '',
});
Sends the head of the multi-part message body. You can specify the charset and the encoding, and yes bestie, you get to choose. โจ
Cancel ๐
$sender = $sender->Cancel;
Cancels an opened message. Simple enough, right? But listen: SendFile in Mail::Sender and other methods may set $sender->{'error'}. In that case, undef $sender calls $sender->Cancel, not $sender->Close!!! Like, read that again. This is not a drill. ๐ญ
ClearErrors ๐ง
$sender->ClearErrors();
Makes the various error variables undef. Clean slate energy. ๐ซถ
Close ๐
$sender->Close();
$sender->Close(1); # force override keepconnection
Closes and sends the email message. If you pass a true value to the method, the connection will be closed even if the keepconnection was specified. You should only keep the connection open if you plan to send another message immediately. And you should not keep it open for hundreds of emails even if you do send them all in a row. That's giving main character recklessness, and not in a cute way. ๐
This method should be called automatically when destructing the object, but you should not rely on it. If you want to be sure your message WAS processed by the server, you SHOULD call Close in Mail::Sender explicitly. Periodt. ๐
Connect ๐
This method gets called automatically. Do not call it yourself. It's giving "the adults are handling it." ๐
Connected ๐ฆ
my $bool = $sender->Connected();
Returns an undef or true value to let you know if you're connected to the mail server. Lowkey useful vibe check. โจ
EndPart ๐
$sender = $sender->EndPart($ctype);
Closes a multi-part part. If the $ctype is not present or evaluates to false, only the current SIMPLE part is closed! Don't do that unless you are really sure you know what you are doing. Like, genuinely sure. It's best to always pass to the ->EndPart() the content type of the corresponding ->Part(). Match them up, bestie. ๐
GetHandle ๐
$sender->Open({...});
my $handle = $sender->GetHandle();
$handle->print("Hello world.\n");
my ($mday,$mon,$year) = (localtime())[3,4,5];
$handle->print(sprintf("Today is %04d/%02d/%02d.", $year+1900, $mon+1, $mday));
close $handle;
Returns a file handle to which you can print the message or file to attach. The data you print to this handle will be encoded as necessary. Closing this handle closes either the message (for single part messages) or the part. It's giving "direct line to the socket," and honestly? Obsessed. ๐ฅ
MailFile ๐
# set parameters in an ordered list
# -- from, reply-to, to, smtp, subject, headers, message, files(s)
$sender = $sender->MailFile('from@foo.com','reply-to@bar.com','to@baz.com')
# OR use a hashref -- see the attributes section for a
# list of appropriate parameters.
$sender = $sender->MailFile({file => ['/file1','/file2'], msg => "Message"});
Sends one or more files by mail. If a message in $sender is opened, it gets closed and a new message is created and sent. $sender is then closed. ๐
The file parameter may be a string file name, a comma-separated list of filenames, or an array reference of filenames.
Keep in mind that parameters like ctype, charset and encoding will be used for the attached file, not the body of the message. If you want to specify those parameters for the body, you have to use b_ctype, b_charset and b_encoding. Don't mix those up, iykyk. ๐
MailMsg ๐
# set parameters in an ordered list
# -- from, reply-to, to, smtp, subject, headers, message
$sender = $sender->MailMsg('from@foo.com','reply-to@bar.com','to@baz.com')
# OR use a hashref -- see the attributes section for a
# list of appropriate parameters.
$sender = $sender->MailMsg({from => "foo@bar.com", msg => "Message"});
Sends a message. If a message in $sender is opened, it gets closed and a new message is created and sent. $sender is then closed. Very "send it and shut the door" behavior. ๐ชโจ
new ๐ฑ
# Create a new sender instance with only the 'from' address
my $sender = Mail::Sender->new('from_address@bar.com');
# Create a new sender with any attribute above set in a hashref
my $sender = Mail::Sender->new({attribute => 'value', });
# Create a new sender as a copy of an existing one
my $copy = $sender->new({another_attr => 'bar',});
Prepares a sender. Any attribute can be set during instance creation. This doesn't start any connection to the server. You have to use $sender->Open or $sender->OpenMultipart to start talking to the server. Like, new is the outfit planning; Open is actually leaving the house. ๐
The attributes are used in subsequent calls to $sender->Open and $sender->OpenMultipart. Each such call changes the saved variables. You can set smtp, from and other options here and then use the info in all messages. Reusable slay. ๐
Open ๐
# set parameters in an ordered list
# -- from, reply-to, to, smtp, subject, headers
$sender = $sender->Open('from@foo.com','reply-to@bar.com','to@baz.com');
# OR use a hashref -- see the attributes section for a
# list of appropriate parameters.
$sender = $sender->Open({to=>'to@baz.com', subject=>'Incoming!!!'});
Opens a new message. The only additional parameter that may not be specified directly in new in Mail::Sender is messageid. If you set this option, the message will be sent with that Message-ID, otherwise a new Message ID will be generated out of the sender's address, current date+time and a random number (or by the function you specified in the createmessageid attribute). ๐ฐ๏ธ๐ฒ
After the message is sent $sender->{messageid} will contain the Message-ID with which the message was sent. Cute little receipt, honestly. ๐งพโจ
OpenMultipart ๐งฉ
# set parameters in an ordered list
# -- from, reply-to, to, smtp, subject, headers, boundary
$sender = $sender->OpenMultipart('from@foo.com','reply-to@bar.com');
# OR use a hashref -- see the attributes section for a
# list of appropriate parameters.
$sender = $sender->OpenMultipart({to=>'to@baz.com', subject=>'Incoming!!!'});
Opens a multipart message. That's it, that's the whole vibe. ๐ฆ
Part ๐
# set parameters in an ordered list
# -- description, ctype, encoding, disposition, content_id, Message
$sender = $sender->Part(
'something', 'text/plain', '7BIT', 'attachment; filename="send.pl"'
);
# OR use a hashref -- see the attributes section for a
# list of appropriate parameters.
$sender = $sender->Part({
description => "desc",
ctype => "application/octet-stream", # default
encoding => '7BIT', # default
disposition => 'attachment', # default
content_id => '#', # for auto-increment number, or * for filename
msg => '', # You don't have to specify here, you may use SendEnc()
# to add content to the part.
});
Prints a part header for the multipart message and (if specified) the contents. It's giving "build-a-bear, but for MIME parts." ๐งธ๐
print ๐จ๏ธ
An alias for SendEnc in Mail::Sender. Short, sweet, iconic. โจ
QueryAuthProtocols ๐
my @protocols = $sender->QueryAuthProtocols();
my @protocols = $sender->QueryAuthProtocols( $smtpserver);
Queries the server specified in the attributes or in the parameter to this method for the authentication protocols it supports. Very "so what are we working with?" energy. ๐ต๏ธโโ๏ธ
Send ๐จ
$sender = $sender->Send(@strings);
Prints the strings to the socket. It doesn't add any line terminations or encoding. You should use "\r\n" as the end-of-line!
UNLESS YOU ARE ABSOLUTELY SURE YOU KNOW WHAT YOU ARE DOING YOU SHOULD USE SendEnc in Mail::Sender INSTEAD!
Bestie, that warning is loud for a reason. ๐ญ
SendEnc ๐
$sender = $sender->SendEnc(@strings);
Prints the bytes to the socket. It doesn't add any line terminations. Encodes the text using the selected encoding: none | Base64 | Quoted-printable. You should use "\r\n" as the end-of-line! Slay, but correctly. โจ
SendEx ๐
$sender = $sender->SendEx(@strings);
Prints the strings to the socket. Doesn't add any end-of-line characters. Changes all end-of-lines to "\r\n". Doesn't encode the data!
UNLESS YOU ARE ABSOLUTELY SURE YOU KNOW WHAT YOU ARE DOING YOU SHOULD USE SendEnc in Mail::Sender INSTEAD!
Again with the lowercase warning? No bestie, this is uppercase for a reason. ๐
SendFile ๐
Alias for Attach in Mail::Sender. Same energy, different name. ๐
SendLine ๐
$sender = $sender->SendLine(@strings);
Prints the strings to the socket. Each byte string is terminated by "\r\n". No encoding is done. You should use "\r\n" as the end-of-line!
UNLESS YOU ARE ABSOLUTELY SURE YOU KNOW WHAT YOU ARE DOING YOU SHOULD USE SendLineEnc in Mail::Sender INSTEAD!
The drama is warranted. ๐ญ
SendLineEnc ๐ธ
$sender = $sender->SendLineEnc(@strings);
Prints the strings to the socket and adds the end-of-line character at the end. Encodes the text using the selected encoding: none | Base64 | Quoted-printable.
Do NOT mix up Send in Mail::Sender, SendEx in Mail::Sender, SendLine in Mail::Sender, or SendLineEx in Mail::Sender with SendEnc in Mail::Sender or SendLineEnc in Mail::Sender! SendEnc in Mail::Sender does some buffering necessary for correct Base64 encoding, and Send in Mail::Sender and SendEx in Mail::Sender are not aware of that. ๐ซ
Usage of Send in Mail::Sender, SendEx in Mail::Sender, SendLine in Mail::Sender, and SendLineEx in Mail::Sender in non xBIT parts is not recommended. Using Send(encode_base64($string)) may work, but more likely it will not! In particular, if you use several such to create one part, the data is very likely to get crippled. Do not play with this. ๐
SendLineEx โญ
$sender = $sender->SendLineEnc(@strings);
Prints the strings to the socket. Adds an end-of-line character at the end. Changes all end-of-lines to "\r\n". Doesn't encode the data!
UNLESS YOU ARE ABSOLUTELY SURE YOU KNOW WHAT YOU ARE DOING YOU SHOULD USE SendLineEnc in Mail::Sender INSTEAD!
And yes, bestie, the example really says SendLineEnc up there. Copy it exactly, don't "fix" it, and keep the vibe check intact. ๐
โจ
โจ FUNCTIONS โจ
okay so Mail::Sender also ships with these three functions, and they're lowkey the backstage crew of the whole operation ๐
๐ธ GuessCType
my $ctype = Mail::Sender::GuessCType($filename, $filepath);
It guesses the content type based on the filename or the file contents โ whichever it can work with ๐ต๏ธโโ๏ธ This is literally the function that gets called when you attach a file and you're too lazy to specify the content type yourself. And bestie, heads up: it is not exported by default! So you gotta call it fully qualified, no cap.
๐ MessageID
my $id = Mail::Sender::MessageID('from@foo.com');
Generates a "unique" message ID for a given from address. The quotes around "unique" are doing a lot of work there and honestly we respect the honesty ๐ญ
๐ฆ ResetGMTdiff
Mail::Sender::ResetGMTdiff();
So here's the tea: the module computes the local-vs-GMT time difference so it can include it in the timestamps it adds into the message headers โฐ But plot twist โ that difference can change because of summer savings time changes. So if you've got a long-running program just vibing for ages, you might wanna reset the time difference occasionally. It's giving "reapply your sunscreen" energy, fr fr ๐งด
๐ฅ BUGS ๐ฅ
ngl, I'm sure there are many. Please let me know if you find any ๐
But the iconic part: the problem with multi-line responses from some SMTP servers (namely qmail โ http://www.qmail.org/top.html) is solved at last ๐โจ periodt, we love a resolved-issue arc.
๐ SEE ALSO ๐
Email::Sender
There are lots of mail-related modules on CPAN, bestie. Be wise: use Email::Sender! ๐
๐ซถ AUTHOR ๐ซถ
Jan Krynickรฝ Jenda@Krynicky.cz http://Jenda.Krynicky.cz โ the main character who made all this happen โจ
๐ CONTRIBUTORS ๐
- Brian Blakley
<bblakley@mp5.net>, - Chase Whitener
<capoeirab@cpan.org>, - Ed McGuigan
<itstech1@gate.net>, - John Sanche
<john@quadrant.net> - Rodrigo Siqueira
<rodrigo@insite.com.br>,
the supporting cast that carried this whole production ๐ (yes, the punctuation on that last bullet of John's is missing in the original, and yes, I'm preserving it character for character, don't look at me ๐)
๐ LICENSE AND COPYRIGHT ๐
Copyright (c) 1997-2014 Jan Krynickรฝ <Jenda@Krynicky.cz>. All rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
and that's the whole page, bestie, you made it to the end ๐๐
this was perl v5.40.0, dated 2024-07-19, and you've officially read the entirety of Mail::Sender(3). go forth and send some mail, you absolute icon ๐๐
๐ฆ where this page comes from
- epel 10: perl-Mail-Sender 1:0.903-25.el10_0 ยท GPL-1.0-or-later OR Artistic-1.0-Perl
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms