I got an error while trying to send an email using sendmail python. Here is my python code: (Pas dobjet)
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
me = "my@email.com"
you = "email@gmail.com"
msg = MIMEMultipart('alternative')
msg['Subject'] = "Link"
msg['From'] = me
msg['To'] = you
text = "Hi!\nHow are you?\nHere is the link you wanted:\nhttp://www.python.org"
html = """\
<html>
<head></head>
<body>
<p>Hi!<br>
How are you?<br>
Here is the <a href="[http://www.python.org">link</a]http://www.python.org">link</a> you wanted.
</p>
</body>
</html>
"""
part1 = MIMEText(text, 'plain')
part2 = MIMEText(html, 'html')
msg.attach(part1)
msg.attach(part2)
s = smtplib.SMTP('localhost')
s.sendmail(me, you, msg.as_string())
s.quit()
When I send this email, I have this error:
Traceback (most recent call last):
File "./mail.py", line 47, in <module>
s.sendmail(me, you, msg.as_string())
File "/usr/lib/python2.7/smtplib.py", line 747, in sendmail
raise SMTPRecipientsRefused(senderrs)
smtplib.SMTPRecipientsRefused: {'email@gmail.com': (454, '4.7.1 <email@gmail.com>: Relay access denied')}
I really do not know why this does not work in production, since it works in a test environment. Can you please understand?
source
share