0

I use code below to send mails:

...

msg = MIMEText(htmlString, 'html', 'utf-8')

msg["Subject"] = "Test Subject"

sm = smtplib.SMTP(SMTPSERVER, port=PORT, timeout=TIMEOUT)

sm.set_debuglevel(1)

# sm.ehlo()
# sm.starttls()
# sm.ehlo()

sm.login(username, password)
sm.sendmail(from_address, to_address, msg.as_string())
sm.quit()

The question is, every time when I send the mail with same Subject, the mail can not send out successfully.

I tried different Subject with Test Subject1 and Test Subject2 and "est Subject... and then the mail sent out successfully immediately.

I have checked the SMTPSERVER, there is no filter by Subject.

How can I find the reason and solve this problem?

Remi Guan
  • 21,506
  • 17
  • 64
  • 87
Simon
  • 1,033
  • 1
  • 8
  • 16

1 Answers1

0

You should check what is stored in the msg.as_string() variable and empty the value of the variables before each iteration

Andy
  • 863
  • 1
  • 8
  • 20