Sending email through G Suite using Perl

Viewed 99

After almost a decade of sending email through our G Suite account/address, the script stopped working last night after a hosting company server upgrade. (Unfortunately the hosting company has currently filed this under "Not Our Problem", so there's really no help from that side. I'm hoping to at least rule out anything we're doing wrong, and to be able to go back to them with some useful forensics.)

Here's the relevant Perl excerpt:

    $smtp = Net::SMTP->new('smtp.gmail.com', Port => 465, Timeout => 30, Hello => 'mail.mydomain.com', SSL => 1, Debug => 1);
    # $login and $pass are valid address@mydomain.com and password
    # used for logging into the Gmail interface at mail.mydomain.com
    print "auth($login, $pass)\n";
    $smtp->auth($login, $pass) or die "Unable to authenticate";
    $smtp->mail($login);
    $smtp->recipient($email);
    $smtp->data($message) or die "data() failed sending to: $email\n";
    $smtp->quit;

And here is the output:

    Net::SMTP::_SSL>>> Net::SMTP::_SSL
    Net::SMTP::_SSL>>>   IO::Socket::SSL(2.060)
    Net::SMTP::_SSL>>>     IO::Socket::IP(0.39)
    Net::SMTP::_SSL>>>       IO::Socket(1.39)
    Net::SMTP::_SSL>>>         IO::Handle(1.39)
    Net::SMTP::_SSL>>>           Exporter(5.73)
    Net::SMTP::_SSL>>>   Net::SMTP(3.11)
    Net::SMTP::_SSL>>>     Net::Cmd(3.11)
    Net::SMTP::_SSL=GLOB(0x7fc8de8ab9d8)<<< 220 smtp.gmail.com ESMTP [###] - gsmtp
    Net::SMTP::_SSL=GLOB(0x7fc8de8ab9d8)>>> EHLO mail.mydomain.com
    Net::SMTP::_SSL=GLOB(0x7fc8de8ab9d8)<<< 250-smtp.gmail.com at your service, [###.###.###.###]
    Net::SMTP::_SSL=GLOB(0x7fc8de8ab9d8)<<< 250-SIZE 35882577
    Net::SMTP::_SSL=GLOB(0x7fc8de8ab9d8)<<< 250-8BITMIME
    Net::SMTP::_SSL=GLOB(0x7fc8de8ab9d8)<<< 250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH
    Net::SMTP::_SSL=GLOB(0x7fc8de8ab9d8)<<< 250-ENHANCEDSTATUSCODES
    Net::SMTP::_SSL=GLOB(0x7fc8de8ab9d8)<<< 250-PIPELINING
    Net::SMTP::_SSL=GLOB(0x7fc8de8ab9d8)<<< 250-CHUNKING
    Net::SMTP::_SSL=GLOB(0x7fc8de8ab9d8)<<< 250 SMTPUTF8
    auth(address@mydomain.com, [password])
    Unable to authenticate at mymodule.pm line 459.

A couple of other notes:

  1. Less Secure Apps access is turned on for both the domain and the user address@mydomain.com (as it was before).
  2. These are valid credentials. They can currently be used to log in to mail.mydomain.com (the web/Gmail interface), and are the same as were used previously for this method.
  3. The method used to send mail via Gmail is described fairly commonly on the web, both here on SO and elsewhere, including https://support.google.com/a/answer/176600: Use the Gmail SMTP server under Other setup options.
  4. Again, this worked up until a server upgrade. But since I'm not seeing anything in the error output, I'm not sure where to start looking for breakage.

Usually when this happens I'm missing something obvious, so am I missing something obvious?

1 Answers

Given that the debug output shows no attempt for authentication it is likely that the required Authen::SASL module is not installed or not properly installed. From the documentation of Net::SMTP:

auth ( USERNAME, PASSWORD )
auth ( SASL )
Attempt SASL authentication. Requires Authen::SASL module. The first form constructs a new Authen::SASL object using the given username and password; the second form uses the given Authen::SASL object.

To determine the issue it might be useful to not simply die() with a custom error but also log $smtp->message. Based on this code it will then maybe log the error "Need MIME::Base64 and Authen::SASL todo auth".

Related