Last active
August 29, 2015 14:22
-
-
Save Smenus/68f73fb402d9d7d2c25f to your computer and use it in GitHub Desktop.
msmtp Setup (Debian Jessie)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
These are files I needed in order to get msmtp running inside my initramfs on Debian Jessie. | |
I encountered quite a few pitfalls while trying to get this set up, so I wanted to save them here for posterity. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
PREREQ="dropbear" | |
prereqs() { | |
echo "$PREREQ" | |
} | |
case "$1" in | |
prereqs) | |
prereqs | |
exit 0 | |
;; | |
esac | |
. "${CONFDIR}/initramfs.conf" | |
. /usr/share/initramfs-tools/hook-functions | |
# Install msmtp if explicitly enabled, or in case of a dropbear setup if not | |
# explicitly disabled | |
if [ "${MSMTP}" = "y" ] || ( [ "${MSMTP}" != "n" ] && [ -x "${DESTDIR}/sbin/dropbear" ] ); then | |
if [ ! -x "/usr/bin/msmtp" ]; then | |
if [ "${MSMTP}" = "y" ]; then | |
echo "msmtp: FAILURE: msmtp not found!" | |
else | |
echo "msmtp: WARNING: msmtp not found, you won't be notified via mail when system is booting up!" | |
fi | |
else | |
# Remove old binary, copy new one | |
rm -f "${DESTDIR}/bin/msmtp" | |
copy_exec "/usr/bin/msmtp" "/bin/" | |
# Remove old configuration, copy new one | |
rm -f "${DESTDIR}/root/.msmtprc" | |
cp /etc/initramfs-tools/root/.msmtprc "${DESTDIR}/root/" | |
# Copy resolv.conf, for DNS lookups | |
cp /etc/resolv.conf "${DESTDIR}/etc/" | |
# Copy libraries needed for DNS lookups | |
cp /lib/x86_64-linux-gnu/libnss_dns.so.2 "${DESTDIR}/lib/x86_64-linux-gnu/" | |
cp /lib/x86_64-linux-gnu/libnss_files.so.2 "${DESTDIR}/lib/x86_64-linux-gnu/" | |
cp /lib/x86_64-linux-gnu/libresolv.so.2 "${DESTDIR}/lib/x86_64-linux-gnu/" | |
# Copy certificates | |
mkdir -p "${DESTDIR}/etc/ssl/certs/" | |
cp /etc/ssl/certs/ca-certificates.crt "${DESTDIR}/etc/ssl/certs/" | |
fi | |
fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defaults | |
tls on | |
tls_starttls on | |
tls_trust_file /etc/ssl/certs/ca-certificates.crt | |
account gmail.com | |
host smtp.gmail.com | |
port 587 | |
auth on | |
user <email> | |
password <password> | |
from <email> | |
syslog off | |
logfile |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
PREREQ="dropbear udev devpts" | |
prereqs() { | |
echo "$PREREQ" | |
} | |
case "$1" in | |
prereqs) | |
prereqs | |
exit 0 | |
;; | |
esac | |
. /scripts/functions | |
[ -x /bin/msmtp ] || exit 0 | |
log_begin_msg "Sending mail" | |
. /conf/initramfs.conf | |
configure_networking | |
echo -e "Subject: Server '<server>' has rebooted\nServer '<server>' has rebooted, and is awaiting unlocking before it can continue booting." | /bin/msmtp --file=/root/.msmtprc --account gmail.com -- <destemail> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment