C
C
chrome1232020-10-22 22:33:06
Python
chrome123, 2020-10-22 22:33:06

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()


CLIENT
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()


Letters from the client come. But how to transfer them to gmail for example? Help please
There is a dedicated IP and there is a domain. if necessary. What else is needed ?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
shurshur, 2020-10-22
@chrome123

The STMP server receives the letter, and then, as an SMTP client, sends it to gmail. What is not clear here?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question