send by postfix only
This commit is contained in:
parent
79a2f5379f
commit
6f93f419c2
|
@ -66,25 +66,4 @@ def send_activation_email(user, next_url):
|
||||||
LOG.d("redirect user to %s after activation", next_url)
|
LOG.d("redirect user to %s after activation", next_url)
|
||||||
activation_link = activation_link + "&next=" + encode_url(next_url)
|
activation_link = activation_link + "&next=" + encode_url(next_url)
|
||||||
|
|
||||||
email_utils.send_by_sendgrid(
|
email_utils.send_activation_email(user.email, user.name, activation_link)
|
||||||
user.email,
|
|
||||||
f"Welcome to SimpleLogin {user.name} - just one more step!",
|
|
||||||
html_content=f"""
|
|
||||||
Welcome to SimpleLogin! <br><br>
|
|
||||||
|
|
||||||
Our mission is to make the login process as smooth and as secure as possible. This should be easy. <br><br>
|
|
||||||
|
|
||||||
To get started, we need to confirm your email address, so please click this <a href="{activation_link}">link</a>
|
|
||||||
to finish creating your account. Or you can paste this link into your browser: <br><br>
|
|
||||||
|
|
||||||
{activation_link} <br><br>
|
|
||||||
|
|
||||||
Your feedbacks are very important to us. Please feel free to reply to this email to let us know any
|
|
||||||
of your suggestion! <br><br>
|
|
||||||
|
|
||||||
Thanks! <br><br>
|
|
||||||
|
|
||||||
SimpleLogin team.
|
|
||||||
|
|
||||||
""",
|
|
||||||
)
|
|
||||||
|
|
|
@ -39,7 +39,6 @@ ENABLE_SENTRY = "ENABLE_SENTRY" in os.environ
|
||||||
NOT_SEND_EMAIL = "NOT_SEND_EMAIL" in os.environ
|
NOT_SEND_EMAIL = "NOT_SEND_EMAIL" in os.environ
|
||||||
EMAIL_DOMAIN = os.environ["EMAIL_DOMAIN"]
|
EMAIL_DOMAIN = os.environ["EMAIL_DOMAIN"]
|
||||||
SUPPORT_EMAIL = os.environ["SUPPORT_EMAIL"]
|
SUPPORT_EMAIL = os.environ["SUPPORT_EMAIL"]
|
||||||
SENDGRID_API_KEY = os.environ["SENDGRID_API_KEY"]
|
|
||||||
MAX_NB_EMAIL_FREE_PLAN = int(os.environ["MAX_NB_EMAIL_FREE_PLAN"])
|
MAX_NB_EMAIL_FREE_PLAN = int(os.environ["MAX_NB_EMAIL_FREE_PLAN"])
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
|
|
||||||
import arrow
|
|
||||||
import stripe
|
|
||||||
from flask import render_template, request, redirect, url_for, flash
|
from flask import render_template, request, redirect, url_for, flash
|
||||||
from flask_login import login_required, current_user
|
from flask_login import login_required, current_user
|
||||||
from flask_wtf import FlaskForm
|
from flask_wtf import FlaskForm
|
||||||
|
@ -9,9 +7,8 @@ from flask_wtf.file import FileField
|
||||||
from wtforms import StringField, validators
|
from wtforms import StringField, validators
|
||||||
|
|
||||||
from app import s3, email_utils
|
from app import s3, email_utils
|
||||||
from app.config import URL, PROMO_CODE
|
from app.config import URL
|
||||||
from app.dashboard.base import dashboard_bp
|
from app.dashboard.base import dashboard_bp
|
||||||
from app.email_utils import notify_admin
|
|
||||||
from app.extensions import db
|
from app.extensions import db
|
||||||
from app.log import LOG
|
from app.log import LOG
|
||||||
from app.models import PlanEnum, File, ResetPasswordCode
|
from app.models import PlanEnum, File, ResetPasswordCode
|
||||||
|
@ -59,7 +56,6 @@ def setting():
|
||||||
elif request.form.get("form-name") == "change-password":
|
elif request.form.get("form-name") == "change-password":
|
||||||
send_reset_password_email(current_user)
|
send_reset_password_email(current_user)
|
||||||
|
|
||||||
|
|
||||||
return redirect(url_for("dashboard.setting"))
|
return redirect(url_for("dashboard.setting"))
|
||||||
|
|
||||||
return render_template(
|
return render_template(
|
||||||
|
@ -79,21 +75,7 @@ def send_reset_password_email(user):
|
||||||
|
|
||||||
reset_password_link = f"{URL}/auth/reset_password?code={reset_password_code.code}"
|
reset_password_link = f"{URL}/auth/reset_password?code={reset_password_code.code}"
|
||||||
|
|
||||||
email_utils.send_by_sendgrid(
|
email_utils.send_reset_password_email(user.email, user.name, reset_password_link)
|
||||||
user.email,
|
|
||||||
f"Reset your password on SimpleLogin",
|
|
||||||
html_content=f"""
|
|
||||||
Hi {user.name}! <br><br>
|
|
||||||
|
|
||||||
To reset or change your password, please follow this link <a href="{reset_password_link}">reset password</a>.
|
|
||||||
Or you can paste this link into your browser: <br><br>
|
|
||||||
|
|
||||||
{reset_password_link} <br><br>
|
|
||||||
|
|
||||||
Cheers,
|
|
||||||
SimpleLogin team.
|
|
||||||
""",
|
|
||||||
)
|
|
||||||
|
|
||||||
flash(
|
flash(
|
||||||
"You are going to receive an email containing instruction to change your password",
|
"You are going to receive an email containing instruction to change your password",
|
||||||
|
|
|
@ -38,46 +38,7 @@ app: {client.name}
|
||||||
# if this is the first app user creates, sends an email to ask for feedback
|
# if this is the first app user creates, sends an email to ask for feedback
|
||||||
if db.session.query(Client).filter_by(user_id=current_user.id).count() == 1:
|
if db.session.query(Client).filter_by(user_id=current_user.id).count() == 1:
|
||||||
LOG.d(f"send feedback email to user {current_user}")
|
LOG.d(f"send feedback email to user {current_user}")
|
||||||
email_utils.send_by_sendgrid(
|
email_utils.send_new_app_email(current_user.email, current_user.name)
|
||||||
current_user.email,
|
|
||||||
"SimpleLogin questions/feedbacks",
|
|
||||||
f"""
|
|
||||||
Hi {current_user.name}! <br><br>
|
|
||||||
|
|
||||||
This is Son, SimpleLogin CEO & Founder :) <br><br>
|
|
||||||
|
|
||||||
Even though I lead the company, I’m the "product person" and the user experience you get from our product means a lot to me. <br><br>
|
|
||||||
|
|
||||||
Our users and developers love SimpleLogin and its simplicity (hence the "simple" in the name 😉), but if there's anything that's bugging you, even the smallest of issues that could be done better, I want to hear about it - so hit the reply button.
|
|
||||||
<br><br>
|
|
||||||
|
|
||||||
And ok, this is an automated email, but if you reply it comes directly to me and will be answered by me.
|
|
||||||
<br><br>
|
|
||||||
|
|
||||||
Best regards, <br>
|
|
||||||
Son. <br>
|
|
||||||
<br>
|
|
||||||
----------------------------------<br>
|
|
||||||
Son NK <br>
|
|
||||||
SimpleLogin founder. <br>
|
|
||||||
https://simplelogin.io <br>
|
|
||||||
https://twitter.com/nguyenkims <br>
|
|
||||||
""",
|
|
||||||
plain_content="""
|
|
||||||
Hi there!
|
|
||||||
|
|
||||||
This is Son, SimpleLogin CEO & Founder :).
|
|
||||||
|
|
||||||
Even though I lead the company, I’m the "product person" and the user experience you get from our product means a lot to me.
|
|
||||||
|
|
||||||
Our users and developers love SimpleLogin and its simplicity (hence the "simple" in the name 😉), but if there's anything that's bugging you, even the smallest of issues that could be done better, I want to hear about it - so hit the reply button.
|
|
||||||
|
|
||||||
And ok, this is an automated email, but if you reply it comes directly to me and will be answered by me.
|
|
||||||
|
|
||||||
Best regards,
|
|
||||||
Son.
|
|
||||||
""",
|
|
||||||
)
|
|
||||||
|
|
||||||
return redirect(
|
return redirect(
|
||||||
url_for("developer.client_detail", client_id=client.id, is_new=1)
|
url_for("developer.client_detail", client_id=client.id, is_new=1)
|
||||||
|
|
|
@ -1,40 +1,62 @@
|
||||||
# using SendGrid's Python Library
|
import os
|
||||||
# https://github.com/sendgrid/sendgrid-python
|
|
||||||
from email.message import EmailMessage
|
from email.message import EmailMessage
|
||||||
from smtplib import SMTP
|
from smtplib import SMTP
|
||||||
|
|
||||||
from sendgrid import SendGridAPIClient
|
from jinja2 import Environment, FileSystemLoader
|
||||||
from sendgrid.helpers.mail import Mail
|
|
||||||
|
|
||||||
from app.config import SUPPORT_EMAIL, SENDGRID_API_KEY, NOT_SEND_EMAIL
|
from app.config import SUPPORT_EMAIL, ROOT_DIR
|
||||||
from app.log import LOG
|
|
||||||
|
|
||||||
|
|
||||||
def send_by_sendgrid(to_email, subject, html_content, plain_content=None):
|
def _render(template_name, **kwargs) -> str:
|
||||||
# On local only print out email content
|
templates_dir = os.path.join(ROOT_DIR, "templates", "emails")
|
||||||
if NOT_SEND_EMAIL:
|
env = Environment(loader=FileSystemLoader(templates_dir))
|
||||||
LOG.d(
|
|
||||||
"send mail to %s, subject:%s, content:%s", to_email, subject, html_content
|
|
||||||
)
|
|
||||||
return
|
|
||||||
|
|
||||||
if not plain_content:
|
template = env.get_template(template_name)
|
||||||
plain_content = subject
|
|
||||||
|
|
||||||
message = Mail(
|
return template.render(**kwargs)
|
||||||
from_email=SUPPORT_EMAIL,
|
|
||||||
to_emails=to_email,
|
|
||||||
subject=subject,
|
def send_welcome_email(email, name):
|
||||||
html_content=html_content,
|
send_by_postfix(
|
||||||
plain_text_content=plain_content,
|
email,
|
||||||
|
f"{name}, welcome to SimpleLogin!",
|
||||||
|
_render("welcome.txt", name=name),
|
||||||
|
_render("welcome.html", name=name),
|
||||||
)
|
)
|
||||||
|
|
||||||
sg = SendGridAPIClient(SENDGRID_API_KEY)
|
|
||||||
response = sg.send(message)
|
def send_activation_email(email, name, activation_link):
|
||||||
LOG.d("sendgrid res:%s, email:%s", response.status_code, to_email)
|
send_by_postfix(
|
||||||
|
email,
|
||||||
|
f"{name}, just one more step to join SimpleLogin",
|
||||||
|
_render("activation.txt", name=name, activation_link=activation_link),
|
||||||
|
_render("activation.html", name=name, activation_link=activation_link),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def send_by_postfix(to_email, subject, content):
|
def send_reset_password_email(email, name, reset_password_link):
|
||||||
|
send_by_postfix(
|
||||||
|
email,
|
||||||
|
f"{name}, reset your password on SimpleLogin",
|
||||||
|
_render(
|
||||||
|
"reset-password.txt", name=name, reset_password_link=reset_password_link
|
||||||
|
),
|
||||||
|
_render(
|
||||||
|
"reset-password.html", name=name, reset_password_link=reset_password_link
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def send_new_app_email(email, name):
|
||||||
|
send_by_postfix(
|
||||||
|
email,
|
||||||
|
f"{name}, any questions/feedbacks for SimpleLogin?",
|
||||||
|
_render("new-app.txt", name=name),
|
||||||
|
_render("new-app.html", name=name),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def send_by_postfix(to_email, subject, plaintext, html):
|
||||||
# host IP, setup via Docker network
|
# host IP, setup via Docker network
|
||||||
smtp = SMTP("1.1.1.1", 25)
|
smtp = SMTP("1.1.1.1", 25)
|
||||||
msg = EmailMessage()
|
msg = EmailMessage()
|
||||||
|
@ -42,10 +64,13 @@ def send_by_postfix(to_email, subject, content):
|
||||||
msg["Subject"] = subject
|
msg["Subject"] = subject
|
||||||
msg["From"] = f"Son from SimpleLogin <{SUPPORT_EMAIL}>"
|
msg["From"] = f"Son from SimpleLogin <{SUPPORT_EMAIL}>"
|
||||||
msg["To"] = to_email
|
msg["To"] = to_email
|
||||||
msg.set_content(content)
|
|
||||||
|
msg.set_content(plaintext)
|
||||||
|
if html is not None:
|
||||||
|
msg.add_alternative(html, subtype="html")
|
||||||
|
|
||||||
smtp.send_message(msg, from_addr=SUPPORT_EMAIL, to_addrs=[to_email])
|
smtp.send_message(msg, from_addr=SUPPORT_EMAIL, to_addrs=[to_email])
|
||||||
|
|
||||||
|
|
||||||
def notify_admin(subject, html_content=""):
|
def notify_admin(subject, html_content=""):
|
||||||
send_by_postfix(SUPPORT_EMAIL, subject, html_content)
|
send_by_postfix(SUPPORT_EMAIL, subject, html_content, html_content)
|
||||||
|
|
Loading…
Reference in a new issue