diff --git a/app/api/views/new_custom_alias.py b/app/api/views/new_custom_alias.py index b6f77c11..e4c66ebe 100644 --- a/app/api/views/new_custom_alias.py +++ b/app/api/views/new_custom_alias.py @@ -3,11 +3,11 @@ from flask import jsonify, request from flask_cors import cross_origin from app.api.base import api_bp, verify_api_key -from app.config import MAX_NB_EMAIL_FREE_PLAN +from app.config import MAX_NB_EMAIL_FREE_PLAN, ALIAS_DOMAINS from app.dashboard.views.custom_alias import verify_prefix_suffix from app.extensions import db from app.log import LOG -from app.models import GenEmail, AliasUsedOn, User +from app.models import GenEmail, AliasUsedOn, User, CustomDomain from app.utils import convert_to_id @@ -61,6 +61,14 @@ def new_custom_alias(): gen_email = GenEmail.create( user_id=user.id, email=full_alias, mailbox_id=user.default_mailbox_id, note=note ) + + if alias_suffix.startswith("@"): + alias_domain = alias_suffix[1:] + if alias_domain not in ALIAS_DOMAINS: + domain = CustomDomain.get_by(domain=alias_domain) + LOG.d("set alias %s to domain %s", full_alias, domain) + gen_email.custom_domain_id = domain.id + db.session.commit() if hostname: