I am trying to send email from my application using flask mail. I have my setting configured in init .py but flask-mail is trying to use 127.0.0.1 as the mail server with port 25 instead of the configuration I have provided
At first I though it was a problem with using gmail. So I tried sendgrid and mailjet with the same results. Then I noticed that it isn't using the correct server
Here is my config from init .py
MAIL_SERVER = 'in-v3.mailjet.com'
MAIL_PORT = 587
MAIL_USE_TLS = True
MAIL_USE_SSL = False
MAIL_USERNAME = os.environ.get('MAILJET_USER')
MAIL_PASSWORD = os.environ.get('MAILJET_PASS')
mail = Mail(app)
here is the dump() from the stacktrace
address
('127.0.0.1', 25)
timeout
<object object at 0x7f086826c150>
source_address
None
host
'127.0.0.1'
port
25
err
ConnectionRefusedError(111, 'Connection refused')
res
(, , 6, '', ('127.0.0.1', 25))
af
socktype
proto
6
canonname
''
sa
('127.0.0.1', 25)
sock
<socket.socket [closed] fd=-1, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=6>
All my other config stuff in init .py is being read and applied correctly
Adding app.config was the answer
app.config['MAIL_SERVER'] = 'in-v3.mailjet.com'
app.config['MAIL_PORT'] = 587
app.config['MAIL_USE_TLS'] = True
app.config['MAIL_USE_SSL'] = False
app.config['MAIL_USERNAME'] = os.environ.get('MAILJET_USER')
app.config['MAIL_PASSWORD'] = os.environ.get('MAILJET_PASS')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.