Mail-DWIM
view release on metacpan or search on metacpan
######################################################################
Revision history for Perl extension Mail::DWIM
0.09 (2025/07/13)
(ms) Mandatory SSL smtp server communication with user/password auth
0.08 (2014/10/24)
(ms) Added SASL auth for SMTP servers, specify 'user' and 'password'.
(ms) Compensated for MIME::Lite shortcomings and added 'boundary' to
content-type header on html emails.
0.07 (2014/06/19)
(ms) Added smtp_port parameter (defaults to 25).
(ms) Now setting ENV var MAILADDRESS for smtp transport
0.06 2010/02/03
(ms) Splitting 'to' field on comma separators because for SMTP hosts,
as SMTP protocol doesn't support comma-separated recipient lists.
0.05 2008/10/10
for (qw(Content-Transfer-Encoding Content-Type
MIME-version)) {
$headers{$_} = $msg->attr($_);
}
# evil hack to compensate for MIME::Lite's shortcomings
if( $headers{ "Content-Type" } !~ /boundary/ ) {
$headers{ "Content-Type" } =
$headers{ "Content-Type" } .
qq{; boundary="} .
$msg->{ SubAttrs }->{ "content-type" }->{ boundary } .
qq{"};
}
return \%headers, $msg->body_as_string;
}
###########################################
sub attach_msg {
###########################################
my($text, @files) = @_;
mail(
to => 'foo@bar.com',
subject => 'test message',
html_compat => 1,
text => 'This is an <b>HTML</b> email.'
);
This will create two attachments, the first one as plain text
(generated by HTML::Text to the best of its abilities), followed by
the specified HTML message marked as content-type C<text/html>.
Non-HTML mail readers will pick up the first one, and Outlook-using
marketroids get fancy HTML. Everyone wins.
=head2 Test Mode
If the environment variable C<MAIL_DWIM_TEST> is set to a filename,
C<Mail::DWIM> prepares mail as usual, but doesn't send it off
using the specified transport mechanism. Instead, it appends outgoing
mail ot the specified file.
mail(
to => 'foo@bar.com',
subject => 'test message',
html_compat => 1,
text => 'This is an <b>HTML</b> email.'
);
This will create two attachments, the first one as plain text (generated
by HTML::Text to the best of its abilities), followed by the specified
HTML message marked as content-type "text/html". Non-HTML mail readers
will pick up the first one, and Outlook-using marketroids get fancy
HTML. Everyone wins.
Test Mode
If the environment variable "MAIL_DWIM_TEST" is set to a filename,
"Mail::DWIM" prepares mail as usual, but doesn't send it off using the
specified transport mechanism. Instead, it appends outgoing mail ot the
specified file.
"Mail::DWIM"'s test suite uses this mode to run a regression test
( run in 2.146 seconds using v1.01-cache-2.11-cpan-d7f47b0818f )