`Hi, i am using pythonanywhere with my python script. The script works ok on my pc and i get a email. But on pythonanywhere it does not work.
In my example i am using wrong emails and password...
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
import sys
#ivanjefrajer007
# Email configuration
sender_email = "[email protected]"
receiver_email = ["[email protected]"]
password = "xxx"
# Create a message object
message = MIMEMultipart()
message["From"] = sender_email
message["To"] = 'XXX'
message["Subject"] = "XXX"
html_body = """<html>
<body>
"""
# Email content
html_body = html_body + '''
<p>Google tabulky s rekordy zde </p>
</body>
</html>`your text`
'''
message.attach(MIMEText(html_body, "html"))
# Connect to the SMTP server
with smtplib.SMTP_SSL('smtp.seznam.cz', 465) as smtp:
print('Přihlašuji se...')
try:
smtp.login(sender_email, password)
except Exception as e:
print('Přihlášení se nepovedlo.', e)
sys.exit()
print('Odesílám email...')
try:
smtp.sendmail(sender_email, receiver_email, message.as_string())
smtp.quit()
except Exception as e:
print('Odeslání se nepovedlo.', e)
sys.exit()`
print('OK')
From the PythonAnywhere pricing page I read :
If you are using a free account, this is expected.
PythonAnywhere allows free users to communicate only with Gmail SMTP servers (source), but your SMTP server seems to be
smtp.seznam.cz.They mention on the site that all paid plans have unrestricted Internet access so I would suggest you give this a try if you want to access internet from your programs.
Edit : add @Filip's infos