forked from ghumman/lfce
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathemail.txt
More file actions
135 lines (112 loc) · 4.98 KB
/
email.txt
File metadata and controls
135 lines (112 loc) · 4.98 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
Install Postfix(MTA) and Dovecot(Email Server(IMAP/POP3))
sudo apt-get install postfix dovecot-imapd dovecot-pop3d
#########################################################
#Postfix smtp, make sure all clients are able to send emails to server
#########################################################
On server:
sudo apt-get install postfix
(Select Internet site and hostname as mail name)
#listen to all interfaces
sudo postconf -e "inet_interfaces=all"
#enable trusted subnets
sudo postconf -e "mynetworks_style=subnet"
# In order to send mail to remote server use ip address not the hostname otherwise will get DNS MX records error inside /var/log/mail.log
# rcpt to: root@[192.168.33.10]
On client(192.168.33.10):
telnet 192.168.33.1 25
helo localhost
mail from:client1@localhost
rcpt to:root@localhost
data
Subject: Test sent from client1 to server
Tesing 1, 2, 4
.
Test if we get the mail on server.
#mailutils install mail
#mutt shows emails and sends emails, and it installs postfix, if
# it's already not installed
# mail can be used to send mail like following from terminal
# mail -s "How are you?" client1@localhost (This gives DNS MX record error if we use hostname for remote computer)
# mail -s "How are you?" client1@[192.168.33.20] (Using this I was able to send email from one server to another server)
Cc
(Keep writing once you're done, press <Ctrl+D>)
sudo apt-get install mailutils
mail
############################################################
#Enable dovecot as IMAP server
############################################################
At this point without having mutt and dovecott (but having mail and postfix), we can send messages and view messages from the same machine.
But from a remote machine we can still use tellnet to login to server machine and send from emails from one user to another. but won't be able to see email like using this kind of command. "mutt -f client1@192.168.0.106"
# above assumption is wrong, later I figured you can send emails by putting ip address inside [].
sudo apt-get install mutt dovecot-imapd dovecot-pop3d dovecot-core dovecot-lmtpd
sudo vim /etc/dovecot/dovecot.conf
(uncomment this line: listen =*, ::)
sudo systemctl restart dovecot
(Doing this vagrant client with different IP address works for follwoing command but client on same network but on a different machine doesn't work)
mutt -f imap://client1@192.168.0.106/
# It doesn't work on different machine because other machine it's looking for TLS(transport layer security) / SSL (secure socket layer). After enabling it in next step, above command work on remote host
###########################################################
#Enforce TLS/SSL for IMAP server i.e. inside Dovecot
###########################################################
sudo vim /etc/dovecot/conf.d/10-ssl.conf
#Edit
ssl = required
ssl_cert = </etc/dovecot/dovecot.pem
ssl_key = </etc/dovecot/private/dovecot.pem
#generate certificates
cd /usr/share/dovecot
./mkcert.sh
sudo systemctl restart dovecot
#Mutt works but still Thunderbird is not working
##########################################################
#Sending email using SMTP Auth (SASL-Simple Authentication and Security Layer)
##########################################################
sudo postconf -e "mynetworks_style=host"
sudo postconf -e "disable_dns_lookups=yes"
sudo postconf -e "smtpd_tls_auth_only=no"
sudo systemctl restart postfix.service
#enable sasl in dovecot
sudo vim /etc/dovecot/conf.d/10-master.conf
#uncomment following lines inside section "service auth"
unix_listener /var/spool/postfix/private/auth {
mode = 0666
}
#enable sasl in postfix
sudo postconf -e "smtpd_sasl_type = dovecot"
sudo postconf -e "smtpd_sasl_auth_enable = yes"
sudo postconf -e "smtpd_recipient_restrictions = \
permit_mynetworks, \
permit_sasl_authenticated, \
reject_unauth_destination"
postconf -e "smtpd_sasl_path = private/auth"
systemctl restart postfix
#Using telnet after enabling sasl
Copy output of following command
echo -en "\0student\0student" | base64 -> AHN0dWRlbnQAc3R1ZGVudA==
telnet localhost 25
helo localhost
auth plain AHN0dWRlbnQAc3R1ZGVudA==
mail from ...
###########################################################
# Using both SASL and TLS in Postfix (SASL type = dovecot)
###########################################################
postconf -e "smtpd_tls_auth_only = yes"
postconf -e "smtpd_tls_security_level = may"
postconf -e "smtpd_tls_cert_file = /etc/postfix/postfix.pem"
postconf -e "smtpd_tls_key_file = /etc/postfix/postfix.pem"
#creating postfix.pem
/usr/bin/openssl req -utf8 -newkey rsa:2048 -keyout /tmp/postfix.key -nodes \
-x509 -days 365 -out /tmp/postfix.crt -set_serial 0
cat /tmp/postfix.key > /etc/postfix/postfix.pem
echo "" >> /etc/postfix/postfix.pem
cat /tmp/postfix.crt >> /etc/postfix/postfix.pem
rm -f /tmp/postfix.crt /tmp/postfix.key
#restart postfix
systemctl restart postfix
#test using telnet
(sudo apt-get install gnutls-bin)
gnutls-cli --crlf --starttls --insecure --port 25 localhost
starttls
Ctrl+d
auth plain AHN0dWRlbnQAc3R1ZGVudA==
mail ...