Relay email to gmail (msmtp, mailx, sendmail: Difference between revisions
Benoitm974 (talk | contribs) No edit summary |
Benoitm974 (talk | contribs) No edit summary |
||
Line 1: | Line 1: | ||
== Overview == | |||
If you're running an alpine from stick and need a way for your program to alert you through a standard gmail account | If you're running an alpine from stick and need a way for your program to alert you through a standard gmail account | ||
Line 8: | Line 8: | ||
== Configuration == | == Configuration == | ||
Create a global configuration, "/etc/msmtprc" with content | |||
<pre> | <pre> | ||
Line 42: | Line 42: | ||
</pre> | </pre> | ||
Make it executable | |||
<pre> | <pre> | ||
sudo chmod +x /etc/local.d/msmtp-sendmail.start | sudo chmod +x /etc/local.d/msmtp-sendmail.start | ||
Line 48: | Line 48: | ||
== Mailx and aliases == | == Mailx and aliases == | ||
Install mailx for program that uses mail (like apcupsd for monitoring UPS events) | |||
<pre> | <pre> | ||
sudo apk add mailx | sudo apk add mailx | ||
</pre> | </pre> | ||
Create an "/etc/aliases" file with content: | |||
<pre> | <pre> | ||
root: <your external email where all email to root will be sent> | root: <your external email where all email to root will be sent> | ||
Line 61: | Line 61: | ||
== Testing == | == Testing == | ||
Test an email, run | |||
<pre> | <pre> | ||
echo -e "Subject: Do you love alpine?\nYes, I do!\n" | msmtp root | echo -e "Subject: Do you love alpine?\nYes, I do!\n" | msmtp root |
Revision as of 21:42, 3 June 2017
Overview
If you're running an alpine from stick and need a way for your program to alert you through a standard gmail account
Install msmtp
sudo apk add msmtp
Configuration
Create a global configuration, "/etc/msmtprc" with content
# Set default values for all following accounts. defaults auth on tls on tls_trust_file /etc/ssl/certs/ca-certificates.crt syslog on # Gmail account gmail host smtp.gmail.com port 587 from <your email> user <your gmail account> password <your password> # Set a default account account default : gmail aliases /etc/aliases
Note: Please note I've used the syslog on to send msmtp log to syslog, yet you can use the logfile <log_file_path> if you prefer to log to a file
Note: Please note the aliases /etc/aliases, this will help for mail/sendmail to redirect email to local user (like root) to an external email
Sendmail alias
By default alpine comes with busybox sendmail, msmtp can act as a sendmail alternative including syntax and option, there I create a local.d script to overwrite the busybox link to msmtp.
Create a file "/etc/local.d/msmtp-sendmail.start" with below content:
#!/bin/sh ln -sf /usr/bin/msmtp /usr/sbin/sendmail
Make it executable
sudo chmod +x /etc/local.d/msmtp-sendmail.start
Mailx and aliases
Install mailx for program that uses mail (like apcupsd for monitoring UPS events)
sudo apk add mailx
Create an "/etc/aliases" file with content:
root: <your external email where all email to root will be sent> default: <default email>
Testing
Test an email, run
echo -e "Subject: Do you love alpine?\nYes, I do!\n" | msmtp root
Note: root only work if you've setup /etc/aliases, otherwise put any email adress you can check instead of root
Saving the configuration
sudo lbu ci
Hope it helps.