Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mailinabox
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
mailinabox
Commits
1b4dd982
Commit
1b4dd982
authored
Apr 23, 2014
by
Joshua Tauberer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test that the SMTP server's EHLO name matches its reverse DNS name
parent
22ad6686
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
0 deletions
+16
-0
test_mail.py
tests/test_mail.py
+16
-0
No files found.
tests/test_mail.py
View file @
1b4dd982
...
...
@@ -2,6 +2,7 @@
# Tests sending and receiving mail by sending a test message to yourself.
import
sys
,
imaplib
,
smtplib
,
uuid
,
time
import
socket
,
dns
.
reversename
,
dns
.
resolver
if
len
(
sys
.
argv
)
<
3
:
print
(
"Usage: tests/mail.py hostname emailaddress password"
)
...
...
@@ -28,9 +29,24 @@ This is a test message. It should be automatically deleted by the test script.""
emailto
=
emailto
,
subject
=
mailsubject
,
)
# Connect to the server on the SMTP submission TLS port.
server
=
smtplib
.
SMTP
(
host
,
587
)
#server.set_debuglevel(1)
server
.
starttls
()
# Verify that the EHLO name matches the server's reverse DNS.
ipaddr
=
socket
.
gethostbyname
(
host
)
# IPv4 only!
reverse_ip
=
dns
.
reversename
.
from_address
(
ipaddr
)
# e.g. "1.0.0.127.in-addr.arpa."
reverse_dns
=
dns
.
resolver
.
query
(
reverse_ip
,
'PTR'
)[
0
]
.
target
.
to_text
(
omit_final_dot
=
True
)
# => hostname
server
.
ehlo_or_helo_if_needed
()
# must send EHLO before getting the server's EHLO name
helo_name
=
server
.
ehlo_resp
.
decode
(
"utf8"
)
.
split
(
"
\n
"
)[
0
]
# first line is the EHLO name
if
helo_name
!=
reverse_dns
:
print
(
"The server's EHLO name does not match its reverse hostname. Check DNS settings."
)
sys
.
exit
(
1
)
print
(
"SMTP EHLO name (
%
s) is OK."
%
helo_name
)
# Login and send a test email.
server
.
login
(
emailaddress
,
pw
)
server
.
sendmail
(
emailaddress
,
[
emailto
],
msg
)
server
.
quit
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment