【问题标题】:Gmail smtp 5.5.2 error with PHP ZEND and Xoauth2使用 PHP ZEND 和 Xoauth2 的 Gmail smtp 5.5.2 错误
【发布时间】:2014-05-19 18:20:40
【问题描述】:

我尝试使用带有 xoauth 身份验证的 gmail api 通过 Gmail 发送电子邮件。 来自谷歌的 IMAP 示例运行良好。 我正在尝试根据这些文章来实现这个东西:
http://www.boxuk.com/blog/php-smtp-xoauth2-gmail/
http://www.chargenevier.com/2013/02/google-smtp-and-oauth2-authentication/

我在尝试发送电子邮件时收到以下错误: 致命错误:未捕获的异常 'Zend_Mail_Protocol_Exception' 带有消息 '5.5.2 语法错误。 e5sm17066681bkg.3 - gsmtp

我也尝试了第一篇文章中的 openssl 方法,在写入 XOAUTH2 后,我从服务器收到相同的错误并且连接已关闭。

有趣的是,当我回显 base64_encode("user=\1auth=Bearer \1\1") 时,我得到的字符串比我回显 $smtpInitClientRequestEncoded 变量时的字符串短在 IMAP 示例中很好。 而 mail.google.com 给出 5.5.2 Cannot decode response for the short encoding string.

function constructAuthString($email, $accessToken) {
    return base64_encode("user=$email\1auth=Bearer $accessToken\1\1");
}

function sendEmail($email,$accessToken){
    $smtpInitClientRequestEncoded = constructAuthString($email, $accessToken);

    echo '<br/><br/>BASE64: ' . $smtpInitClientRequestEncoded;

    $config = array('ssl' => 'ssl',
        'port' => '465',
        'auth' => 'xoauth',
        'xoauth_request' => $smtpInitClientRequestEncoded
    );

    $transport = new Zend_Mail_Transport_Smtp('smtp.gmail.com', $config); 

    $mail = new Zend_Mail();
    $mail->setBodyText('some body text');
    $mail->setFrom($email, 'Some Sender');
    $mail->addTo("myemail@gmail.com", 'Some Recipient');
    $mail->setSubject('Test sending by smtp');
    $mail->send($transport);
}

你怎么看,有什么问题吗?为什么不进行身份验证?

【问题讨论】:

    标签: php zend-framework oauth-2.0 google-api smtp-auth


    【解决方案1】:

    $accesToken 不好。我通过了 $client->getAccessToken(),但你只需要这个字符串中的 access_token 字符串,而不是全部。

    【讨论】:

      猜你喜欢
      • 2011-05-18
      • 2011-10-16
      • 2012-01-24
      • 2018-09-25
      • 2018-05-17
      • 2014-08-02
      • 1970-01-01
      • 2010-11-08
      • 2018-08-16
      相关资源
      最近更新 更多