aboutsummaryrefslogtreecommitdiffhomepage
path: root/snippets/use_curl_send_mail
diff options
context:
space:
mode:
authorHsieh Chin Fan <pham@topo.tw>2024-06-28 01:24:13 +0800
committerHsieh Chin Fan <pham@topo.tw>2024-06-28 01:24:13 +0800
commit3526eb6d756e3c37190814eca2e22ce9f7d9f1de (patch)
treef334c6ef0a4b77c40980eee7a5fdf07899405069 /snippets/use_curl_send_mail
parente58f70b411ae935fcd32f00d9e3983381fdc0294 (diff)
Update
Diffstat (limited to 'snippets/use_curl_send_mail')
-rw-r--r--snippets/use_curl_send_mail38
1 files changed, 38 insertions, 0 deletions
diff --git a/snippets/use_curl_send_mail b/snippets/use_curl_send_mail
new file mode 100644
index 0000000..70eeb7c
--- /dev/null
+++ b/snippets/use_curl_send_mail
@@ -0,0 +1,38 @@
1#! /usr/bin/env bash
2
3# User input
4sender=typebrook@gmail.com
5receiver=typebrook@gmail.com
6gapp=$(pass google/imap_for_typebrook)
7sub="$(date) test mail from curl"
8body="$(echo -e 'just\na\ntest\nmail')"
9
10# check for provided attachment file as a positional parameter
11# -z indicating an empty positional parameter
12# attachment doesn't exist condition
13if [ -z "$1" ]; then
14
15 # curl command for accessing the smtp server
16
17 curl -s --url 'smtps://smtp.gmail.com:465' --ssl-reqd \
18 --mail-from $sender \
19 --mail-rcpt $receiver --user $sender:$gapp \
20 -T <(echo -e "From: ${sender}
21To: ${receiver}
22Subject: ${sub}
23
24 ${body}")
25
26# attachment exists condition
27else
28 file="$1" # set file as the 1st positional parameter
29
30 # MIME type for multiple type of input file extensions
31 MIMEType=$(file --mime-type "$file" | sed 's/.*: //')
32 curl -s --url 'smtps://smtp.gmail.com:465' --ssl-reqd \
33 --mail-from $sender \
34 --mail-rcpt $receiver --user $sender:$gapp \
35 -H "Subject: $sub" -H "From: $sender" -H "To: $receiver" -F \
36 '=(;type=multipart/mixed' -F "=$body;type=text/plain" -F \
37 "file=@$file;type=$MIMEType;encoder=base64" -F '=)'
38fi