Hi,
I cannot seem to figure out how to send mail via gmail using Net::SMTP (that's what you're supposed to use right?).
Here is what I try:
use strict;
use Net::SMTP;
my $from = 'somebody@gmail.com';
my $full_name = "Some Body";
my $pw = "my_password";
my $to = 'someone@somewhere.com';
my $smtp = Net::SMTP->new('smtp.gmail.com',
Port=> 587,
User => $from,
Password => $pw
);
$smtp->mail($from);
$smtp->recipient($to);
$smtp->data();
$smtp->datasend("To: $to");
$smtp->datasend("From: $full_name\n");
$smtp->datasend("Content-Type: text/plain \n");
$smtp->datasend("Subject: A Test Mail");
$smtp->datasend("\n");
$smtp->datasend("This is a test mail body");
$smtp->datasend("\n");
$smtp->dataend();
$smtp->quit();
It all looks very silly to me and (even worse) it does not work.
I do not get an error, but no mail seems to get sent.
So my question: How do you send mail via gmail using perl in the year 2020?
Many thanks!
EDIT:
Why do code-blocks look so bad now?
EDIT2: Because copying the code introduced a lot of white space - fixed that.
-
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.
|