Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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":



  • 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.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2024-04-19 17:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found