You are not logged in.

#1 2015-06-14 16:48:27

emacsomancer
Member
Registered: 2014-09-20
Posts: 211

systemd email not working (can't find ssmtp.conf) [solved]

I set up systemd to send email when a unit fails, as described here: https://wiki.archlinux.org/index.php/Sy … ers#MAILTO

But when I run:

systemctl status status-email-user1@dbus.service

I get the error:

status-email-user1@dbus.service - status email for dbus to user1
   Loaded: loaded (/etc/systemd/system/status-email-user1@.service; static; vendor preset: disabled)
   Active: failed (Result: exit-code) since Sun 2015-06-14 10:19:36 MDT; 20min ago
  Process: 31229 ExecStart=/usr/local/bin/systemd-email someone@gmail.com %i (code=exited, status=1/FAILURE)
 Main PID: 31229 (code=exited, status=1/FAILURE)

Jun 14 10:19:36 sindhu systemd[1]: Starting status email for dbus to user1...
Jun 14 10:19:36 sindhu sSMTP[31230]: /etc/ssmtp/ssmtp.conf not found
Jun 14 10:19:36 sindhu sSMTP[31230]: Unable to locate mailhub
Jun 14 10:19:36 sindhu systemd-email[31229]: sendmail: Cannot open mailhub:25
Jun 14 10:19:36 sindhu systemd[1]: status-email-user1@dbus.service: main pro...RE
Jun 14 10:19:36 sindhu systemd[1]: Failed to start status email for dbus to ...1.
Jun 14 10:19:36 sindhu systemd[1]: Unit status-email-user1@dbus.service ente...1.
Jun 14 10:19:36 sindhu systemd[1]: status-email-user1@dbus.service failed.
Hint: Some lines were ellipsized, use -l to show in full.

/etc/ssmtp/ssmtp.conf is in fact present, and configured as suggested in the Arch wiki.

If I run something like:

echo -e "To: me@gmail.com\nFrom: someone@domain.com\nSubject: Hello Notification\n\n Hello, this is a test"|ssmtp me@gmail.com

I receive email as expected.

Last edited by emacsomancer (2015-06-22 00:49:17)

Offline

#2 2015-06-15 23:00:38

emacsomancer
Member
Registered: 2014-09-20
Posts: 211

Re: systemd email not working (can't find ssmtp.conf) [solved]

Likewise, if I run

systemd-email someone@gmail.com dbus

it also works.

So something's off in the status-email-user@.service part.  Following the Arch guide, I have:

[Unit]                                                                                           
Description=status email for %I to user                                                         
                                                                                                 
[Service]                                                                                        
Type=oneshot                                                                                     
ExecStart=/usr/local/bin/systemd-email someone@gmail.com %i                                       
User=nobody                                                                                      
Group=systemd-journal                                                                            

                                                                                               

but this doesn't seem to work.

Offline

#3 2015-06-19 00:02:28

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

Re: systemd email not working (can't find ssmtp.conf) [solved]

Hello,

I did not go all the way checking if service failure notification works as described in wiki, but I did copy your/wiki set-up steps. Similarly to what's on you computer, sending e-mails works correctly on mine, both the commands you mentioned:

echo -e "To: me@gmail.com\nFrom: someone@domain.com\nSubject: Hello Notification\n\n Hello, this is a test"|ssmtp me@gmail.com
systemd-email someone@gmail.com dbus

But when I run

systemctl status status-email-user1@dbus.service

no errors are reported.
So my question is, Do you still have this problem? Or has it been solved?

Offline

#4 2015-06-19 16:04:52

emacsomancer
Member
Registered: 2014-09-20
Posts: 211

Re: systemd email not working (can't find ssmtp.conf) [solved]

dif wrote:

Hello,

I did not go all the way checking if service failure notification works as described in wiki, but I did copy your/wiki set-up steps. Similarly to what's on you computer, sending e-mails works correctly on mine, both the commands you mentioned:

echo -e "To: me@gmail.com\nFrom: someone@domain.com\nSubject: Hello Notification\n\n Hello, this is a test"|ssmtp me@gmail.com
systemd-email someone@gmail.com dbus

But when I run

systemctl status status-email-user1@dbus.service

no errors are reported.
So my question is, Do you still have this problem? Or has it been solved?

I'm still having the exact problem I described.

Before you ran

systemctl status status-email-user1@dbus.service

did you run

systemctl start status-email-user1@dbus.service

?

Offline

#5 2015-06-21 23:39:55

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

Re: systemd email not working (can't find ssmtp.conf) [solved]

I made a test:  I ran a "status" - "start" - "status" sequence, then rebooted and ran a "start" - "status" sequence. Both times successful, no errors reported. Here are the logs from my virtual box, where I made those experiments as user "wm".
The status+start+status log

cze 22 00:41:33 arch login[306]: LOGIN ON tty1 BY wm
cze 22 00:42:34 arch sudo[376]: wm : TTY=tty1 ; PWD=/home/wm ; USER=root ; COMMAND=/usr/bin/systemctl status status-email-user1@dbus.service
cze 22 00:42:34 arch sudo[376]: pam_unix(sudo:session): session opened for user root by wm(uid=0)
cze 22 00:42:38 arch sudo[376]: pam_unix(sudo:session): session closed for user root
cze 22 00:43:34 arch sudo[382]: wm : TTY=tty1 ; PWD=/home/wm ; USER=root ; COMMAND=/usr/bin/systemctl start status-email-user1@dbus.service
cze 22 00:43:34 arch sudo[382]: pam_unix(sudo:session): session opened for user root by wm(uid=0)
cze 22 00:43:34 arch dbus[300]: [system] Activating via systemd: service name='org.freedesktop.PolicyKit1' unit='polkit.service'
cze 22 00:43:34 arch systemd[1]: Starting Authorization Manager...
cze 22 00:43:34 arch polkitd[387]: Started polkitd version 0.113
cze 22 00:43:34 arch polkitd[387]: Loading rules from directory /etc/polkit-1/rules.d
cze 22 00:43:34 arch polkitd[387]: Loading rules from directory /usr/share/polkit-1/rules.d
cze 22 00:43:34 arch polkitd[387]: Finished loading, compiling and executing 1 rules
cze 22 00:43:34 arch dbus[300]: [system] Successfully activated service 'org.freedesktop.PolicyKit1'
cze 22 00:43:34 arch systemd[1]: Started Authorization Manager.
cze 22 00:43:34 arch polkitd[387]: Acquired the name org.freedesktop.PolicyKit1 on the system bus
cze 22 00:43:34 arch polkitd[387]: Registered Authentication Agent for unix-process:383:19398 (system bus name :1.3 [/usr/bin/pkttyagent --notify-fd 5 --fallback], object path /org/freedesktop/PolicyKit1/AuthenticationAgent, locale pl_PL.UTF-8)
cze 22 00:43:34 arch systemd[1]: Created slice system-status\x2demail\x2duser1.slice.
cze 22 00:43:34 arch systemd[1]: Starting system-status\x2demail\x2duser1.slice.
cze 22 00:43:34 arch systemd[1]: Starting status email for dbus to user@gmail.com...
cze 22 00:43:39 arch sSMTP[396]: Creating SSL connection to host
cze 22 00:43:39 arch sSMTP[396]: SSL connection using ECDHE-RSA-AES128-GCM-SHA256
cze 22 00:43:42 arch sSMTP[396]: Sent mail for root@arch (221 2.0.0 closing connection di7sm14260437wib.23 - gsmtp) uid=99 username=nobody outbytes=1312
cze 22 00:43:42 arch polkitd[387]: Unregistered Authentication Agent for unix-process:383:19398 (system bus name :1.3, object path /org/freedesktop/PolicyKit1/AuthenticationAgent, locale pl_PL.UTF-8) (disconnected from bus)
cze 22 00:43:42 arch sudo[382]: pam_unix(sudo:session): session closed for user root
cze 22 00:43:42 arch systemd[1]: Started status email for dbus to user@gmail.com.
cze 22 00:45:15 arch sudo[405]: wm : TTY=tty1 ; PWD=/home/wm ; USER=root ; COMMAND=/usr/bin/systemctl status status-email-user1@dbus.service
cze 22 00:45:15 arch sudo[405]: pam_unix(sudo:session): session opened for user root by wm(uid=0)
cze 22 00:45:15 arch sudo[405]: pam_unix(sudo:session): session closed for user root

and the start+status log

cze 22 00:58:19 arch login[308]: LOGIN ON tty1 BY wm
cze 22 00:59:50 arch sudo[378]: wm : TTY=tty1 ; PWD=/home/wm ; USER=root ; COMMAND=/usr/bin/systemctl start status-email-user1@dbus.service
cze 22 00:59:50 arch sudo[378]: pam_unix(sudo:session): session opened for user root by wm(uid=0)
cze 22 00:59:51 arch dbus[301]: [system] Activating via systemd: service name='org.freedesktop.PolicyKit1' unit='polkit.service'
cze 22 00:59:51 arch systemd[1]: Starting Authorization Manager...
cze 22 00:59:51 arch polkitd[383]: Started polkitd version 0.113
cze 22 00:59:51 arch polkitd[383]: Loading rules from directory /etc/polkit-1/rules.d
cze 22 00:59:51 arch polkitd[383]: Loading rules from directory /usr/share/polkit-1/rules.d
cze 22 00:59:51 arch polkitd[383]: Finished loading, compiling and executing 1 rules
cze 22 00:59:51 arch dbus[301]: [system] Successfully activated service 'org.freedesktop.PolicyKit1'
cze 22 00:59:51 arch systemd[1]: Started Authorization Manager.
cze 22 00:59:51 arch polkitd[383]: Acquired the name org.freedesktop.PolicyKit1 on the system bus
cze 22 00:59:51 arch polkitd[383]: Registered Authentication Agent for unix-process:379:16268 (system bus name :1.3 [/usr/bin/pkttyagent --notify-fd 5 --fallback], object path /org/freedesktop/PolicyKit1/AuthenticationAgent, locale pl_PL.UTF-8)
cze 22 00:59:51 arch systemd[1]: Created slice system-status\x2demail\x2duser1.slice.
cze 22 00:59:51 arch systemd[1]: Starting system-status\x2demail\x2duser1.slice.
cze 22 00:59:51 arch systemd[1]: Starting status email for dbus to user@gmail.com...
cze 22 00:59:57 arch sSMTP[392]: Creating SSL connection to host
cze 22 00:59:59 arch sSMTP[392]: SSL connection using ECDHE-RSA-AES128-GCM-SHA256
cze 22 01:00:01 arch sSMTP[392]: Sent mail for root@arch (221 2.0.0 closing connection f8sm14300037wiy.7 - gsmtp) uid=99 username=nobody outbytes=1312
cze 22 01:00:01 arch systemd[1]: Started status email for dbus to user@gmail.com.
cze 22 01:00:01 arch polkitd[383]: Unregistered Authentication Agent for unix-process:379:16268 (system bus name :1.3, object path /org/freedesktop/PolicyKit1/AuthenticationAgent, locale pl_PL.UTF-8) (disconnected from bus)
cze 22 01:00:01 arch sudo[378]: pam_unix(sudo:session): session closed for user root
cze 22 01:00:24 arch sudo[397]: wm : TTY=tty1 ; PWD=/home/wm ; USER=root ; COMMAND=/usr/bin/systemctl status status-email-user1@dbus.service
cze 22 01:00:24 arch sudo[397]: pam_unix(sudo:session): session opened for user root by wm(uid=0)
cze 22 01:00:24 arch sudo[397]: pam_unix(sudo:session): session closed for user root

If you still have errors I would think that your e-mail config files might be wrong, but your error message is very strange. So maybe something wrong with permissions. I'm afraid I'm just guessing.

To be clear.
Each command

systemctl start status-email-user1@dbus.service

generated an e-mail message.
None of

systemctl status status-email-user1@dbus.service

commands generated any e-mail messages.

Offline

#6 2015-06-22 00:36:42

emacsomancer
Member
Registered: 2014-09-20
Posts: 211

Re: systemd email not working (can't find ssmtp.conf) [solved]

I just figured it out.  I set up ssmtp as described here: https://wiki.archlinux.org/index.php/SSMTP , including the Security section.  Since the systemd/Timers part has user "nobody" sending mail; since I secured /etc/ssmtp/ssmtp.conf as described in the SSMTP Arch wiki, it was inaccessible to "nobody".

Once I added "nobody" to the ssmtp group, it worked!

The question now is what is the best setup?  I assume it's terribly insecure having "nobody" as member of the ssmtp group, as that defeats the purpose of the ssmtp security setup.  Maybe have "root" as the emailer?

Offline

#7 2015-06-22 23:54:02

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

Re: systemd email not working (can't find ssmtp.conf) [solved]

I do not have the "nobody" in the ssmtp group.

$ cat /etc/group |grep ssmtp
ssmtp:x:1000:

where 1000 is my test user "wm".
See the permissions

$ ls -l /etc/ssmtp/ssmtp.conf
-rw-r----- 1 root ssmtp 728 06-19 00:07 /etc/ssmtp/ssmtp.conf

As promised by wiki, I cannot successfully run

$ cat /etc/ssmtp/ssmtp.conf
cat: /etc/ssmtp/ssmtp.conf: Permission denied

Here's an excerpt from my /etc/passwd so that you have a clear view of my setup.

...
nobody:x:99:99:nobody:/:/usr/bin/nologin
wm:x:1000:100::/home/wm:/bin/bash
...

The post is marked as solved, but double check your configs and permissions. And yes, having root as the mailer should be the safest.

Offline

Board footer

Powered by FluxBB