Skip to content

Instantly share code, notes, and snippets.

@kaniket7209
Created December 5, 2021 17:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kaniket7209/57d0d196ea2244e7ba71dba96f8d9054 to your computer and use it in GitHub Desktop.
Save kaniket7209/57d0d196ea2244e7ba71dba96f8d9054 to your computer and use it in GitHub Desktop.
SEND EMAILS USING FLASK-MAIL
1. How can we set up Mail instance using init_app method
Answer: Use below command:
mail = Mail()
app = Flask(__name__)
mail.init_app(app)
2. Why 'ConnectionRefusedError:[WinError 10061]' occurs and how to fix it?
Answer: Based on the description of the error, this is not a problem with your Python code, but rather that the network connection to smtp.gmail.com is being blocked/rejected (possibly by a firewall or some other network issue).
Note that if you are running this on a home machine, most ISPs will actively block outbound SMTP connections to anything except the ISP's own SMTP servers (some hosting providers also do the same), to prevent spammers from exploiting the service. You may need to change your settings to use your ISP's outbound mail host instead of connecting directly to smtp.gmail.com.
3. What is Flask_mail ?
Answer: The Flask-Mail is a extension that provides a simple interface to set up SMTP with your Flask application and to send messages from your views and scripts.
4. How do I send a confirmation link in an email Flask?
Answer: Handling Email Confirmation During Registration in Flask
a) Generate confirmation token.
b) Update register() view function.
c) Handle Email Confirmation.
d) Create the email template.
e) Send email.
f) Update register() view function in project/user/views.py (again!)
g) Mail.
5. How do I debug Flask-Mail?
Answer: Flask-Email use smtplib which can set debug level. You can set it with MAIL_DEBUG = True or DEBUG = True . Also check that MAIL_SUPPRESS_SEND = False and TESTING = False .
6. What is an SMTP server name?
Answer: An SMTP server is the machine that takes care of the whole email delivery process: that's why to send your messages with an email client or software you need first of all to configure the correct SMTP settings – in particular, the right SMTP address you're using. (For instance, Gmail's is smtp.gmail.com).
7. How does SMTP work?
Answer: It functions following the Simple Mail Transfer Protocol (SMTP). The SMTP server receives emails from the email client. Then it passes them on to another SMTP server and relays them to the incoming mail server.
8. Why SMTP is used?
Answer: The Simple Mail Transfer Protocol (SMTP) is used to deliver e-mail messages over the Internet. This protocol is used by most e-mail clients to deliver messages to the server, and is also used by servers to forward messages to their final destination.
1. Choose the correct command to install flask-mail
a) pip install flask-mail
b) npm install flask-mail
c) pip install flask mail
d) npm install flask mail
Answer: a)
2. What is the command to launch virtual environment(.venv)
a) pyenv exec python -m .venv venv
b) python -m venv .venv
c) pyenv exec python -m .venv venv
d) python exec pyenv -m venv .venv
Answer: d)
3. Can we enable STARTTLS and SSL/TLS both at a same time
a) No
b) Yes
Answer: a)
4. Suppose we are using STARTTLS with MAIL_USE_TLS = True, then MAIL_PORT will be
a) 587
b) 465
c) 25
d) either 587 or 465
Answer: a)
5. Suppose we are using SSL/TLS directly with MAIL_USE_SSL = True,, then MAIL_PORT will be
a) 587
b) 465
c) 25
d) either 587 or 465
Answer: b)
6. What is the instance that we use to send message(msg)
a) mail.send(msg)
b) flask_mail.send(msg)
c) mail.get(msg)
d) msg.send()
Answer: a)
7. Can we attach files/images using flask-mail
a) No
b) Yes
Answer: b)
8. Can we set the recipient emails individually?
a) Yes
b) No
Answer: a)
9. What is the server name while using flask-mail
a) localhost
b) smtp.gmail.com
c) flask-mail.gmail.com
d) sttp-gmail.com
Answer: b)
10. Can SMTP receive email?
a) Yes
b) No
Answer: b)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment