theactiveactor
theactiveactor

Reputation: 7554

python smtpd.SMTPServer: How to send reply message in process_message?

In my implementation of smtpd.SMTPServer, I can receive messages via the process_message() callback. How could I send a reply message back to the sender?

Upvotes: 2

Views: 303

Answers (1)

Hcetipe
Hcetipe

Reputation: 466

This is a script that can send email it works for me. I don't know if is that you want but I hope its help you.

import smtplib
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText


fromaddr = "YOUR ADDRESS"
toaddr = "ADDRESS YOU WANT TO SEND TO"
msg = MIMEMultipart()
msg['From'] = fromaddr
msg['To'] = toaddr
msg['Subject'] = "SUBJECT OF THE MAIL"

body = "YOUR MESSAGE HERE"
msg.attach(MIMEText(body, 'plain'))

server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
server.login(fromaddr, "YOUR PASSWORD")
text = msg.as_string()
server.sendmail(fromaddr, toaddr, text)
server.quit()

Upvotes: 2

Related Questions