jeanluca has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks

I have the following script for sending email using the the smtp server from gmail
#!/usr/bin/perl -w use warnings; use strict; use Net::SMTP::TLS; my $EMAIL_SMTP='smtp.gmail.com'; my $EMAIL_HELLO='me@mydomain.com'; # ????? my $EMAIL_PORT=587; my $EMAIL_SENDER = 'mygmail@gmail.com'; my $EMAIL_PASSWORD='s3cr3t'; my $mailer = new Net::SMTP::TLS ( $EMAIL_SMTP, Hello => $EMAIL_HELLO, Port => $EMAIL_PORT, User => $EMAIL_SENDER, Password=> $EMAIL_PASSWORD, ); # this doesn't work #$mailer->datasend("From: me\@mydomain.com"); #$mailer->datasend("To: you\@yourdomain.com"); #$mailer->datasend("Subject: This is a test"); #$mailer->datasend("\n"); #$mailer->datasend("blahblah\n"); $mailer->mail('me@mydomain.com'); $mailer->to(you@yourdomain.com'); $mailer->data; $mailer->datasend("Sent thru TLS!"); $mailer->dataend; $mailer->quit;
Sending mail with this script, I receive email from mygmail@gmail.com not from me@mydomain.com. Can this be changed ?
Also, what is the HELLO good for?

Cheers
LuCa

Replies are listed 'Best First'.
Re: howto set the 'from' address (Net::SMTP::TLS)?
by cormanaz (Deacon) on Jun 25, 2009 at 21:51 UTC
    First off, why are you using Net::SMTP::TLS rather than Net::SMTP? Do you need the security? If not then you might switch to Net::SMTP and follow the example here.

    The HELLO is part of the authentication process, but I have not used it so I can't tell you any more than that, except that $EMAIL_HELLO is supposed to be a host.domain, not an email address.

    Finally it's sending to me@mydomain.com because that's what you've got in the mail() method. Check the docs.

      I think security is required for smtp.gmail.com
Re: howto set the 'from' address (Net::SMTP::TLS)?
by Anonymous Monk on Jun 26, 2009 at 03:09 UTC
    The purpose of authenticated email is so you can't fake sender