Python Forum
Trying to reply to an email instead of sending a new mail using python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Trying to reply to an email instead of sending a new mail using python
#1
I want to reply to an email as a thread using python SMTP, I wrote the following code and that does not reply, instead it sends a new mail to the recipient.

def email_sending(user, pwd, recipient, subject, body):
try:
mail_html_content = body

msg = MIMEMultipart()
msg['Subject'] = subject
msg['From'] = user
msg['reply-to'] = recipient

ctype = None
if ctype is None or encoding is not None:
ctype = "application/octet-stream"

maintype, subtype = ctype.split("/", 1)
text = MIMEText(mail_html_content, 'html')
msg.attach(text)
s = smtplib.SMTP("smtp.gmail.com", 587)
context = ssl.create_default_context()
s.starttls(context=context)
s.login(user, pwd)

s.sendmail(user, recipient, msg.as_string())
s.quit()

return True
except Exception as ex:
print("Error == ", ex)
return False
Know someone who can answer?
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020