2010-05-04 13:17:09 +0000 2010-05-04 13:17:09 +0000
31
31
Advertisement

mailx发送邮件是使用SMTP中继还是直接连接到目标SMTP服务器?

Advertisement

假设我用下面的命令发送了一封邮件。

mailx person@x.com

那么mailx是先找出我的ISP的SMTP服务器来转发邮件还是直接连接。这要看我的电脑是有公共IP地址还是在NAT后面。如何检查我电脑上mailx的设置?如何用tcpdump验证?

Advertisement
Advertisement

答案 (4)

31
31
31
2010-12-06 16:37:44 +0000

mailx可以使用SMTP。它的配置文件是~/.mailrc

一个例子是【mailx使用Gmail的SMTP】(http://www.systutorials.com/1411/sending-email-from-mailx-command-in-linux-using-gmails-smtp/)。

配置文件甚至可以用一个命令。

mailx -v -s "$EMAIL_SUBJECT" \
-S smtp-use-starttls \
-S ssl-verify=ignore \
-S smtp-auth=login \
-S smtp=smtp://smtp.gmail.com:587 \
-S from="$FROM_EMAIL_ADDRESS($FRIENDLY_NAME)" \
-S smtp-auth-user=$FROM_EMAIL_ADDRESS \
-S smtp-auth-password=$EMAIL_ACCOUNT_PASSWORD \
-S ssl-verify=ignore \
-S nss-config-dir=~/.mozilla/firefox/xxxxxxxx.default/ \
$TO_EMAIL_ADDRESS

如果使用的是普通的SMTP服务器,那就简单多了(请看详细介绍 这里 ):

mailx -v -s "$EMAIL_SUBJECT" \
-S smtp=smtp://smtp.example.com
-S from="$FROM_EMAIL_ADDRESS($FRIENDLY_NAME)" \
$TO_EMAIL_ADDRESS

你也可以把这些放到mailx的配置文件~/.mailrc中。

29
29
29
2010-05-04 16:16:41 +0000

传统上,Unix mail及其衍生工具(以及许多其他Unix工具)使用/usr/bin/sendmail接口,几乎所有的邮件传输代理(MTA–postfix、exim、courier,当然还有sendmail)都会提供这个接口。

也就是说,mail程序不讲任何网络协议–它通过stdin将邮件送入sendmail,让它来处理实际的传送。(这要追溯到一些邮件使用SMTP、一些使用UUCP、一些使用BITNET的时代…)

一旦邮件通过sendmail排队,MTA就会处理实际的邮件传输,无论是通过SMTP还是其他方式。根据配置的不同,它可能会直接连接到目标MTA,或者通过另一台主机(也称为smarthost)中继邮件。

直接连接在服务器上比较常见;通过smarthost中继在家庭连接的个人电脑上比较常见–通过Gmail或ISP/工作邮件账户中继是必不可少的,以避免一概而论的 “动态IP "反垃圾邮件过滤器。

(一些MTA如esmtpnullmailer是专门为家庭用户建立的,并且_总是使用中继主机。这些不支持接收邮件,而且对资源的要求更低。)

mailx → [/usr/bin/sendmail] → local MTA queue → [SMTP] → recipient MTA → recipient inbox
mailx → [/usr/bin/sendmail] → local MTA queue → [SMTP] → Gmail or ISP/work servers → [SMTP] → recipient MTA → recipient inbox
  • *

其他程序,大多是用户友好的图形客户端,如Thunderbird或Outlook,总是直接连接到中继/智能主机SMTP服务器(同样,通常是Gmail或ISP/工作SMTP服务器),由它代你传送邮件。

本机SMTP支持存在于heirloom-mailx中,但不是传统的bsd-mailx

app → [SMTP] → Gmail or ISP/work servers → [SMTP] → recipient MTA → recipient inbox

第三种方法–直接连接到收件人的服务器–几乎**不使用,没有任何MUA支持它。在个人电脑上,使用它会导致你的邮件被拒绝(很多垃圾邮件都是从被感染的家庭用户IP地址发送的)。

app → [SMTP] → recipient MTA → caught by the spam filter
3
Advertisement
3
3
2010-05-04 13:27:27 +0000
Advertisement

mailx(1)man页面,DESCRIPTION部分,字符串选项小节。

smtp Normally, mailx invokes sendmail(8) directly to transfer
          messages. If the smtp variable is set, a SMTP connection
          to the server specified by the value of this variable is
          used instead.
1
1
1
2014-01-27 09:06:23 +0000

有一个没有本地MTA的替代方案,比如sendmail/postix。

debian 包 ssmtp

信息来自 rpm 描述。

Summary : Extremely simple MTA to get mail off the system to a Mailhub
URL : http://packages.debian.org/stable/mail/ssmtp
License : GPLv2+
Description : A secure, effective and simple way of getting mail off a system to your mail
            : hub. It contains no suid-binaries or other dangerous things - no mail spool
            : to poke around in, and no daemons running in the background. Mail is simply
            : forwarded to the configured mailhost. Extremely easy configuration.

hth

Stefan K.

Advertisement

相关问题

6
10
5
37
5
Advertisement