Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

Mail command use with msmtp + msmtp-mta doesn't work

Linux Kernel, Network, and Services configuration.
Post Reply
Message
Author
josely
Posts: 3
Joined: 2021-04-02 15:10

Mail command use with msmtp + msmtp-mta doesn't work

#1 Post by josely »

I'm setting up a very small GNUsocial instance (friends only) on an old PC with Debian10.
I want it to send notifications email via an external mail provider (like gmail, etc), because the domain is dynamic and thus blocked by other email services.


I can successfully send emails with the msmtp command directly.
If I understood well, msmtp-mta should enable to use the mail command to send mails through msmtp?

However, the mail command returns an error (with mailutils installed):

Code: Select all

echo "Test" | mail personal@external.email
returns

Code: Select all

mail: cannot send message: Process exited with a non-zero status
and

Code: Select all

echo $? 
returns "36"

Without mailutils, the mail command isn't found.

I have followed the instructions on https://wiki.debian.org/msmtp, and also tried to manually start the service , it seems to start but no success in using the mail command, which appears to be what GNUSocial uses.

Any idea how to fix this or an alternative outbound mail system set up?

Much appreciated.

Dai_trying
Posts: 1100
Joined: 2016-01-07 12:25
Has thanked: 5 times
Been thanked: 16 times

Re: Mail command use with msmtp + msmtp-mta doesn't work

#2 Post by Dai_trying »

I have a script that sends emails (via gmail) as required using "sendemail", there are two caveats though

1. when using gmail you must first enable "less secure apps" in google settings.

2. the password is in plain text inside your scripts.

if those don't put you off you can use it something like the below example, note that the time in the message body is taken from a command but you could just as easily insert $variables too.

Code: Select all

sendemail -f <your-email@gmail.com> -t <recipient-email@wherever.com> -u "This is the title" -m "This is the message body.\n The time now is $(date '+%D @ %T')" -s smtp.gmail.com:587 -o tls=yes -xu <your-email@gmail.com> -xp <your password>

josely
Posts: 3
Joined: 2021-04-02 15:10

Re: Mail command use with msmtp + msmtp-mta doesn't work

#3 Post by josely »

Thanks @Dai_trying

The msmtp command works great for me to send messages *manually*:

Code: Select all

cat message.txt | msmtp  --account default  --read-recipients
Where message.txt includes contains From, To, Subject and email message.

The issue is with the GNU Social instance automated email (notifications etc) as GNU Social would be calling the mail command.

Dai_trying
Posts: 1100
Joined: 2016-01-07 12:25
Has thanked: 5 times
Been thanked: 16 times

Re: Mail command use with msmtp + msmtp-mta doesn't work

#4 Post by Dai_trying »

You are welcome, I was just offering an alternative as I don't use your method to send mails, hopefully someone with more/better understanding will be along to offer something.

reinob
Posts: 1189
Joined: 2014-06-30 11:42
Has thanked: 97 times
Been thanked: 47 times

Re: Mail command use with msmtp + msmtp-mta doesn't work

#5 Post by reinob »

FWIW if you don't want to install postfix (which would solve the issue rather elegantly), you can install nullmailer, which provides a suitable /usr/sbin/sendmail, and the configuration is really simple.

Otherwise, if you insist on using msmtp-mta, then there must be a log somewhere, which would tell you where the error/problem is.

josely
Posts: 3
Joined: 2021-04-02 15:10

Re: Mail command use with msmtp + msmtp-mta doesn't work

#6 Post by josely »

reinob wrote:FWIW if you don't want to install postfix (which would solve the issue rather elegantly), you can install nullmailer, which provides a suitable /usr/sbin/sendmail, and the configuration is really simple.

Otherwise, if you insist on using msmtp-mta, then there must be a log somewhere, which would tell you where the error/problem is.
Thanks for popping in. Yes POSTFIX would probably work it. msmtp-mta already does the work with sendmail.

The issue was with mail command

In the meanwhile, found the answer here
https://moritzvd.com/email-with-smtp-debian-ubuntu/

In order to be able to use the mail command wee need to install mailx

Code: Select all

sudo apt-get install bsd-mailx
Set mail transport agent to use msmtp

Code: Select all

sudo nano /etc/mail.rc
append the following:

Code: Select all

set mta=/usr/bin/msmtp

Post Reply