Answer the question
In order to leave comments, you need to log in
How to send email with smtpd.SMTPServer?
There is a SMPT server in python. They accept mail from the client.
SERVER
import smtpd
import asyncore
class CustomSMTPServer(smtpd.SMTPServer):
def process_message(self, peer, mailfrom, rcpttos, data, mail_options, rcpt_options):
print('Receiving message from:', mail_options)
print('Message addressed from:', rcpt_options)
print('Receiving message from:', peer)
print('Message addressed from:', mailfrom)
print('Message addressed to :', rcpttos)
print('Message length :', data)
server = CustomSMTPServer(('localhost', 25), None)
asyncore.loop()
import smtplib
HOST = "localhost"
SUBJECT = "Test email from Python"
TO = "[email protected]"
FROM = "[email protected]"
text = "Python 3.4 rules them all!"
BODY = "\r\n".join((
"From: %s" % FROM,
"To: %s" % TO,
"Subject: %s" % SUBJECT ,
"",
text
))
server = smtplib.SMTP(HOST)
server.sendmail(FROM, [TO], BODY)
server.quit()
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question