1

Some important service:

[Unit]
...
OnFailure=status-email@%n.service

status-email@.service:

[Unit]
Description=status email for %i to user

[Service]
Type=oneshot
ExecStart=/usr/local/bin/systemd-email.sh <recipient> %i
User=root
Group=systemd-journal

[Install]
WantedBy=multi-user.target

I'm getting error systemd-email.sh[117310]: ssmtp: Cannot open smtp.gmail.com:587

I can send mail manually ./systemd-email.sh $RECIPIENT $SERVICE_NAME

It's also working as cronjob.

My /etc/ssmtp/ssmtp.conf:

root=<gmail address>
mailhub=smtp.gmail.com:465
FromLineOverride=YES
AuthUser=<gmail address>
AuthPass=<password>
UseTLS=YES

Why cron can send mail in this setup but systemd cannot?

2
  • 1
    You posted two items: systemd-email.sh[117310]: ssmtp: Cannot open smtp.gmail.com:587 and later, mailhub=smtp.gmail.com:465. Something is mis-configured in the first case to use port 587 instead of the correct port 465.
    – C. M.
    Jul 26 at 5:22
  • That's right, I found the problem. In /etc/ssmtp/revaliases I left wrong ports... root:username@gmail.com:smtp.gmail.com:587 mainuser:username@gmail.com:smtp.gmail.com:587. Changed them to 465 and it's all working now.
    – Catnip
    Jul 26 at 10:48
0

Per the comments, the problem was an incorrectly configured port number somewhere else. Please consider deleting this question, as the main thing it brings to the community and the site/network is "Why you should do a detailed search/research, troubleshooting, and/or diagnostics to exhaust all avenues of resolving the issue on your own."

The only thing I would add to help other/future users is application of various template files and configuration files (setting an environment variable to the correct value, then using it in other files) to ensure a single change propagates to all sub-ordinate configuration files.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.