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?
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?