Install
apt-get install ssmtp
Configure
vi /etc/ssmtp/ssmtp.conf
# # Config file for sSMTP sendmail # # The person who gets all mail for userids < 1000 # Make this empty to disable rewriting. root=xxx@yahoo.com # The place where the mail goes. The actual machine name is required no # MX records are consulted. Commonly mailhosts are named mail.domain.com mailhub=smtp.mail.yahoo.com:465 AuthUser=xxx@yahoo.com AuthPass=xxx UseTLS=YES UseSTARTTLS=NO # Where will the mail seem to come from? #rewriteDomain= # The full hostname hostname=deepthought # 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
Test
echo "This is a test" | sendmail xxx@yahoo.com
Configure an App Password on Yahoo
You may need to generate an app password on Yahoo in order to send email.
From the Yahoo Mail UI, click your Name and then click on Account Info.
From here, select Account Security and click on Manage App Passwords.
Use the generated password in your email settings.
Configure Cron Jobs
Because cron uses a minimal shell, we need to update it's path.
crontab -e
Set the path for cron and MAILTO at the beginning of the file.
Setting a MAILTO="" will disable cron from sending emails for jobs which generate output.
PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin MAILTO=""
If you want to get cronjob emails, set MAILTO in the crontab:
crontab -e
Set the path for cron and MAILTO at the beginning of the file.
PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin MAILTO="xxx@yahoo.com"
You will also need to replace the symlink for sendmail with a script.
rm /usr/sbin/sendmail
vi /usr/sbin/sendmail
#!/bin/sh ARGS=$@ sed -r -e 's/^From: root \(Cron Daemon\)\s*$/From: Cron Daemon <xxx@yahoo.com>/' | /usr/sbin/ssmtp $@
chmod +x /usr/sbin/sendmail
References
Reference | URL |
---|---|
sSMTP | |
sSMTP tips & tricks | https://www.axllent.org/docs/ssmtp/ |
Setup Sendmail | https://kifarunix.com/configure-sendmail-to-use-gmail-relay-on-ubuntu-18-04-debian-10-9/ |