Skip to content

Instantly share code, notes, and snippets.

@starx
Last active March 20, 2021 06:09
Show Gist options
  • Save starx/e7801de23ee58861dea205175ec1276b to your computer and use it in GitHub Desktop.
Save starx/e7801de23ee58861dea205175ec1276b to your computer and use it in GitHub Desktop.
Send mail using gmail and curl
email_file=$(tempfile)
# Compose message
echo "From: Earthlings <people@earth.com>" >> $email_file
echo "To: Martians <people@mars.com>" >> $email_file
echo "Subject: Helloooo world" >> $email_file
echo "Content-Type: text/plain; charset=\"utf8\"" >> $email_file
echo >> $email_file
echo "Hi! :)" >> $email_file
# Send the email
curl \
--url 'smtps://smtp.gmail.com:465' \
--ssl-reqd \
--mail-from 'people@earth.com' \
--mail-rcpt 'people@mars.com' \
--upload-file $email_file \
--user 'people@earth.com:supersecretpassword'
# Cleanup
rm -f $email_file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment