无法使用 mailx 发送邮件

无法使用 mailx 发送邮件

有人能帮助解决这个错误吗?:

mailx -s "test message" [email protected] Cc: This is a test message
cannot send message: Process exited with a non-zero status

当我尝试从命令行使用 mailx 时出现此问题。

答案1

我给你的最佳建议是实际使用,s-nail这比 Ubuntu 下可用的各种版本等要省事得多mailx / bsd-mailx / heirloom-mailx。特别是s-nail可以发送直接地到外部 SMTP 服务器(例如 Gmail)没有Postfix 等应用程序增加了复杂性。

s-nail可以按如下方式安装:

sudo apt-get install s-nail

然后您需要创建一个配置文件并适当地设置权限:

touch ~/.mailrc
chmod 0600 ~/.mailrc

使用您喜欢的文本编辑器打开此文件,并将以下信息粘贴到其中。请注意我主要用“xxxxx”标记的部分,您需要在其中添加自己的详细信息(通常是用户名和密码):

#--------------------------------------------#
# Setting mailx version v14.9.15 for gmail   #
#--------------------------------------------#

# Testing syntax:
# echo "Testing, Testing, Testing" | s-nail -s "My test..." [email protected]

# Use v15.0 compatibility mode
set v15-compat

# See the whole process, especially for troubleshooting:
set verbose

# Essential setting: select allowed character sets
set sendcharsets=utf-8,iso-8859-1
# and reply in the same charset used by sender:
set reply-in-same-charset

# Default directory where we act in (relative to $HOME)
set folder=mail

# My actual address obfuscated here:
set from="[email protected]"

# Request strict TLL transport layer security checks
set tls-verify=strict
set tls-ca-file=/etc/ssl/certs/ca-certificates.crt
set tls-ca-no-defaults
set smtp-use-starttls
set smtp-auth=login

# When sending messages, wait until the Mail-Transfer-Agent finishes.
# Only like this you will be able to see errors reported through the
# exit status of the MTA (including the built-in SMTP one)!
set sendwait

# And of course put your own gmail username and
# App Password here in the obvious places:

set mta=smtps://username:[email protected]:465
#--------------------------------------------#

我已经在我的 Ubuntu 20.04 系统上进行了设置,并且运行正常完美无瑕请参见下文,我已运行建议的测试电子邮件(请注意,我混淆了测试电子邮件地址):

$ echo "Testing, Testing, Testing" | s-nail -s "My test..." [email protected]
s-nail: P(seudo)R(andom)N(umber)G(enerator): *TLS RAND_*
s-nail: Resolving host smtp.gmail.com:465 ... done
s-nail: Connecting to 74.125.130.108:465 ...  connected.
s-nail:  Certificate depth 2 
s-nail:   subject = /OU=GlobalSign Root CA - R2/O=GlobalSign/CN=GlobalSign
s-nail:   notBefore = Dec 15 08:00:00 2006 GMT
s-nail:   notAfter = Dec 15 08:00:00 2021 GMT
s-nail:   issuer = /OU=GlobalSign Root CA - R2/O=GlobalSign/CN=GlobalSign
s-nail:  Certificate depth 1 
s-nail:   subject = /C=US/O=Google Trust Services/CN=GTS CA 1O1
s-nail:   notBefore = Jun 15 00:00:42 2017 GMT
s-nail:   notAfter = Dec 15 00:00:42 2021 GMT
s-nail:   issuer = /OU=GlobalSign Root CA - R2/O=GlobalSign/CN=GlobalSign
s-nail:  Certificate depth 0 
s-nail:   subject = /C=US/ST=California/L=Mountain View/O=Google LLC/CN=smtp.gmail.com
s-nail:   notBefore = Nov  3 07:37:59 2020 GMT
s-nail:   notAfter = Jan 26 07:37:59 2021 GMT
s-nail:   issuer = /C=US/O=Google Trust Services/CN=GTS CA 1O1
s-nail: Comparing subject_alt_name: need<smtp.gmail.com> is<smtp.gmail.com>
s-nail: TLS certificate ok
s-nail: TLS BLAKE2s256 fingerprint: 0C:F8:DA:33:CE:15:EA:7F:F6:8B:28:C1:95:33:A0:1D:01:B7:F3:D8:E2:7B:29:42:70:D6:4B:6A:6D:16:8A:CF
s-nail: TLS connection using TLSv1.3 / TLS_AES_256_GCM_SHA384

希望这也能在你的 Ubuntu 20.04 系统上运行!

笔记

  1. 应用程序密码:现在你需要使用 Google 创建应用密码,以便 s-nail 成功访问 Gmail:https://support.google.com/accounts/answer/185833
  2. 符号链接:大多数 Linux 发行版实际上会将 s-nail 符号链接到 mailx,因此命令mailx会调用,s-nail但在 Ubuntu 20.04 下似乎并非如此。毫无疑问,这可以手动完成。

相关内容