-
Notifications
You must be signed in to change notification settings - Fork 0
/
mail.bash
53 lines (36 loc) · 1.36 KB
/
mail.bash
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/bash
# User input
sender=kolikamlesh12799@gmail.com
read -p "Enter your official jsr email ID : " receiver
gapp=owovdkefutgbfwgn
read -p "Enter the subject of mail : " sub
echo "Enter the body of mail : "
cat > tempfile.txt # using cat command for multiline input
body=$(cat tempfile.txt) # storing the content of file in a variable
rm tempfile.txt
# check for provided attachment file as a positional parameter
# -z indicating an empty positional parameter
# attachment doesn't exist condition
if [ -z "$1" ]; then
# curl command for accessing the smtp server
curl -s --url 'smtps://smtp.gmail.com:465' --ssl-reqd \
--mail-from $sender \
--mail-rcpt $receiver\
--user $sender:$gapp \
-T <(echo -e "From: ${sender}
To: ${receiver}
Subject:${sub}
${body}")
# attachment exists condition
else
file="$1" # set file as the 1st positional parameter
# MIME type for multiple type of input file extensions
MIMEType=`file --mime-type "$file" | sed 's/.*: //'`
curl -s --url 'smtps://smtp.gmail.com:465' --ssl-reqd \
--mail-from $sender \
--mail-rcpt $receiver\
--user $sender:$gapp \
-H "Subject: $sub" -H "From: $sender" -H "To: $receiver" -F \
'=(;type=multipart/mixed' -F "=$body;type=text/plain" -F \
"file=@$file;type=$MIMEType;encoder=base64" -F '=)'
fi