For my use-case, I’ve never had easy access to a private/internal mail server. I’ve always used SMTP methods to connect to gmail or yahoo. I haven’t ever tried any of the other solutions (MailTools, Mail::Sendmail), so I don’t know if they work for my scenario. It does look like as of now (Feb 2019), MIME::Lite and Mail::Sender are not recommended by their respective maintainers.
My solution involves 3 modules:
I’ve tested this on gmail and yahoo. For gmail, I had to go into my account settings and allow less secure apps to access my account. I think this just refers OAuth. You will still use TLS/SSL to talk to Gmail, so you won't be sending your plaintext password over the Internet.
use MIME::Entity;
use Email::Sender::Simple qw( sendmail );
use Email::Sender::Transport::SMTP;
$user = "myself\@gmail.com";
#must be a legitimate email account
$pass = "mypassword";
$mailhost = "smtp.gmail.com";
#for yahoo, use smtp.mail.yahoo.com
$rcpt = other.user@other.com;
#could also send it back to myself;
$file = "my_picture.jpg";
$debug = 0; #enable by setting to 1
my $transport = Email::Sender::Transport::SMTP->new(
host => $mailhost,
port => 465,
ssl => "ssl",
sasl_username => $user,
sasl_password => $pass,
debug => $debug
);
my $mime = MIME::Entity->build(
To => $rcpt,
From => $user,
Subject => "Simple MIME from Perl",
Type => "multipart/mixed");
$mime->attach(Data => "Hungry? Eat a Milky Way",
Type => "text/plain");
if(defined $file and -e $file)
{
$mime->attach(Path => $file,
Encoding => "base64",
Disposition => "attachment");
}
sendmail($mime, { transport => $transport });
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.