0

Install a simple SMTP client:

sudo apt install msmtp  msmtp-mda

Set in msmtprc ::

cat   .msmtprc
account default
host smtp.qq.com
from [email protected]
auth on
tls on
tls_certcheck off
user [email protected]
password  xxxx
logfile ~/.msmtp.log

I can send email with qq account.

echo "Testing msmtp " | mail -s "hi root" -r [email protected]   -- [email protected]

The email can be found in yahoo email.
I find a new issue that user can't send email to root in system!

echo "cron task work done " | mail -s "hi root" root
mail: cannot send message: Process exited with a non-zero status

Check the log:

Aug 24 20:47:31 host=smtp.qq.com tls=on auth=on [email protected] [email protected] [email protected] smtpstatus=501 smtpmsg='501 Mail from address must be same as authorization user.' errormsg='envelope from address [email protected] not accepted by the server' exitcode=EX_DATAERR

echo "cron task work done " | mail -s "hi root" -r [email protected]  root

The log info:

Aug 29 06:56:39 host=smtp.qq.com tls=on auth=on [email protected] [email protected] [email protected] smtpstatus=501 smtpmsg='501 Mail from address must be same as authorization user.' errormsg='envelope from address [email protected] not accepted by the server' exitcode=EX_DATAERR

Everytime mail command was called ,it relay to external host smtp.qq.com enven if i specify return host as [email protected],how can make mail command send email between user and root in the system? I find that postfix or exim4 will be removed when to install msmtp-mda,the fact maybe realted with my issue.

1
  • msmtp is written specially for the purpose of routing all your mail to an external "smart host" that sends it further. In short, msmtp == no local mail. If you want to have both local mail and use an external smart host, you must install a full MTA like Postfix and configure it appropriately.
    – raj
    Commented Aug 30, 2023 at 15:41

1 Answer 1

1
+100

You've installed a simple forwarding mail server (msmtp). Here is the package description from Debian

Package: msmtp (1.8.23-1)

light SMTP client with support for server profiles

msmtp is an SMTP client that can be used to send mails from Mutt and probably other MUAs (mail user agents). It forwards mails to an SMTP server (for example at a free mail provider), which takes care of the final delivery. Using profiles, it can be easily configured to use different SMTP servers with different configurations, which makes it ideal for mobile clients.

The relevant point here is that it, "forwards mails to an SMTP server […] which takes care of the final delivery".

What this means that using msmtp you can only forward emails to your remote mail server; you cannot deliver locally. If you want to do that install Exim, Postfix, Sendmail, or one of the other full-featured MTAs (mail transport agents).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .