Python anywhere not sending email

73 views Asked by At

`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')
2

There are 2 answers

4
LiteApplication On

From the PythonAnywhere pricing page I read :

Beginner: Free!
A limited account with one web app at your-username.pythonanywhere.com, restricted outbound Internet access from your apps, low CPU/bandwidth, no IPython/Jupyter notebook support. It works and it's a great way to get started!

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

0
Shaolin Master On

There was just problem with spam filter. After i put [email protected] into trusted emails it started working... For clarification i have a paid plan.