530,5.7.0SMTP 服务器错误:MAIL FROM 命令失败详细信息:需要身份验证

530,5.7.0SMTP 服务器错误:MAIL FROM 命令失败详细信息:需要身份验证

PHP Mail 错误信息如下:

530,5.7.0SMTP server error: MAIL FROM command failed Detail: Authentication Required

以下是我的 PHP 脚本的关键部分。

new PHPMailer(true)
Host as 'smtp.gmail.com'
SetFrom('MyUsername-Of-Ubuntu-Login@mail.theDomainCreatedInPostfixCOnfiguration.com')
Port=587
SMTPSecure = 'tls'
Username = "one-of-my-gmail-email-id"
Password = "gmail-account-password"
SMTPOptions = array(
  'ssl' => array(
  'cafile' => '/etc/postfix/cacert.pem',
  'verify_peer' => false,
  'verify_peer_name' => false,
  'allow_self_signed' => true
)

作为故障排除的一部分,我做了以下事情:

  1. 在 中/etc/mail/sendmail.inc,通过删除前缀"dnl #使用取消注释以下内容/etc/mail/local-host-names

    1. 而且,我确实有我的主机名列表/etc/mail/local-host-names

    2. 执行命令:$ make -C /etc/mail

  2. /etc/postfix/main.cf使用以下值进行编辑:

    mydomain = theDomainCreatedInPostfixCOnfiguration.com
    relay_domains = theDomainCreatedInPostfixCOnfiguration.com
    smtpd_sasl_security_options = noanonymous,noplaintext
    mynetworks = 127.0.0.0/8 TheIPaddressOfMyUbuntuMachineWifi
    relayhost = smtp.gmail.com
    myorigin = /etc/mailname
    myhostname = mail.theDomainCreatedInPostfixCOnfiguration.com
    smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
    
    1. /etc/mailname,我有mail.theDomainCreatedInPostfixCOnfiguration.com

    2. /etc/aliases,我有

      root: MyUsername-Of-Ubuntu-Login
      daemon: MyUsername-Of-Ubuntu-Login
      postmaster: MyUsername-Of-Ubuntu-Login
      
    3. 我运行命令:systemctl reload postfix

    4. 我运行命令:sudo postmap /etc/aliases,并构建aliases.db

答案1

sudo apt-get install libsasl2-modules

在 /etc/postfix/sasl_passwd 中添加这些内容 [Smtp.gmail.com]:587 gmailusername:gmailapppassword

sudo postmap /etc/postfix/sasl_passwd sudo chown root:root /etc/postfix/sasl_passwd /etc/postfix/sasl_passwd.db sudo chmod 0600 /etc/postfix/sasl_passwd /etc/postfix/sasl_passwd.db

Add below lines at end of main.cf
# enable SASL authentication

smtp_sasl_auth_enable = yes # 禁止允许匿名身份验证的方法。 smtp_sasl_security_options = noanonymous # 在哪里可以找到 sasl_passwd smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd # 启用 STARTTLS 加密 smtp_use_tls = yes # 在哪里可以找到 CA 证书 smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt

sudo service postfix restart

Hope your issue will resolve

相关内容