3

当 crontab 出现一些错误时,我想使用 msmtp 而不是 postfix 发送邮件,但我失败了。

我的操作系统是 ubuntu 12.04

这是我的步骤:

apt-get install msmtp-mta  #This will auto install msmtp, and symlink /usr/sbin/sendmail
apt-get install mailutils

然后我编辑/etc/msmtprc文件以配置 smtp 服务器:

defaults
tls off

account default
host smtp.ym.163.com
auth login
from myuser@mydomain.com
user myuser@mydomain.com
password mypss
logfile /var/log/msmtp.log
aliases /etc/aliases

然后我测试了msmtp,就OK了

msmtp -Sd

loaded system configuration file /etc/msmtprc
ignoring user configuration file /root/.msmtprc: no such file or directory
falling back to default account
using account default from /etc/msmtprc
host                  = smtp.ym.163.com
port                  = 25
timeout               = off
protocol              = smtp
domain                = localhost
auth                  = LOGIN
user                  = myuser@mydomain
password              = *
passwordeval          = (not set)
ntlmdomain            = (not set)
tls                   = off
tls_starttls          = on
tls_trust_file        = (not set)
tls_crl_file          = (not set)
tls_fingerprint       = (not set)
tls_key_file          = (not set)
tls_cert_file         = (not set)
tls_certcheck         = on
tls_force_sslv3       = off
tls_min_dh_prime_bits = (not set)
tls_priorities        = (not set)
<-- 220 m199-177.yeah.net ESMTP HMail (1.0)
--> EHLO localhost
<-- 250-m199-177.yeah.net
<-- 250-PIPELINING
<-- 250-SIZE 71680000
<-- 250-ETRN
<-- 250-STARTTLS
<-- 250-AUTH LOGIN PLAIN
<-- 250-AUTH=LOGIN PLAIN
<-- 250-ENHANCEDSTATUSCODES
<-- 250 8BITMIME
--> QUIT
<-- 221 2.0.0 Bye
SMTP server at smtp.ym.163.com (m199-177.yeah.net [123.58.177.199]), port 25:
    m199-177.yeah.net ESMTP HMail (1.0)
Capabilities:
    SIZE 71680000:
        Maximum message size is 71680000 bytes = 68.36 MiB
    PIPELINING:
        Support for command grouping for faster transmission
    ETRN:
        Support for RMQS (Remote Message Queue Starting)
    STARTTLS:
        Support for TLS encryption via the STARTTLS command
    AUTH:
        Supported authentication methods:
        PLAIN LOGIN 
This server might advertise more or other capabilities when TLS is active.

下一步是修改/etc/aliases

# See man 5 aliases for format
postmaster:    root
root: myuser@mydomain.com
default: myuser@mydomain.com

我可以使用 msmtp 发送我的电子邮件。

但在 中/var/log/cron.log,出现错误:

(root) MAIL (mailed 1 byte of output; but got status 0x004e, #012)

怎么了 ?如何解决问题?谁能帮我一把?

4

2 回答 2

2

最后我自己解决了这个问题......

因为我MAILTO=myemail在文件中写了/etc/crontab,但是我添加了 crons 使用crontab -e。所以 varMAILTO不起作用。它还将邮件发送到rootnot myemail,它无法到达该地址,因此 msmtp 出现错误。

然后我修改了/etc/aliaseswithdefault: myemail让所有邮件都发送到 myemail,它可以工作。

然后我得到另一个问题,我发现邮件内容不会显示任何 utf-8 字符,但标题可以。怎么了?如何解决这个问题呢 ?

于 2014-02-16T11:40:27.013 回答
1

我有一个与问题中描述的非常相似的场景,但是当前的答案并没有为我解决问题。就我而言,问题的解释是每次cron执行sendmail命令时它都设置$HOME/,而不是/home/<user>. 因此,即使通过符号链接msmtp替换sendmail它也无法找到位于$HOME/.msmtprc.

我的解决方案是使用/etc/msmtprc而不是$HOME/.msmtprc.

这可能不是您系统的最佳解决方案,因为它可能会强制/etc/msmtprc其他用户读取您的某些敏感数据。

在这里阅读更多:http: //comments.gmane.org/gmane.linux.debian.devel.bugs.general/671011

于 2016-01-13T23:03:09.040 回答