You are not logged in.

#1 2013-02-11 11:52:00

fdservices
Member
From: France
Registered: 2012-02-06
Posts: 413

Problem with mail and msmtp [SOLVED]

I thought I would get system mail sent to my isp mail account, so I set up msmtp with all my details and sent a few emails from the command line to check that it was working OK.

No problems so far.

I installed msmtp-mta to get the sendmail links, and created an aliases file in /etc to alia root to my email account.

root:  myself@myaddress

but all the emails are still sent to root instead of myself@myaddress, which generates a failuer notice from my ISP.

I notice that if a send mail with the -P option I have a line "aliases   =   (not set)" which seems to be a clue

Can some kind person tell me what I have done wrong?

Thanks

Andrew

Last edited by fdservices (2013-02-12 11:38:55)

Offline

#2 2013-02-11 13:17:02

the sad clown
Member
From: 192.168.0.X
Registered: 2011-03-20
Posts: 837

Re: Problem with mail and msmtp [SOLVED]

Is there a configuration file you could redact and post?


I laugh, yet the joke is on me

Offline

#3 2013-02-11 13:38:37

fdservices
Member
From: France
Registered: 2012-02-06
Posts: 413

Re: Problem with mail and msmtp [SOLVED]

Sure:

#Accounts will inherit settings from this section
defaults
auth             login
tls              off
logfile		 ~/msmtp.log

# First address
account        account_name
host           smtp.mydomain.co.uk
port           25025
from           user@mydomain.co.uk
user           user@mydomain.co.uk
password       mypassword

# Default Account
account default : account_name

Offline

#4 2013-02-12 01:05:33

dif
Member
From: Stalowa Wola, Poland
Registered: 2009-12-22
Posts: 146

Re: Problem with mail and msmtp [SOLVED]

@fdservices
I don't understand the "alias" thing.
I assume that you listed the .msmtprc file in your user home directory. Its permissions are set to 600:

chmod 600 ~/.msmtprc

If you want to send e-mail during the boot time or shutdown, you will be the root user then. In order to use /home/$USER/.msmtprc you should do something like that

/usr/bin/sudo -u USER /home/USER/path/to/your/script/sendmessage.sh

Replace the USER with your user name.
And in the "sendmessage.sh" script you can prepare the message you want to be sent and send it.
For example

/bin/echo TEXT | /usr/bin/mail -s SUBJECT you@your.domain.uk

The TEXT could be another $script, contents of a text file, or just a simple text.

Perhaps it is much too complocated and can be made very easy, but it's what I wrote to replace my rc.local and rc.shutdown scripts when I began to use pure systemd. It sends me the current IP address and informs me when the machine is turned down. In my case e-mail is sent by a service, but you can use a different mechanism to trigger sending a message.

Offline

#5 2013-02-12 07:52:45

fdservices
Member
From: France
Registered: 2012-02-06
Posts: 413

Re: Problem with mail and msmtp [SOLVED]

No, I put the configuration in /etc/msmtprc which means that it will be used by every user unless a .msmtprc file exists in the users home directory, in which case the contents of that file will override the /etc file. Also, that part works fine and I get the emails sent with one problem. If the email is sent by mailx to the root mailbox when a process has encountered an error, I receive a failure notice because the email goes to root and my mail server at the ISP does not know how to forward the email to that address. This is what the aliases file is supposed to deal with.

I put "root:  myself@myaddress" into the /etc/aliases file which, according to the instructions, should mean that instead of sending the messages to root they will be sent to the alias "myself@myaddress". This is the bit that doesn't work at the moment.

Thanks for the reply

Andrew

Offline

#6 2013-02-12 08:29:14

fdservices
Member
From: France
Registered: 2012-02-06
Posts: 413

Re: Problem with mail and msmtp [SOLVED]

I think I have found the answer. I added the line

aliases        /etc/aliases

to the default section of the msmtprc file and now if a send mail with the -P option I have a line "aliases   =  /etc/aliases" in the output

I will let it run for a while to see if it is OK now and let you know.

Andrew

Offline

#7 2013-02-12 11:11:20

dif
Member
From: Stalowa Wola, Poland
Registered: 2009-12-22
Posts: 146

Re: Problem with mail and msmtp [SOLVED]

Thank you for the tip. It may come in handy one day.
I never gave it much thought, but I ddn't put my e-mail password into /etc/msmtprc in case it was read by another user. Unless the /etc/msmtprc file permissions have to be 600.

Offline

#8 2013-02-12 11:26:36

fdservices
Member
From: France
Registered: 2012-02-06
Posts: 413

Re: Problem with mail and msmtp [SOLVED]

According to the documentation msmptrc accepts passwords in the form

passwordeval gpg -d ~/.msmtp.password.gpg

The aliases parameter worked so I am marking this as solved

Andrew

Offline

Board footer

Powered by FluxBB