使用Perl通过G Suite发送电子邮件 [英] Sending email through G Suite using Perl

查看:77
本文介绍了使用Perl通过G Suite发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过我们的G Suite帐户/地址发送电子邮件将近十年后,该脚本在托管公司服务器升级后于昨晚停止工作.(不幸的是,托管公司目前已将此文件提交到不是我们的问题"下,因此,那方面确实没有任何帮助.我希望至少可以排除我们做错的任何事情,并且以便可以通过一些有用的取证方法与他们联系.)

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.)

以下是相关的Perl摘录:

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;

这是输出:

    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.

其他一些注意事项:

  1. 该域和用户地址@ mydomain.com均已启用最低安全应用程序访问权限.
  2. 这些是有效的凭据.当前,它们可以用于登录mail.mydomain.com(Web/Gmail界面),并且与以前用于此方法的相同.
  3. 在网络上相当普遍地描述了通过Gmail发送邮件的方法,无论是在SO还是在其他地方,包括
  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?

推荐答案

鉴于调试输出未显示任何身份验证尝试,很可能必需的 Net :: SMTP的文档:

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(用户名,密码)
身份验证(SASL)
尝试SASL身份验证.需要Authen :: SASL模块.第一种形式构造了一个新的使用给定的用户名和密码的Authen :: SASL对象;第二表单使用给定的Authen :: SASL对象.

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.

要确定问题,可能不仅有用带有自定义错误的die(),而且还要记录 $ smtp->消息.根据此代码,它可能会记录错误需要MIME :: Base64和Authen :: SASL进行身份验证"..

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".

这篇关于使用Perl通过G Suite发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆