连接到 smtp.gmail:连接被拒绝

连接到 smtp.gmail:连接被拒绝

我正在尝试通过 Ubuntu 14.04 版本向我的 gmail ID 发送邮件。Ubuntu 通过我的 Windows 机器上的 VMware 运行。如果上述描述不清楚,请告诉我,因为我是虚拟机新手。我首先安装了 VMware Workstation 12 Player。然后下载了 ubuntu-14.04.4-desktop-amd64.iso 并为其创建了一个虚拟机。

我正在尝试运行以下命令: echo "This is the body of the email" | mail -s "This is the subject line" myemailID

没有错误提示。我已经在Ubuntu上执行了以下实用程序:

sudo apt-get install mailutils
sudo apt-get install postfix mailutils libsasl2-2 ca-certificates libsasl2-modules
sudo dpkg-reconfigure postfix

我已选择“Internet 站点”作为邮件配置,其余设置均为默认设置。我通过执行“tail -f /var/log/mail.log”检查了 mail.log 文件,以下是消息:

Mar 22 16:34:00 ubuntu postfix/qmgr[2743]: 257891057F0: from=<>, size=474, nrcpt=1 (queue active)
Mar 22 16:34:00 ubuntu postfix/smtp[2755]: connect to smtp.gmail.com[74.125.70.109]:587: Connection refused
Mar 22 16:34:00 ubuntu postfix/smtp[2755]: connect to smtp.gmail.com[74.125.70.108]:587: Connection refused
Mar 22 16:34:00 ubuntu postfix/smtp[2755]: 257891057F0: to=<myemailid>, relay=none, delay=0.07, delays=0/0/0.06/0, dsn=4.4.1, status=deferred (connect to smtp.gmail.com[74.125.70.108]:587: Connection refused)
Mar 22 16:34:00 ubuntu postfix/pickup[2744]: 3DE6F10580A: uid=1000 from=<>
Mar 22 16:34:00 ubuntu postfix/cleanup[2753]: 3DE6F10580A: message-id=<20160322110400.3DE6F10580A@ubuntu>
Mar 22 16:34:00 ubuntu postfix/qmgr[2743]: 3DE6F10580A: from=<>, size=476, nrcpt=1 (queue active)
Mar 22 16:34:00 ubuntu postfix/smtp[2755]: connect to smtp.gmail.com[74.125.70.108]:587: Connection refused
Mar 22 16:34:00 ubuntu postfix/smtp[2755]: connect to smtp.gmail.com[74.125.70.109]:587: Connection refused
Mar 22 16:34:00 ubuntu postfix/smtp[2755]: 3DE6F10580A: to=<myemailid>, relay=none, delay=0.05, delays=0/0/0.05/0, dsn=4.4.1, status=deferred (connect to smtp.gmail.com[74.125.70.109]:587: Connection refused)

请指导并告知我是否需要任何其他信息。

/etc/postfix/main.cf下面还提到了文件以供参考。

smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
biff = no

append_dot_mydomain = no

readme_directory = no


smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
smtpd_use_tls=yes
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache

smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
myhostname = ubuntu
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
mydestination = ubuntu, localhost.localdomain, localhost
relayhost = [smtp.gmail.com]:587
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_tls_CAfile = /etc/postfix/cacert.pem
smtp_use_tls = yes
smtp_tls_policy_maps = hash:/etc/postfix/tls_policy
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
inet_protocols = ipv4
mynetworks = 127.0.0.0/8
mailbox_command = procmail -a "$EXTENSION"

答案1

我已经模拟了防火墙问题

# host smtp.gmail.com
smtp.gmail.com is an alias for gmail-smtp-msa.l.google.com.
gmail-smtp-msa.l.google.com has address 74.125.136.109
gmail-smtp-msa.l.google.com has address 74.125.136.108
gmail-smtp-msa.l.google.com has IPv6 address 2a00:1450:4013:c01::6d

# iptables -I OUTPUT -d 74.125.136.108 -j DROP
# iptables -I OUTPUT -d 74.125.136.109 -j DROP

检查连接

# openssl s_client -connect smtp.gmail.com:587 -starttls smtp
socket: Network is unreachable
connect:errno=101

这些行意味着您网络上的某个人正在阻止与端口 587 上的 smtp.gmail.com 的连接。您可以尝试另一个 smtp 服务器:smtp-mail.outlook.com:25、smtp.mail.yahoo.com:587、smtp.mail.ru:2525

# openssl s_client -connect smtp.mail.yahoo.com:587 -starttls smtp
CONNECTED(00000003)
depth=3 C = US, O = "VeriSign, Inc.", OU = Class 3 Public Primary Certification Authority
verify return:1
depth=2 C = US, O = "VeriSign, Inc.", OU = VeriSign Trust Network, OU = "(c) 2006 VeriSign, Inc. - For authorized use only", CN = VeriSign Class 3 Public Primary Certification Authority - G5
verify return:1
depth=1 C = US, O = Symantec Corporation, OU = Symantec Trust Network, CN = Symantec Class 3 Secure Server CA - G4
verify return:1
depth=0 C = US, ST = California, L = Sunnyvale, O = Yahoo Inc., OU = Information Technology, CN = smtp.mail.yahoo.com
verify return:1
...
---
250 STARTTLS
quit
221 2.0.0 Bye
closed

顺便问一下,您尝试过 465 端口吗?

# openssl s_client -connect smtp.gmail.com:465

相关内容