0

this is the code form init.py:

#mail configuration
app.config['MAIL_SERVER'] : 'smtp-mail.outlook.com'
app.config['MAIL_PORT'] : 587
app.config['MAIL_USE_TLS'] : False
app.config['MAIL_USE_SSL'] : True
app.config['MAIL_USERNAME'] : 'user'
app.config['MAIL_PASSWORD'] : 'passwd'
app.config['MAIL_DEBUG'] : False
mail = Mail(app)

the route code that handles the Post from the form:

@app.route('/contact', methods=['POST'])
def contact():
    if request.method == 'POST':
        name = request.form['name']
        email = request.form['email']
        subject = request.form['subject']
        message = request.form['message']
        msg = Message(subject=subject,
                    recipients=['rec'],
                    sender='sender',
                    body=f'message from : {name} \n email : {email} \n\n\n {message}')
        mail.send(msg)

the error :

ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it

any ideas please

  • What's to say? `smtp-mail.outlook.com'` doesn't like you, or a local firewall is blocking the outbound connection. – tripleee May 31 '21 at 12:16
  • am using the outlook live smtp – abdelouahed ait ali May 31 '21 at 13:01
  • No you aren't because it's rejecting you. By quick glance, try using TLS instead, though I'm not exactly sure what these options mean (not a Flask person). Generally port 587 is unencrypted and you should then pivot to TLS with `STARTTLS` once you are connected. – tripleee May 31 '21 at 14:00
  • I tried gmail smtp and I had the same problem .. I cant figure out what have I done wrong – abdelouahed ait ali Jun 01 '21 at 09:02
  • As already suggested, try `MAIL_USE_TLS` instead of `MAIL_USE_SSL`; https://stackoverflow.com/questions/37058567/configure-flask-mail-to-use-gmail seems to bear this out. – tripleee Jun 01 '21 at 09:28
  • I read somewhere that `sender` is required and must be exactly the email address for outlook server, is that right? – daro Oct 08 '21 at 10:56

0 Answers0