本文介绍了无法通过IMAP服务器进行身份验证:[AUTHENTICATIONFAILED]无效的凭据(失败)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试通过imap从电子邮件中获取消息时-我遇到此错误:

When i trying to get messages from email via imap - i have this error:

麻烦在哪里?

PHP代码:

<?php
/* connect to gmail */
$hostname = '{imap.gmail.com:993/imap/ssl}INBOX';
$username = '[email protected]';
$password = 'pass';

/* try to connect */
$inbox = imap_open($hostname,$username,$password, NULL, 1, array('DISABLE_AUTHENTICATOR' => 'GSSAPI')) or die('Cannot connect to Gmail: ' . imap_last_error());

/* grab emails */
$emails = imap_search($inbox,'ALL');

/* if emails are returned, cycle through each... */
if($emails) {

/* begin output var */
$output = '';

/* put the newest emails on top */
rsort($emails);

/* for every email... */
foreach($emails as $email_number) {

    /* get information specific to this email */
    $overview = imap_fetch_overview($inbox,$email_number,0);
    $message = imap_fetchbody($inbox,$email_number,2);

    /* output the email header information */
    $output.= '<div class="toggler '.($overview[0]->seen ? 'read' : 'unread').'">';
    $output.= '<span class="subject">'.$overview[0]->subject.'</span> ';
    $output.= '<span class="from">'.$overview[0]->from.'</span>';
    $output.= '<span class="date">on '.$overview[0]->date.'</span>';
    $output.= '</div>';

    /* output the email body */
    $output.= '<div class="body">'.$message.'</div>';
}

echo $output;
}

/* close the connection */
imap_close($inbox);

推荐答案

如果您使用的是G Suite,则必须与G Suite管理员联系,以在Google管理面板中启用对用户应用的不安全访问,URL如https://admin.google.com/{YOUR_DOMAIN_NAME}/AdminHome?hl=en#ServiceSettings/notab=1&service=securitysetting&subtab=lesssecureappsaccess

If you are using G Suite, you have to contact your G Suite administrator to enable not secure access for users apps in Google Admin panel, URL like https://admin.google.com/{YOUR_DOMAIN_NAME}/AdminHome?hl=en#ServiceSettings/notab=1&service=securitysetting&subtab=lesssecureappsaccess

或采用这种方式(对于G Suite管理员)

or go this way (for G Suite admin)

  1. https://admin.google.com
  2. 安全设置
  3. 基本设置(第一个链接)
  4. 安全性较低的应用程序->转到安全性较低的应用程序的设置
  5. 强制所有用户访问安全性较低的应用程序(不推荐)
  6. 保存
  7. 利润(可以在1-2分钟内生效,请等待一段时间)
  1. https://admin.google.com
  2. Security settings
  3. Basic settings (first link)
  4. Less secure apps -> Go to settings for less secure apps
  5. Enforce access to less secure apps for all users (Not Recommended)
  6. Save
  7. PROFIT (can take effect in 1-2 mins, wait for some time please)

这篇关于无法通过IMAP服务器进行身份验证:[AUTHENTICATIONFAILED]无效的凭据(失败)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 00:01