aboutsummaryrefslogtreecommitdiffhomepage
path: root/snippets/use_openssl_send_mail
diff options
context:
space:
mode:
Diffstat (limited to 'snippets/use_openssl_send_mail')
-rw-r--r--snippets/use_openssl_send_mail36
1 files changed, 36 insertions, 0 deletions
diff --git a/snippets/use_openssl_send_mail b/snippets/use_openssl_send_mail
new file mode 100644
index 0000000..fabaca3
--- /dev/null
+++ b/snippets/use_openssl_send_mail
@@ -0,0 +1,36 @@
1#!/bin/bash
2
3# ref: https://stackoverflow.com/questions/9998710/is-it-possible-to-send-mails-by-bash-script-via-smtp
4# Use "host -t mx host" to find out mail server
5
6set -e
7
8MAIL_SERVER=smtp.gmail.com
9PORT=465
10MAIL_FROM=typebrook@gmail.com
11RCPT_TO=typebrook@gmail.com
12
13send_message_line_by_line() {
14 while read line; do
15 echo $line >/dev/tty
16 echo $line
17 sleep 1
18 done | openssl s_client -connect $MAIL_SERVER:$PORT -crlf
19}
20
21# 1. openssl do RENEGOTIATING when input starts with R, so use "rcpt to:" instead of "RCPT TO:"
22# 2. End mail with an empty line, and followed by '.' and 'QUIT'
23cat <<MAILEND | send_message_line_by_line
24HELO $MAIL_SERVER
25AUTH LOGIN
26$(echo $MAIL_FROM | base64)
27$(pass google/imap_for_typebrook | base64)
28MAIL FROM: <$MAIL_FROM>
29rcpt to: <$RCPT_TO>
30DATA
31Subject: $(date) test mail from bash
32Another test mail
33
34.
35QUIT
36MAILEND