ubuntu - crontab 使用msmtp 发送邮件失败

标签 ubuntu cron msmtp

我想在 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)

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

最佳答案

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

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

然后我修改了 /etc/aliasesdefault: myemail 让所有邮件都发送到 myemail,它起作用了。

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

关于ubuntu - crontab 使用msmtp 发送邮件失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21808408/

相关文章:

php - FFMPEG (2.5.7) 来自 PHP 的进度条

node.js - 引用错误 : listen is not defined in NodeJS

linux - 通过电子邮件正文中的日志获取 cronjob 脚本执行的日志

Python crontab 不工作

php - linux msmtp 配置从 shell 发送但从 PHP/apache 失败

linux - Yum 没有安装 msmtp

c - 从 libssh2 获取 undefined reference

java - 为什么在 Linux 中,JButton、JLabel 鼠标点击丢失或被忽略?它没有按照程序应该做的去做

PostgreSQL:为每一行运行查询并将结果保存在其中

linux - 如何使用 beaglebone black 发送电子邮件更新?