Skip to content

Instantly share code, notes, and snippets.

@OdysseasKr
Created July 4, 2023 10:30
Show Gist options
  • Save OdysseasKr/74fdf4cf2cf47776184fb03fff99ca0d to your computer and use it in GitHub Desktop.
Save OdysseasKr/74fdf4cf2cf47776184fb03fff99ca0d to your computer and use it in GitHub Desktop.
A simple script that sends emails from bash using CURL
#!/bin/bash
# Change these details accordingly
SMTP_HOST='smtps://smtp.gmail.com:465'
SENDER_EMAIL='[email protected]'
SENDER_PASSWORD='yourpassword'
RECEIVER_EMAIL='[email protected]'
# Generate body of email in a file
echo "From: $SENDER_EMAIL" > emailbody
echo "To: $RECEIVER_EMAIL" >> emailbody
echo "Subject: This is an example subject" >> emailbody
echo "Date: $(date)" >> emailbody
echo "Hello world" >> emailbody
# Send email. You can change the url according tou your host
curl --url $SMTP_HOST --ssl-reqd \
--mail-from $SENDER_EMAIL \
--user "$SENDER_EMAIL:$SENDER_PASSWORD" \
-T emailbody \
--mail-rcpt $RECEIVER_EMAIL
# You can add more receivers by repeating the --mail-rcpt argument
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment