Relay email to gmail (msmtp, mailx, sendmail: Difference between revisions
No edit summary |
(use cmd, cat, path template) |
||
Line 3: | Line 3: | ||
== Install msmtp == | == Install msmtp == | ||
{{Cmd|# apk add msmtp}} | |||
== Configuration == | == Configuration == | ||
Create a global configuration | Create a global configuration: | ||
{{Cat|/etc/msmtprc|# Set default values for all following accounts. | |||
# Set default values for all following accounts. | |||
defaults | defaults | ||
auth on | auth on | ||
Line 29: | Line 26: | ||
account default : gmail | account default : gmail | ||
aliases /etc/aliases | 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 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 | {{note|Please note the aliases {{Path|/etc/aliases}}, this will help for mail/sendmail to redirect email to local user (like root) to an external email }} | ||
== Sendmail alias == | == 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. | 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. | ||
{{Cat|/etc/local.d/msmtp-sendmail.start|#!/bin/sh | |||
#!/bin/sh | |||
ln -sf /usr/bin/msmtp /usr/bin/sendmail | ln -sf /usr/bin/msmtp /usr/bin/sendmail | ||
ln -sf /usr/bin/msmtp /usr/sbin/sendmail | ln -sf /usr/bin/msmtp /usr/sbin/sendmail | ||
}} | |||
Make it executable | Make it executable | ||
{{Cmd|# chmod +x /etc/local.d/msmtp-sendmail.start}} | |||
and run it first time through | and run it first time through | ||
{{Cmd|# /etc/local.d/msmtp-sendmail.start}} | |||
== Mailx and aliases == | == Mailx and aliases == | ||
Install mailx for program that uses mail (like apcupsd for monitoring UPS events) | Install mailx for program that uses mail (like apcupsd for monitoring UPS events) | ||
{{Cmd|# apk add mailx}} | |||
Create an | Create an {{Path|/etc/aliases}} file with content: | ||
{{Cat|/etc/aliases|root: <your external email where all email to root will be sent> | |||
root: <your external email where all email to root will be sent> | |||
default: <default email> | default: <default email> | ||
}} | |||
== Testing == | == Testing == | ||
Test an email, run | Test an email, run | ||
{{Cmd|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 | {{note|'''root''' only work if you've setup {{Path|/etc/aliases}}, otherwise put any email adress you can check instead of 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 == | == Saving the configuration == | ||
{{Expand|This does't apply to a static install.}} | |||
{{Cmd|# lbu ci}} | |||
Hope it helps. | Hope it helps. |
Latest revision as of 13:48, 25 August 2023
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
# apk add msmtp
Configuration
Create a global configuration:
Contents of /etc/msmtprc
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.
Contents of /etc/local.d/msmtp-sendmail.start
Make it executable
# chmod +x /etc/local.d/msmtp-sendmail.start
and run it first time through
# /etc/local.d/msmtp-sendmail.start
Mailx and aliases
Install mailx for program that uses mail (like apcupsd for monitoring UPS events)
# apk add mailx
Create an /etc/aliases file with content:
Contents of /etc/aliases
Testing
Test an email, run
echo -e "Subject: Do you love alpine?\nYes, I do!\n"
Saving the configuration
This material needs expanding ... This does't apply to a static install. |
# lbu ci
Hope it helps.