0

Some important service:

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

[email protected]:

[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. Commented Jul 26, 2021 at 5:22
  • That's right, I found the problem. In /etc/ssmtp/revaliases I left wrong ports... root:[email protected]:smtp.gmail.com:587 mainuser:[email protected]:smtp.gmail.com:587. Changed them to 465 and it's all working now. Commented Jul 26, 2021 at 10:48

1 Answer 1

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.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.