Skip to content

Instantly share code, notes, and snippets.

@EricTendian
Created February 17, 2020 22:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EricTendian/464a44a5874f985654d79609fd4885f8 to your computer and use it in GitHub Desktop.
Save EricTendian/464a44a5874f985654d79609fd4885f8 to your computer and use it in GitHub Desktop.
Sending an HTML email with curl over SMTP
#!/bin/bash
cat << EOF > email.eml
From: "${MAIL_FROM_NAME}" <${MAIL_FROM_ADDRESS}>
To: "${MAIL_TO_NAME}" <${MAIL_TO_ADDRESS}>
Reply-To: "${MAIL_TO_NAME}" <${MAIL_TO_ADDRESS}>
Subject: ${MAIL_SUBJECT}
Content-Type: text/html; charset="utf-8"
Content-Transfer-Encoding: quoted-printable
EOF
python -m quopri << EOF >> email.eml
<html>
<body>
<p>BODY HERE</p>
</body>
</html>
EOF
curl --ssl-reqd "smtps://${MAIL_HOST}:${MAIL_PORT}" \
--user "${MAIL_USERNAME}:${MAIL_PASSWORD}" \
--mail-from "${MAIL_FROM_ADDRESS}" \
--mail-rcpt "${MAIL_TO_ADDRESS}" \
--upload-file email.eml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment