Last active
January 14, 2020 03:15
-
-
Save Porrapat/75c1934cb10ad4dcc42526ad9d2af9d3 to your computer and use it in GitHub Desktop.
This file contains 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
# How to use | |
# Make sure you install curl. By running curl -v to test it. | |
# Provide your Gmail username and password and who you need to send email to. | |
# For password it is not your Gmail password but it is App passwords https://support.google.com/mail/answer/185833. Please go to your Gmail account setting and create it. | |
# chmod -R 777 send-email-gmail-thai.com | |
# ./send-email-gmail-thai.com | |
# Your Gmail username (email) (Required) | |
SENDER_GMAIL_USERNAME= | |
# Your App password (Required) | |
SENDER_GMAIL_PASSWORD= | |
# Email you want to send to (Required) | |
SEND_TO= | |
# Name of you want to send to (Optional) | |
SEND_TO_NAME= | |
# Create temporary email_temp.html for use it to store email html format and some information. | |
# It's use internet message format as descript in RFC5322 https://tools.ietf.org/html/rfc5322 | |
echo "To: $SEND_TO_NAME <$SEND_TO>" >> email_temp.html | |
echo "Subject: ทดสอบ ส่งเมล์เข้าตัวเองหน่อยด้วย Shell Script and Curl" >> email_temp.html | |
echo "Content-Type: text/html; charset=\"utf8\"" >> email_temp.html | |
# Add Some HTML5 Template Here | |
cat << EOF | cat >> email_temp.html | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<title>หัวข้ออีเมล</title> | |
<style> | |
.button { | |
background-color: #4CAF50; /* Green */ | |
border: none; | |
color: white; | |
padding: 15px 32px; | |
text-align: center; | |
text-decoration: none; | |
display: inline-block; | |
font-size: 16px; | |
margin: 4px 2px; | |
cursor: pointer; | |
} | |
</style> | |
</head> | |
<body> | |
<h2>สวัสดีครับ</h2> | |
<p>คุณสามารถใส่รูปภาพได้</p> | |
<!-- ต้องเป็นภาพที่อยู่บน internet เท่านั้น --> | |
<img src="https://i.pinimg.com/originals/70/20/b8/7020b8116f833bce825852899b205de4.jpg" /> | |
<p>หรือสามารถใส่ปุ่มหรือ CSS ได้แบบนี้</p> | |
<a href="https://gist.github.com/Porrapat" class="button" _target="_blank">ติดต่อผม</a> | |
</body> | |
</html> | |
EOF | |
curl --mail-from "$SEND_TO" --mail-rcpt "$SEND_TO" --ssl -u "$SENDER_GMAIL_USERNAME:$SENDER_GMAIL_PASSWORD" -T "email_temp.html" -k --anyauth smtps://smtp.gmail.com:465 | |
# Clean Up email_temp.html | |
rm email_temp.html |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment