in reply to Send email via Gmail

I can't believe how complicated / long winded this has proven to be (I've written a whole invoice generating script in the time its taken to get here :S)

What a shame it is that you did not search here before you started. Merely searching for send gmail would have found Sending mails via gmail with noxxi's informative reply pointing out the unmaintained status of Net::SMTP::TLS and suggesting better alternatives.

Replies are listed 'Best First'.
Re^2: Send email via Gmail
by ultranerds (Hermit) on Oct 08, 2016 at 13:37 UTC
    Hi,

    Thanks for the reply. Ah man, I didn't realise I was running on such an old Net:::SMTP. I've upgraded it now. Almost have it working:

    use Net::SMTP; my $smtp = Net::SMTP->new('smtp.gmail.com', Hello => 'smtp.gmail.com', Timeout => 30, Debug => 1, SSL => 1, ); $smtp->auth($CFG->{db_smtp_user}, $CFG->{db_smtp_pass}); $smtp->data(); $smtp->datasend($email); $smtp->dataend();
    With the debug on, I get this error (and no email sent);

    Net::SMTP::_SSL=GLOB(0x3b08578)<<< 502 5.5.1 Unrecognized command. y39sm8325289wmh.21 - gsmtp

    Not quite sure what that's telling me though?

    Thanks!

    Andy

      In this snippet you have provided there are 5 method calls and not one test of the return value of any of them. Why not test those return values to see where things are going awry? eg.

      $smtp->auth($CFG->{db_smtp_user}, $CFG->{db_smtp_pass}) or die "Bad au +th for user $CFG->{db_smtp_user}";
        Hi,

        Funnily enough, I was just playing with that :)
        use Net::SMTP; my $smtp = Net::SMTP->new('smtp.gmail.com', Hello => 'smtp.gmail.com', Timeout => 30, Debug => 1, SSL => 1 ) || die "Error: $!"; $smtp->auth($CFG->{db_smtp_user}, $CFG->{db_smtp_pass}) or die "C +ould not authenticate with mail.\n"; $smtp->data(); $smtp->datasend($email) || die $!; $smtp->dataend() || die $smtp->message();


        It complains on line 99, which is:

        $smtp->dataend() || die $!;

        Which gives the following error message:

        5.5.1 Unrecognized command. vs7sm25292357wjb.10 - gsmtp


        I found a similar post here: http://www.perlmonks.org/?node_id=680369, but I'm not quite sure what the suggestion is (it also 2008, so I'm not sure if its relative any more)

        Just to clarify a bit more, this is the debug that reports the error:

        Net::SMTP::_SSL>>> Net::SMTP::_SSL Net::SMTP::_SSL>>> IO::Socket::SSL(2.019) Net::SMTP::_SSL>>> IO::Socket::IP(0.32) Net::SMTP::_SSL>>> IO::Socket(1.38) Net::SMTP::_SSL>>> IO::Handle(1.35) Net::SMTP::_SSL>>> Exporter(5.71) Net::SMTP::_SSL>>> Net::SMTP(3.10) Net::SMTP::_SSL>>> Net::Cmd(3.10) ******* Net::SMTP::_SSL=GLOB(0x1f5e100)<<< 220 smtp.gmail.com ESMTP y2sm147858 +26wjx.20 - gsmtp ******* Net::SMTP::_SSL=GLOB(0x1f5e100)>>> EHLO localhost.localdomain Net::SMTP::_SSL=GLOB(0x1f5e100)<<< 250-smtp.gmail.com at your service, + [2a01:7e00::f03c:91ff:fea8:e2c5]


        Cheers

        Andy