diff options
Diffstat (limited to 'snippets/use_openssl_send_mail')
-rw-r--r-- | snippets/use_openssl_send_mail | 36 |
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 | |||
6 | set -e | ||
7 | |||
8 | MAIL_SERVER=smtp.gmail.com | ||
9 | PORT=465 | ||
10 | MAIL_FROM=typebrook@gmail.com | ||
11 | RCPT_TO=typebrook@gmail.com | ||
12 | |||
13 | send_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' | ||
23 | cat <<MAILEND | send_message_line_by_line | ||
24 | HELO $MAIL_SERVER | ||
25 | AUTH LOGIN | ||
26 | $(echo $MAIL_FROM | base64) | ||
27 | $(pass google/imap_for_typebrook | base64) | ||
28 | MAIL FROM: <$MAIL_FROM> | ||
29 | rcpt to: <$RCPT_TO> | ||
30 | DATA | ||
31 | Subject: $(date) test mail from bash | ||
32 | Another test mail | ||
33 | |||
34 | . | ||
35 | QUIT | ||
36 | MAILEND | ||