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.


In reply to gmail and Net::SMTP by morgon

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.