-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPOSTFIX_GMAIL.sh
More file actions
44 lines (35 loc) · 1.2 KB
/
POSTFIX_GMAIL.sh
File metadata and controls
44 lines (35 loc) · 1.2 KB
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
#!/bin/bash
[ $EUID -ne 0 ] && {
echo "run script as root" >&2
exit 1
}
echo -e "NOTICE:\nThis will work only for gmail"; sleep .5
echo -e "updating ..."
apt-get update &> /dev/null
echo "installing reuqired softwares ..."
apt-get install postfix mailutils -y > /dev/null
echo "time to give me your credentials"
read -p 'username: ' username
read -p 'password: ' password
if [ -z "$username" ] || [ -z "$password" ];then
echo "ERROR, username or password is empty" >&2
elif ! grep -q "@gmail.com$" <<< "$username"; then
echo "ERROR, username doesn't end with @gmail.com" >&2
exit 1
else
echo "[smtp.gmail.com]:587 ${username}:${password}" > /etc/postfix/sasl_passwd
chmod 600 /etc/postfix/sasl_passwd
fi
echo "configuring postfix ..."
cat << CONFIG >> /etc/postfix/main.cf
relayhost = [smtp.gmail.com]:587
smtp_use_tls = yes
smtp_sasl_auth_enable = yes
smtp_sasl_security_options =
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt
CONFIG
postmap /etc/postfix/sasl_passwd
systemctl restart postfix.service
echo "finished. make sure you have enabled less secure apps"
echo "to use mail: echo \"this is test mail\" | mail -s \"TEST\" recipient@domain.com"