无法登录外部 IMAP/POP3 服务器

无法登录外部 IMAP/POP3 服务器

我已经通过本教程安装了 Postfix、Dovecot 和 MySQL (https://www.linode.com/docs/email/postfix/troubleshooting-problems-with-postfix-dovecot-and-mysql/)。

当我执行以下命令时,我收到以下响应:

$ openssl s_client -connect mail.domain.com:993

* OK [CAPABILITY IMAP4rev1 LITERAL+ SASL-IR LOGIN-REFERRALS ID ENABLE IDLE AUTH=PLAIN] Dovecot ready.

我可以通过控制台登录我的虚拟账户,但是当我使用这个 PHP 脚本时,它会失败(页面继续加载)。

<?php 
    $mbox = imap_open("{mail.domain.com:993}", "[email protected]", "password");
?>

当我运行 dovecot -n 命令时,我得到以下输出:

$ dovecot -n

# 2.2.22 (fe789d2): /etc/dovecot/dovecot.conf
# Pigeonhole version 0.4.13 (7b14904)
# OS: Linux 4.4.0-130-generic x86_64 Ubuntu 16.04.3 LTS
auth_debug = yes
auth_verbose = yes
log_path = /var/log/dovecot.log
mail_location = mbox:~/mail:INBOX=/var/mail/%u
mail_privileged_group = mail
namespace inbox {
  inbox = yes
  location =
  mailbox Drafts {
    special_use = \Drafts
  }
  mailbox Junk {
    special_use = \Junk
  }
  mailbox Sent {
    special_use = \Sent
  }
  mailbox "Sent Messages" {
    special_use = \Sent
  }
  mailbox Trash {
    special_use = \Trash
  }
  prefix =
}
passdb {
  args = /etc/dovecot/dovecot-sql.conf.ext
  driver = sql
}
protocols = imap pop3 lmtp
service auth-worker {
  user = vmail
}
service auth {
  unix_listener /var/spool/postfix/private/auth {
    group = postfix
    mode = 0666
    user = postfix
  }
  unix_listener auth-userdb {
    mode = 0600
    user = vmail
  }
  user = dovecot
}
service imap-login {
  inet_listener imap {
    port = 0
  }
}
service lmtp {
  unix_listener /var/spool/postfix/private/dovecot-lmtp {
    group = postfix
    mode = 0600
    user = postfix
  }
}
service pop3-login {
  inet_listener pop3 {
    port = 0
  }
}
ssl = required
ssl_cert = </etc/dovecot/private/dovecot.crt
ssl_key = </etc/dovecot/private/dovecot.key
userdb {
  args = uid=vmail gid=vmail home=/var/mail/vhosts/%d/%n
  driver = static
}

我使用防火墙‘ufw’。

$ ufw status

Status: active

To                         Action      From
--                         ------      ----
Apache Full                ALLOW       Anywhere
993                        ALLOW       Anywhere
995                        ALLOW       Anywhere
587                        ALLOW       Anywhere
OpenSSH                    ALLOW       Anywhere
Dovecot POP3               ALLOW       Anywhere
Dovecot Secure IMAP        ALLOW       Anywhere
Dovecot Secure POP3        ALLOW       Anywhere
Postfix                    ALLOW       Anywhere
Postfix SMTPS              ALLOW       Anywhere
Postfix Submission         ALLOW       Anywhere
Apache Full (v6)           ALLOW       Anywhere (v6)
993 (v6)                   ALLOW       Anywhere (v6)
995 (v6)                   ALLOW       Anywhere (v6)
587 (v6)                   ALLOW       Anywhere (v6)
OpenSSH (v6)               ALLOW       Anywhere (v6)
Dovecot POP3 (v6)          ALLOW       Anywhere (v6)
Dovecot Secure IMAP (v6)   ALLOW       Anywhere (v6)
Dovecot Secure POP3 (v6)   ALLOW       Anywhere (v6)
Postfix (v6)               ALLOW       Anywhere (v6)
Postfix SMTPS (v6)         ALLOW       Anywhere (v6)
Postfix Submission (v6)    ALLOW       Anywhere (v6)

这是防火墙问题吗?似乎我只能从本地主机连接,而不能从远程连接。

提前致谢。

附言:如果您需要更多信息,我很乐意与您分享。但我不知道你们到底需要哪些信息来解决这个问题。

编辑:我的 SMTP 服务器也不起作用。我用这个测试了它(https://www.wormly.com/test-smtp-server) 工具。

输出:

Resolving hostname...
Connecting...
Connection: opening to mail.domain.com:25, timeout=300, options=array (
                 )
Connection: opened
SERVER -> CLIENT: 220 mail.domain.com ESMTP Postfix (Ubuntu)
CLIENT -> SERVER: EHLO tools.wormly.com
SERVER -> CLIENT: 250-mail.domain.com
                 250-PIPELINING
                 250-SIZE 10240000
                 250-VRFY
                 250-ETRN
                 250-STARTTLS
                 250-ENHANCEDSTATUSCODES
                 250-8BITMIME
                 250 DSN
CLIENT -> SERVER: STARTTLS
SERVER -> CLIENT: 454 4.7.0 TLS not available due to local problem
SMTP ERROR: STARTTLS command failed: 454 4.7.0 TLS not available due to local problem
2018-07-07 17:06:08 SMTP Error: Could not connect to SMTP host.
CLIENT -> SERVER: QUIT
SERVER -> CLIENT: 221 2.0.0 Bye
Connection: closed
2018-07-07 17:06:08 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Message sending failed.

答案1

基本上你imap_open()一个IMAP 流到邮箱,不要对其进行任何操作,并且将其打开,无需imap_close()。由于没有任何内容可打印,但脚本尚未完成,因此空白页保持加载状态预期的mail.log。你大概可以通过显示连接来确认这一点。之后imap_open(),尝试例如示例 #2 中的这个:

$folders = imap_listmailbox($mbox, "{imap.example.org:143}", "*");

if ($folders == false) {
    echo "Call failed<br />\n";
} else {
    foreach ($folders as $val) {
        echo $val . "<br />\n";
    }
}

imap_close($mbox);
?>

此外,上次测试的 SMTP 连接打开后会关闭STARTTLS。这肯定不是防火墙,而是Postfix TLS配置问题。

相关内容