2

I have very small flask app which send emails using flask-mail but when I run it nothing happen no errors no exceptions nothing!

this is the code

from flask import Flask
from flask_mail import Mail, Message

app = Flask(__name__)

DEBUG = True
MAIL_SERVER = 'smtp.gmail.com'
MAIL_PORT = 465
MAIL_USE_TLS = False
MAIL_USE_SSL = True
MAIL_DEBUG = True
MAIL_USERNAME = "myemail@gmail.com"
MAIL_PASSWORD = "mypassword"

app.config.from_object(__name__)

mail = Mail(app)

@app.route("/")
def send_mail():
    msg = Message("Hello",
                  sender="myemail@gmail.com",
                  recipients=["another_email@gmail.com"],
                  body="just testing",
                  )
    mail.send(msg)
    return "Message sent"
if __name__ == '__main__':
    app.run()

Update

after very long time i got this error TimeoutError: [Errno 110] Connection timed out

davidism
  • 121,510
  • 29
  • 395
  • 339
Ali Faki
  • 3,928
  • 3
  • 17
  • 25
  • Looks like the connection to gmail isn't working at all, hasn't got the point of checking your password. Can the system this is on connect to gmail? Also google list some requirements for the user id, like having passed captcha authentication, have you checked that? https://support.google.com/a/answer/176600?hl=en – DisappointedByUnaccountableMod Jan 08 '16 at 12:53
  • @barny nothing is shown in the shell and also I have just create a new Gmail account and I don't face any CAPATCHA – Ali Faki Jan 08 '16 at 13:33
  • OK the captcha is probably the problem - use e.g. chrome to login to gmail.com using the email id you want to use, you will have to authenticate the ID, get to the point of seeing the emails of that ID. Then try running the script again. – DisappointedByUnaccountableMod Jan 08 '16 at 13:52
  • @barny i solve my problem thanks for your time – Ali Faki Jan 08 '16 at 14:31

3 Answers3

2

it looks like I solve my problem first go to this page to unlock CAPTCHA

https://accounts.google.com/DisplayUnlockCaptcha

then to this page to allow access from less secure apps https://www.google.com/settings/security/lesssecureapps

Ali Faki
  • 3,928
  • 3
  • 17
  • 25
1

Got the same as Mustapha.

Found this: https://www.linode.com/docs/guides/running-a-mail-server/

Sending Email on Linode

In an effort to fight spam, Linode restricts outbound connections on ports 25, 465, and 587 on all Linodes for new accounts created after November 5th, 2019.

If you have a need to send mail from your Linode, we ask that you first configure (1) valid DNS A records and (2) rDNS records for any Linodes that you plan to use to send mail. Then, open a Support ticket from the Linode Manager – we’ll ask you to provide the name of the Linode(s) that will be used for mailing.

Once you’ve completed those steps and provided that information, our Support team will be happy to review your request.

0

i tried the solution that Ali Faki suggested , and it didnt work for me , but as i made further tries ( simple code to check where is the problem ) , it turned out that mailing ports are blocked by cloud service providers ( Linode in my case ) and you have to set up a domain name and contact them to get it open again .