mirror of
https://github.com/simple-login/app.git
synced 2025-02-22 23:02:55 +08:00
create a notification for a bounce email
This commit is contained in:
parent
bdb97e73e9
commit
90fa4abf69
4 changed files with 72 additions and 2 deletions
|
@ -1,4 +1,5 @@
|
|||
import enum
|
||||
import os
|
||||
import random
|
||||
import uuid
|
||||
from email.utils import formataddr
|
||||
|
@ -11,6 +12,7 @@ from email_validator import validate_email
|
|||
from flanker.addresslib import address
|
||||
from flask import url_for
|
||||
from flask_login import UserMixin
|
||||
from jinja2 import FileSystemLoader, Environment
|
||||
from sqlalchemy import orm
|
||||
from sqlalchemy import text, desc, CheckConstraint, Index, Column
|
||||
from sqlalchemy.dialects.postgresql import TSVECTOR
|
||||
|
@ -33,6 +35,7 @@ from app.config import (
|
|||
ALIAS_RANDOM_SUFFIX_LENGTH,
|
||||
MAX_NB_SUBDOMAIN,
|
||||
MAX_NB_DIRECTORY,
|
||||
ROOT_DIR,
|
||||
)
|
||||
from app.db import Session
|
||||
from app.errors import (
|
||||
|
@ -2563,6 +2566,20 @@ class Notification(Base, ModelMixin):
|
|||
# whether user has marked the notification as read
|
||||
read = sa.Column(sa.Boolean, nullable=False, default=False)
|
||||
|
||||
@staticmethod
|
||||
def render(template_name, **kwargs) -> str:
|
||||
templates_dir = os.path.join(ROOT_DIR, "templates")
|
||||
env = Environment(loader=FileSystemLoader(templates_dir))
|
||||
|
||||
template = env.get_template(template_name)
|
||||
|
||||
return template.render(
|
||||
URL=URL,
|
||||
LANDING_PAGE_URL=LANDING_PAGE_URL,
|
||||
YEAR=arrow.now().year,
|
||||
**kwargs,
|
||||
)
|
||||
|
||||
|
||||
class SLDomain(Base, ModelMixin):
|
||||
"""SimpleLogin domains"""
|
||||
|
|
|
@ -149,6 +149,7 @@ from app.models import (
|
|||
MessageIDMatching,
|
||||
DeletedAlias,
|
||||
DomainDeletedAlias,
|
||||
Notification,
|
||||
)
|
||||
from app.pgp_utils import PGPException, sign_data_with_pgpy, sign_data
|
||||
from app.utils import sanitize_email
|
||||
|
@ -1396,6 +1397,21 @@ def handle_bounce_forward_phase(msg: Message, email_log: EmailLog):
|
|||
)
|
||||
disable_alias_link = f"{URL}/dashboard/unsubscribe/{alias.id}"
|
||||
block_sender_link = f"{URL}/dashboard/alias_contact_manager/{alias.id}?highlight_contact_id={contact.id}"
|
||||
|
||||
Notification.create(
|
||||
user_id=user.id,
|
||||
title=f"Email from {contact.website_email} to {alias.email} cannot be delivered to {mailbox.email}",
|
||||
message=Notification.render(
|
||||
"notification/bounce-forward-phase.html",
|
||||
alias=alias,
|
||||
website_email=contact.website_email,
|
||||
disable_alias_link=disable_alias_link,
|
||||
refused_email_url=refused_email.get_url(),
|
||||
mailbox_email=mailbox.email,
|
||||
block_sender_link=block_sender_link,
|
||||
),
|
||||
commit=True,
|
||||
)
|
||||
send_email_with_rate_control(
|
||||
user,
|
||||
ALERT_BOUNCE_EMAIL,
|
||||
|
|
|
@ -34,8 +34,9 @@
|
|||
<div v-if="loading">Loading ...</div>
|
||||
<div class="dropdown-item d-flex" v-for="notification in notifications">
|
||||
<div class="flex-grow-1">
|
||||
<div v-html="notification.title" class="font-weight-bold" />
|
||||
</div>
|
||||
<div v-html="notification.title" class="font-weight-bold" style="width: 40em; word-wrap:break-word; white-space: normal; overflow: hidden;"></div>
|
||||
|
||||
|
||||
|
||||
<div v-html="notification.message"
|
||||
style="width: 40em; word-wrap:break-word; white-space: normal; overflow: hidden; max-height: 100px; text-overflow: ellipsis;">
|
||||
|
|
36
templates/notification/bounce-forward-phase.html
Normal file
36
templates/notification/bounce-forward-phase.html
Normal file
|
@ -0,0 +1,36 @@
|
|||
<div>
|
||||
This is usually because your mailbox service thinks the email is <b>spam</b>.
|
||||
</div>
|
||||
|
||||
<a href="{{ refused_email_url }}" class="btn btn-primary">
|
||||
View the bounced email
|
||||
</a>
|
||||
|
||||
<div>
|
||||
The email is automatically deleted in 7 days.
|
||||
</div>
|
||||
|
||||
<div>
|
||||
Please consider the following options: <br>
|
||||
|
||||
<ol>
|
||||
<li>If the email is not spam, you can create a
|
||||
<a href="https://simplelogin.io/docs/getting-started/troubleshooting/">filter</a>
|
||||
to explicitly allow all emails from SimpleLogin. <br>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
If this email is indeed spam, it means your alias {{ alias.email }} is now in the hands of a spammer.
|
||||
You can either <a href="{{ disable_alias_link }}">disable the alias</a>
|
||||
or <a href="{{ block_sender_link }}">block the sender</a> if they send too many spams.
|
||||
</li>
|
||||
</ol>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<div class="alert alert-warning">
|
||||
Please note that the alias can be automatically disabled if too many emails sent to it are bounced.
|
||||
</div>
|
||||
|
||||
|
Loading…
Reference in a new issue