diff --git a/README.md b/README.md index d83b5991..a80af265 100644 --- a/README.md +++ b/README.md @@ -680,6 +680,42 @@ The code is formatted using https://github.com/psf/black, to format the code, si black . ``` +### Test sending email + +[swaks](http://www.jetmore.org/john/code/swaks/) is used for sending test emails to the `email_handler`. + +[mailcatcher](https://github.com/sj26/mailcatcher) is used to receive forwarded emails. + +There are several steps to set up the email handler + +1) run mailcatcher + +```bash +mailcatcher +``` + +2) Make sure to set the following variables in the `.env` file + +``` +NOT_SEND_EMAIL=true +POSTFIX_SERVER=localhost +POSTFIX_PORT=1025 +``` + +3) Run email_handler + +```bash +python email_handler.py +``` + +4) Send a test email + +```bash +swaks --to e1@d1.localhost --from hey@google.com --server 127.0.0.1:20381 +``` + +Now open http://localhost:1080/, you should see the test email. + ## API SimpleLogin current API clients are Chrome/Firefox/Safari extension and mobile (iOS/Android) app. diff --git a/app/alias_utils.py b/app/alias_utils.py index 1a4f4162..e9506055 100644 --- a/app/alias_utils.py +++ b/app/alias_utils.py @@ -98,7 +98,7 @@ def try_auto_create_catch_all_domain(address: str) -> Optional[Alias]: # try to create alias on-the-fly with custom-domain catch-all feature # check if alias is custom-domain alias and if the custom-domain has catch-all enabled alias_domain = get_email_domain_part(address) - custom_domain = CustomDomain.get_by(domain=alias_domain) + custom_domain: CustomDomain = CustomDomain.get_by(domain=alias_domain) if not custom_domain: return None @@ -116,13 +116,19 @@ def try_auto_create_catch_all_domain(address: str) -> Optional[Alias]: try: LOG.d("create alias %s for domain %s", address, custom_domain) + mailboxes = custom_domain.mailboxes alias = Alias.create( email=address, user_id=custom_domain.user_id, custom_domain_id=custom_domain.id, automatic_creation=True, - mailbox_id=domain_user.default_mailbox_id, + mailbox_id=mailboxes[0].id, ) + db.session.flush() + for i in range(1, len(mailboxes)): + AliasMailbox.create( + alias_id=alias.id, mailbox_id=mailboxes[i].id, + ) db.session.commit() return alias except AliasInTrashError: diff --git a/app/dashboard/templates/dashboard/custom_domain.html b/app/dashboard/templates/dashboard/custom_domain.html index 34be64af..1ebc7008 100644 --- a/app/dashboard/templates/dashboard/custom_domain.html +++ b/app/dashboard/templates/dashboard/custom_domain.html @@ -20,7 +20,10 @@ {% if not current_user.is_premium() %}