<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.alpinelinux.org/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Ahilborne</id>
	<title>Alpine Linux - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.alpinelinux.org/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Ahilborne"/>
	<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/wiki/Special:Contributions/Ahilborne"/>
	<updated>2026-05-09T23:20:21Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.40.0</generator>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Relay_email_to_gmail_(msmtp,_mailx,_sendmail&amp;diff=15340</id>
		<title>Relay email to gmail (msmtp, mailx, sendmail</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Relay_email_to_gmail_(msmtp,_mailx,_sendmail&amp;diff=15340"/>
		<updated>2018-07-13T12:14:53Z</updated>

		<summary type="html">&lt;p&gt;Ahilborne: If doing this without a restart, we have to explicitly link msmtp to sendmail&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Overview ==&lt;br /&gt;
If you&#039;re running an alpine from stick and need a way for your program to alert you through a standard gmail account&lt;br /&gt;
&lt;br /&gt;
== Install msmtp ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apk add msmtp&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Configuration ==&lt;br /&gt;
Create a global configuration, &amp;quot;/etc/msmtprc&amp;quot; with content&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Set default values for all following accounts.&lt;br /&gt;
defaults&lt;br /&gt;
auth           on&lt;br /&gt;
tls            on&lt;br /&gt;
tls_trust_file /etc/ssl/certs/ca-certificates.crt&lt;br /&gt;
syslog         on&lt;br /&gt;
&lt;br /&gt;
# Gmail&lt;br /&gt;
account        gmail&lt;br /&gt;
host           smtp.gmail.com&lt;br /&gt;
port           587&lt;br /&gt;
from           &amp;lt;your email&amp;gt;&lt;br /&gt;
user           &amp;lt;your gmail account&amp;gt;&lt;br /&gt;
password       &amp;lt;your password&amp;gt;&lt;br /&gt;
&lt;br /&gt;
# Set a default account&lt;br /&gt;
account default : gmail&lt;br /&gt;
aliases        /etc/aliases&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
{{note|Please note I&#039;ve used the &#039;&#039;&#039;syslog on&#039;&#039;&#039; to send msmtp log to syslog, yet you can use the &#039;&#039;&#039;logfile    &amp;lt;log_file_path&amp;gt;&#039;&#039;&#039; if you prefer to log to a file }}&lt;br /&gt;
{{note|Please note the aliases &#039;&#039;&#039;/etc/aliases&#039;&#039;&#039;, this will help for mail/sendmail to redirect email to local user (like root) to an external email }}&lt;br /&gt;
&lt;br /&gt;
== Sendmail alias ==&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Create a file &amp;quot;/etc/local.d/msmtp-sendmail.start&amp;quot; with below content:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
ln -sf /usr/bin/msmtp /usr/sbin/sendmail&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make it executable&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo chmod +x /etc/local.d/msmtp-sendmail.start&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and run it first time through&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo /etc/local.d/msmtp-sendmail.start&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Mailx and aliases ==&lt;br /&gt;
Install mailx for program that uses mail (like apcupsd for monitoring UPS events)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apk add mailx&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create an &amp;quot;/etc/aliases&amp;quot; file with content:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root: &amp;lt;your external email where all email to root will be sent&amp;gt;&lt;br /&gt;
&lt;br /&gt;
default: &amp;lt;default email&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Testing ==&lt;br /&gt;
Test an email, run&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
echo -e &amp;quot;Subject: Do you love alpine?\nYes, I do!\n&amp;quot; | msmtp root&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
{{note|&#039;&#039;&#039;root&#039;&#039;&#039; only work if you&#039;ve setup /etc/aliases, otherwise put any email adress you can check instead of root}}&lt;br /&gt;
&lt;br /&gt;
== Saving the configuration ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo lbu ci&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Hope it helps.&lt;br /&gt;
&lt;br /&gt;
[[Category:Monitoring]]&lt;br /&gt;
[[Category:Mail]]&lt;/div&gt;</summary>
		<author><name>Ahilborne</name></author>
	</entry>
</feed>