How to configure Flask Mail to work with Postfix

770 views Asked by At

I have an ubuntu 18.04lts server set up running my Flask app, and I need to be able to send users a confirmation email to let them create an account. I am using Flask-User to handle account authorization/authentication, and I know it uses Flask-Mail to handle confirmation emails.

There are a bunch of tutorials out there on how to set up flask mail to send emails through gmail, and I was using that for a little while, however that (and other smtp clients) only allows you to send up to (I believe) about 100 emails per day, and I may need to handle more emails than this. I found out about postfix for ubuntu, and I have set that up. However, I can't seem to figure out what configurations I need to pass to my app to make this work.

I have looked at the following question, but it and every other tutorial seem to have the configuration already figured out.

BadHeaderError using Flask with FlaskMail and Postfix on Ubuntu server

Here is an example of what I mean:

In my config.py (I need the ??? entries):

import json

with open('/etc/config.json') as config_file:
    config = json.load(config_file)

class Config:
    MAIL_SERVER = # ??? 
    MAIL_USERNAME = # ???
    MAIL_PASSWORD = # ???
    MAIL_DEFAULT_SENDER = # ???
    MAIL_PORT = # ???
    MAIL_USE_SSL = # ???
    MAIL_USE_TLS = # ???
    SECRET_KEY = config.get('SECRET_KEY')
    SQLALCHEMY_DATABASE_URI = config.get('SQLALCHEMY_DATABASE_URI')
    CSRF_ENABLED = True
    USER_ENABLE_EMAIL = True

I would put most of these variables in my config_file, but I don't know what those values are supposed to be. Supposedly I have postfix configured to support TLS.

I can provide any other relevant info if needed. In my init.py file I just import my configuration from this file.

EDIT: I know you can't give me specific values, and I am not looking for parameters for my machine specifically. I just don't know what relative values I needed in those fields, for example, do I need a username? is it the name of my server? the name of the current system user? is the password the password for my server? no password, since it is local? etc.

1

There are 1 answers

2
Jürgen Gmach On

There is not too much I can help you with, as these values are exact the values you configured your Postfix server with.

MAIL_SERVER = # ???

e.g. mail.example.net, or whatever domain your mail server is available at (localhost, ...)

MAIL_USERNAME = # ???

This is the user name for the authentication.

MAIL_PASSWORD = # ???

This is the password for the authentication (the same you would enter e.g. in your mail client when you configure to send emails)

MAIL_DEFAULT_SENDER = # ???

This is an email address, e.g. [email protected]

MAIL_PORT = # ???

The port Postfix is listening, e.g. 25 or 587 or whatever you configured it to.

MAIL_USE_SSL = # ??? MAIL_USE_TLS = # ???

If you use encryption, you have to activate them accordingly. e.g. my mailserver uses TLS so I set MAIL_USE_TLS = True