msmtp hangs instead of delivering the message
I'm trying to configure msmtp
(on Ubuntu 12.04). When I'm trying to send an email, it "hangs" (well, ctrl-c aborts it, so it's not really a hang, but it seems not to do anything anyway). Here's my .msmtprc
(here and further the password and all addresses are correct, of course):
account wmi
host smtp.wmi.amu.edu.pl
port 465
auth on
user mbork
password ***
from from@address
account default : wmi
When I invoke cat mailtest.txt | msmtp -v to@address
, I get this:
ignoring system configuration file /etc/msmtprc: Nie ma takiego pliku ani katalogu
loaded user configuration file /home/marcin/.msmtprc
falling back to default account
using account default from /home/marcin/.msmtprc
host = smtp.wmi.amu.edu.pl
port = 465
timeout = off
protocol = smtp
domain = localhost
auth = choose
user = mbork
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)
auto_from = off
maildomain = (not set)
from = from@address
dsn_notify = (not set)
dsn_return = (not set)
keepbcc = off
logfile = (not set)
syslog = (not set)
aliases = (not set)
reading recipients from the command line
and nothing happens.
(The file mailtest.txt
looks like this:
To: to@address
From: from@address
Subject: A test
msmtp testing
)
What might cause this problem?
Solution 1:
In my case this problem was caused because msmtp enables StartTLS by default. When StartTLS is enabled, msmtp will connect to the server and wait for the server to send data (the SMTP welcome message). If the server does not support StartTLS and expects the connection to be encrypted with SSL from the beginning, it will not send data and will wait for the client to set the SSL connection up.
So you can try setting tls_starttls off
in the defaults
section of ~/.msmtprc
. Also check that the port is correct.
(To troubleshoot this problem, I verified with strace msmtp
that when msmtp was hanging it was connecting to the right server on the right port and waiting to receive data, whereas using openssl s_client
on the same server and port seemed to work.)
Solution 2:
OK, problem solved. msmtp
version 1.4.26 seems to be broken; after installing v1.4.30 it started to work.
Solution 3:
Beware! "reading recipients from the command line" is the last informational message from msmtp before it tries to connect to the server. If it hangs at that point, it means it can't connect. Nothing to do with the command line so don't do what I did and go off on wild goose chases. You could try connecting with telnet (e.g. telnet mail.example.com 587) to see if the server responds. If not, double check its url and port. Or, in my case, fail2ban on the server had banned me after some failed login attempts due to a wrong user name. Simple answer in that case is to wait several hours for the ban to expire.