I made a small script to send an html email using smtplib based on this post
Basically what I want is to send an email to one of our subscribers automatically after certain conditions in our database are fulfilled :
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
sender = "sender_email@domain.com"
receiver = "receiver_email@domain.com"
# Create message container - the correct MIME type is multipart/alternative.
msg = MIMEMultipart('alternative')
msg['Subject'] = "Test email"
msg['From'] = me
msg['To'] = you
# Message body
text = "string message"
html = """\
<html>
<head></head>
<body>
<p>
html message
</p>
</body>
</html>
"""
part1 = MIMEText(text, 'plain')
part2 = MIMEText(html, 'html')
msg.attach(part1)
msg.attach(part2)
# Send the message via external SMTP server.
s = smtplib.SMTP('mail.domain.com')
s.sendmail(sender, receiver, msg.as_string())
s.quit()
The issue is whenever I try to run the script to any email other than my own, i receive the following error:
s.sendmail(me, you, msg.as_string())
File "/usr/lib/python2.7/smtplib.py", line 742, in sendmail
raise SMTPRecipientsRefused(senderrs)
smtplib.SMTPRecipientsRefused: {'other_email@domain.com': (450, 'This mail is temporarily denied')}
EDIT:
I checked my mail server configuration and tested for 3 different addresses, 2 of which I removed the spam filter and 1 for which I kept it and then ran the script. The 2 emails with no spam filter received the email and the one with the filter did not, that is why I believe it is a spam issue, but it must be then how I am setting up the code that generates the email, or perhaps I'm missing a header?