- Create database on your DB server. We use MySQL.
CREATE DATABASE IF NOT EXISTS `email-microservice` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'email-microservice'@'%' IDENTIFIED BY '<insert_password_here>';
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, REFERENCES, INDEX, ALTER, LOCK TABLES ON `email-microservice`.* TO 'email-microservice'@'%';
- Create schema in the database ideally using Alembic migration. If it is not possible, you can use sql script
script/initdb.sql
- Review deployment scripts for Kubernetes in folder
infra/k8s
. At minimum you have to modify1-init.yaml
and set secret values (replace<define-this>
with actual value). - Apply kubernetes scripts:
kubectl apply -f infra/k8s/1-init.yaml
kubectl apply -f infra/k8s/2-define-storage.yaml
kubectl apply -f infra/k8s/3-deployment.yaml
- Save your email templates to TEMPLATE_ROOT. See details about TEMPLATE_ROOT structure below.
TEMPLATE_ROOT
- folder where all templates are stored. No default value, must be set.EMAIL_CONTENT_ROOT
- folder where email-microservice will store output of jinja template transformation. It is the email message body. No default value, must be set.ATTACHMENT_ROOT
- folder where email attachments are stored. No default value, must be set when using attachments.SENDER_ADDRESS
- FROM address of emails. No default value, must be set.SMTP_USERNAME
- username for login to SMTP server. No default value, must be set.SMTP_PASSWORD
- password for login to SMTP server. No default value, must be set.SMTP_SERVER
- URL of SMTP server. No default value, must be set.SMTP_PORT
- SMTP port. Default value: 465DB_URI
- Database connection string. No default value, must be set. E.g.: mysql://email-microservice:@/email-microservice
email-microservice assumes following structure of TEMPLATE_ROOT folder:
TEMPLATE_ROOT
│
└───en
│ │
│ └───<templateId1>
│ │ html.jinja2
│ │ plain.jinja2
│ │
│ └───<templateId2>
| html.jinja2
| plain.jinja2
│
└───de
│ │
│ └───<templateId1>
│ │ html.jinja2
│ │
│ └───<templateId2>
| html.jinja2
Under TEMPLATE_ROOT there is a set of folders named by languages (en
, de
etc.). In every language folder there are folders named by template IDs. In every template ID folder there can be one file for html email content named exactly html.jinja2
and one file for plain text email content named exactly plain.jinja2
. It is not required to have both plain.jinja2
and html.jinja2
. If e.g. plain.jinja2
is omitted, it will simply not be included in the email.
Other pods should use OpenAPI interface of email-microservice for sending emails. OpenAPI interface does not require any authentication. It is assumed email-microservice is accessible only within the cluster. Swagger documentation is available after installation under http://<email-microservice>/docs. Alternatively, you can check out the swagger UI here.
This project (email-microservice) has no effect on whether sent email ends up in the spam folder or not. You need to troubleshoot your SMTP server settings to avoid spam folder. Here are some tips what you can do:
- Test your emails on mail-tester.com
- Check if Sender Policy Framework (SPF) email authentication is enabled for your domain
- Check if DomainKeys Identified Mail (DKIM) email authentication is enabled for your domain
- Check if Domain-based Message Authentication, Reporting and Conformance (DMARC) email authentication is enabled for your domain
Navigate in Powershell to the root folder of project, e.g. C:\projects\email-microservice
and execute:
.\script\create-pip-requirements.ps1
Navigate in Powershell to db
folder of project, e.g. C:\projects\email-microservice\app\db
and execute:
$env:PYTHONPATH = 'C:/projects/email-microservice/'
$env:DB_URI = 'mysql://email-microservice:<password>@localhost/email-microservice'
alembic revision --autogenerate -m "<custom message>"
alembic upgrade head