]> git.lizzy.rs Git - cheatdb.git/blob - app/tasks/emails.py
fa5a8c81f78fb2ea0de31174ae2f4e483551294e
[cheatdb.git] / app / tasks / emails.py
1 # Content DB
2 # Copyright (C) 2018  rubenwardy
3 #
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
16
17
18 from flask import render_template, url_for
19 from flask_mail import Message
20 from app import mail
21 from app.tasks import celery
22 from app.utils import abs_url_for
23
24 @celery.task()
25 def sendVerifyEmail(newEmail, token):
26         print("Sending verify email!")
27         msg = Message("Verify email address", recipients=[newEmail])
28
29         msg.body = """
30                         This email has been sent to you because someone (hopefully you)
31                         has entered your email address as a user's email.
32
33                         If it wasn't you, then just delete this email.
34
35                         If this was you, then please click this link to verify the address:
36
37                         {}
38                 """.format(abs_url_for('users.verify_email', token=token))
39
40         msg.html = render_template("emails/verify.html", token=token)
41         mail.send(msg)
42
43 @celery.task()
44 def sendEmailRaw(to, subject, text, html):
45         from flask_mail import Message
46         msg = Message(subject, recipients=to)
47
48         msg.body = text or html
49         html = html or text
50         msg.html = render_template("emails/base.html", subject=subject, content=html)
51         mail.send(msg)