Skip to content

Instantly share code, notes, and snippets.

@codehimanshu
Created January 21, 2017 03:53
Show Gist options
  • Save codehimanshu/557a20d4e71c80683e299844461c889e to your computer and use it in GitHub Desktop.
Save codehimanshu/557a20d4e71c80683e299844461c889e to your computer and use it in GitHub Desktop.
Trying to send an unauthenticated mail using SMTPD
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()
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