0

This used to work, but does so no longer?

NOW=$(date +%m-%d-%Y_%I:%M%p)
CONTENT="Backup to Maxtor Drive performed on $NOW ."
echo "Sending email."
/usr/sbin/ssmtp -t << EOF
To: 7@yahoo.com
From: 7@yahoo.com
Subject: Backups to Maxtor Drive 

$CONTENT

EOF

I reinstalled ssmtp and I get

  ssmtp: Cannot open mail:25

ssmtp.conf

# The full hostname
hostname=7

# Are users allowed to set their own From: address?
# YES - Allow the user to specify their own From: address
# NO - Use the system generated From: address
#FromLineOverride=YES

root=7@yahoo.com
mailhub=smtp.mail.yahoo.com:587
AuthUser=7
AuthPass=***
UseSTARTTLS=YES

revaliases

# sSMTP aliases
# 
# Format:   local_account:outgoing_address:mailhub
#
# Example: root:your_login@your.domain:mailhub.your.domain[:port]
# where [:port] is an optional port number that defaults to 25.
7@yahoo.com:smtp.mail.yahoo.com:587
fixit7
  • 2,776
  • 3
  • 30
  • 70
  • Have you looked at https://askubuntu.com/q/531526/295286 and https://unix.stackexchange.com/q/135009/85039 ? Try running `strace -o script_trace.txt -f ./myscript.sh` (replace `myscript.sh` with actual script name that you're using), and maybe provide the output of `script_trace.txt` file here or on paste.ubuntu.com – Sergiy Kolodyazhnyy Feb 05 '19 at 23:24
  • script_trace.txt is here. https://paste.ubuntu.com/p/r9qgk3TYv9/ – fixit7 Feb 06 '19 at 01:11
  • I can see from the output that you have permission denied error on `/etc/ssmtp/revaliases` and `/etc/ssmtp/ssmtp.conf` and both of these errors come from `ssmtp` process with PID 2726. Can you provide output of `ls -l` on each of those files ? Does the script work if you run it with `sudo` ? – Sergiy Kolodyazhnyy Feb 06 '19 at 01:36
  • @Sergiy Kolodyazhnyy -rw-r----- 1 root mail 255 Feb 5 19:16 revaliases -rw-r----- 1 root mail 698 Feb 5 19:06 ssmtp.conf Script does not run with sudo. – fixit7 Feb 06 '19 at 01:51
  • OK, in that case it seems it is not permissions issue, but something else. I see there's another error related to missing socket for `nscd`. We might want to try something with that. However, first try adding `-v` to `ssmtp` command to show verbose output, maybe it will shed some extra light. – Sergiy Kolodyazhnyy Feb 06 '19 at 02:15
  • There's also indication that `ssmtp` writes to `/dev/log`. Look at the output of `journalctl` and what error messages might be there from `ssmtp` – Sergiy Kolodyazhnyy Feb 06 '19 at 02:17
  • In journalctl. Feb 05 20:33:37 7 sSMTP[4250]: Unable to connect to "smtp.mail.yahoo.com" port 587. Feb 05 20:33:37 7 sSMTP[4250]: Cannot open smtp.mail.yahoo.com:587 – fixit7 Feb 06 '19 at 02:37
  • 1
    OK, let's try this: `echo "nameserver 8.8.8.8" | sudo tee /etc/resolv.conf` and then run the script again. What this does is temporarily should add google's public dns server to `/etc/resolv.conf` (you can use something else if you like also, 208.67.220.220 for OpenDNS or Cloudflare's 1.0.0.1). In your `strace` output I see that before error message occurs it tries to query your local DNS server, so it might be related to the issue. Hopefully it works. Otherwise, I'll leave the question here for now and come back to it tomorrow with maybe a better solution – Sergiy Kolodyazhnyy Feb 06 '19 at 02:46
  • Let us [continue this discussion in chat](https://chat.stackexchange.com/rooms/89316/discussion-between-fixit7-and-sergiy-kolodyazhnyy). – fixit7 Feb 06 '19 at 03:31
  • @Sergiy Kolodyazhnyy Have you thought of anything else I can try? – fixit7 Feb 06 '19 at 23:52
  • 1
    No, not yet. I'll let you know if anything comes up – Sergiy Kolodyazhnyy Feb 06 '19 at 23:52
  • Quick question, does `apt-cache policy nscd` report `Installed: (none)` in your case ? Do you recall by chance if you used to have it installed ? – Sergiy Kolodyazhnyy Feb 09 '19 at 02:00
  • Also see this one: https://unix.stackexchange.com/a/328573/85039 – Sergiy Kolodyazhnyy Feb 09 '19 at 02:36
  • I am still suspicious of the config file permissions and access. The error reports port 25, which is the default, however you have port 587 in the config file, so your config file is in fact not accessible. – Sergiy Kolodyazhnyy Feb 09 '19 at 02:42
  • andy@7_~/Downloads/$ apt-cache policy nscd nscd: Installed: (none) Candidate: 2.27-3ubuntu1 Version table: 2.27-3ubuntu1 500 500 http://us.archive.ubuntu.com/ubuntu bionic/un I do not recalled if I ever had it installed. – fixit7 Feb 09 '19 at 02:45
  • Changing port to 25 made no difference. – fixit7 Feb 09 '19 at 02:55
  • No, that's not what I meant. The issue isn't the port. The issue, I think, are config files. – Sergiy Kolodyazhnyy Feb 09 '19 at 02:57
  • Maybe something here you can use. http://nekhbet.com/ssmtp_yahoo.shtml – fixit7 Feb 09 '19 at 03:00

1 Answers1

0

Permissions to user may not given.I tried $sudo chmod ug+rwx /etc/ssmtp/ssmtp.conf and do the same for revaliases.It worked!