3

I want to use msmtp instead of postfix to send mail when crontab get some errors, but I failed.

My OS is ubuntu 12.04

Here is my steps:

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

Then I edit the /etc/msmtprc file to config smtp server:

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

Then I tested the msmtp, and it's 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.

The next step is modified the /etc/aliases

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

And I can use msmtp to send my email.

But in /var/log/cron.log, it got an error:

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

What's wrong ? How to solve the problem ? Could anyone give me a hand?

Feng Yu
  • 1,431
  • 2
  • 18
  • 26

2 Answers2

2

Finally I solved the problem by myself...

Because I write the MAILTO=myemail in the file /etc/crontab,but I add the crons use crontab -e. So the var MAILTO doesn't works. It also send the mail to root not myemail, it can't reach the address so msmtp get an error.

Then I modified the /etc/aliases with default: myemail to let all mail send to myemail, and it works.

Then I get another issue, I find the mail content will not display any utf-8 characters, but the title can. What's the matter? How to solve this problem ?

Feng Yu
  • 1,431
  • 2
  • 18
  • 26
1

I had a very similar scenario as described in the question, however the current answer didn't fix the problem for me. In my case, the explanation of the problem was that every time when cron executed sendmail command it was setting $HOME to /, rather than /home/<user>. Thus even if msmtp replaced sendmail via a symlink it was not able to find its user-specific config file located in $HOME/.msmtprc.

My SOLUTION was to use /etc/msmtprc instead of $HOME/.msmtprc.

This may not be the best solution for your system, as it may force some sensitive data from your /etc/msmtprc to be readable by other users.

Read more here: http://comments.gmane.org/gmane.linux.debian.devel.bugs.general/671011

sd1074
  • 21
  • 3