当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,它是正常的
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)出什么事了?如何解决这个问题?有人能帮我一下吗?
发布于 2014-02-16 19:40:27
最后我自己解决了这个问题……
因为我在文件/etc/crontab中编写了MAILTO=myemail,但是我使用crontab -e添加了cron。所以var MAILTO不起作用。它还将邮件发送到root而不是myemail,因为它无法到达该地址,所以msmtp会收到一个错误。
然后,我用default: myemail修改了/etc/aliases,让所有邮件都发送到我的电子邮件中,并且它起作用了。
然后我遇到了另一个问题,我发现邮件内容不会显示任何utf-8字符,但标题可以。你怎么了?如何解决这个问题?
发布于 2016-01-14 07:03:09
我有一个与问题中描述的非常相似的场景,但是目前的答案并没有为我解决这个问题。在我的例子中,对这个问题的解释是,每当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
https://stackoverflow.com/questions/21808408
复制相似问题