简体   繁体   English

如何配置 Flask Mail 以使用 Postfix

[英]How to configure Flask Mail to work with Postfix

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.我有一个运行我的 Flask 应用程序的 ubuntu 18.04lts 服务器,我需要能够向用户发送确认电子邮件,让他们创建一个帐户。 I am using Flask-User to handle account authorization/authentication, and I know it uses Flask-Mail to handle confirmation emails.我正在使用 Flask-User 来处理帐户授权/身份验证,并且我知道它使用 Flask-Mail 来处理确认电子邮件。

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.有很多关于如何设置烧瓶邮件以通过 gmail 发送电子邮件的教程,我使用了一段时间,但是(和其他 smtp 客户端)只允许您发送到(我相信)每天大约 100 封电子邮件,我可能需要处理比这更多的电子邮件。 I found out about postfix for ubuntu, and I have set that up.我发现了 ubuntu 的 postfix,我已经设置好了。 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 BadHeaderError 在 Ubuntu 服务器上使用带有 FlaskMail 和 Postfix 的 Flask

Here is an example of what I mean:这是我的意思的一个例子:

In my config.py (I need the ??? entries):在我的 config.py 中(我需要 ??? 条目):

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.我会将这些变量中的大部分放在我的 config_file 中,但我不知道这些值应该是什么。 Supposedly I have postfix configured to support TLS.据说我已经配置了 postfix 以支持 TLS。

I can provide any other relevant info if needed.如果需要,我可以提供任何其他相关信息。 In my init.py file I just import my configuration from this file.在我的 init.py 文件中,我只是从这个文件中导入我的配置。

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.等等。

There is not too much I can help you with, as these values are exact the values you configured your Postfix server with.我无法帮助您太多,因为这些值与您配置 Postfix 服务器时所用的值完全相同。

MAIL_SERVER = # ???邮件服务器 = # ???

eg mail.example.net, or whatever domain your mail server is available at (localhost, ...)例如 mail.example.net,或您的邮件服务器在 (localhost, ...) 上可用的任何域

MAIL_USERNAME = # ??? MAIL_USERNAME = # ???

This is the user name for the authentication.这是用于身份验证的用户名。

MAIL_PASSWORD = # ??? MAIL_PASSWORD = # ???

This is the password for the authentication (the same you would enter eg in your mail client when you configure to send emails)这是用于身份验证的密码(与您在配置发送电子邮件时在邮件客户端中输入的密码相同)

MAIL_DEFAULT_SENDER = # ??? MAIL_DEFAULT_SENDER = # ???

This is an email address, eg info@example.net这是一个电子邮件地址,例如 info@example.net

MAIL_PORT = # ??? MAIL_PORT = # ???

The port Postfix is listening, eg 25 or 587 or whatever you configured it to. Postfix 正在侦听端口,例如 25 或 587 或您配置的任何端口。

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

If you use encryption, you have to activate them accordingly.如果您使用加密,则必须相应地激活它们。 eg my mailserver uses TLS so I set MAIL_USE_TLS = True例如我的邮件服务器使用 TLS 所以我设置MAIL_USE_TLS = True

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM