Created
January 21, 2017 03:53
-
-
Save codehimanshu/557a20d4e71c80683e299844461c889e to your computer and use it in GitHub Desktop.
Trying to send an unauthenticated mail using SMTPD
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import smtplib | |
import email.utils | |
from email.mime.text import MIMEText | |
# Create the message | |
msg = MIMEText('This is the body of the message.') | |
msg['To'] = email.utils.formataddr(('Recipient', '[email protected]')) | |
msg['From'] = email.utils.formataddr(('Author', '[email protected]')) | |
msg['Subject'] = 'Simple test message' | |
server = smtplib.SMTP('127.0.0.1', 1025) | |
server.set_debuglevel(True) # show communication with the server | |
try: | |
server.sendmail('[email protected]', ['[email protected]'], msg.as_string()) | |
finally: | |
server.quit() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import smtpd | |
import asyncore | |
class CustomSMTPServer(smtpd.SMTPServer): | |
def process_message(self, peer, mailfrom, rcpttos, data): | |
print 'Receiving message from:', peer | |
print 'Message addressed from:', mailfrom | |
print 'Message addressed to :', rcpttos | |
print 'Message length :', len(data) | |
return | |
server = CustomSMTPServer(('127.0.0.1', 1025), None) | |
asyncore.loop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment