gRPC based emailing service for microservice based architecture.
Send Standard emails with following parameters:
Recipients
Recipients - List of recipientsSubject
string - Subject of the emailBody
string - Email bodyContentType
string: Iftext/html
then HTML otherwise Plain text.Attachments
Attachment - Attachments to be sent with email.Headers
map(string -> string) - Add headers.
Send Raw RFC822 based emails:
Recipients
[string] - List of recipientsBody
Bytes - Email body
Send Templated emails (templates should exist beforehand):
Recipients
Recipients - List of recipientsSubject
string - Subject of the emailTemplateName
string - Name of the templateAttachments
Attachment - Attachments to be sent with email.TemplateParams
map(string -> string) - Template data to be used in the template.Headers
map(string -> string) - Add headers.
SMTP_HOST: SMTP host
SMTP_PORT: SMTP port
SMTP_SENDER: SMTP user
SMTP_PASSWORD: SMTP password
PORT: Port to listen on
PROMETHEUS_PORT: Port to expose metrics on
-disableEmail
disable email sending
-help
show help
-port int
port to listen (default 5555)
-prometheusPort int
port to listen for prometheus (default 9090)
-smtpEmail string
SMTP email
-smtpHost string
SMTP host
-smtpPassword string
For templates to be used in the email, they should be stored in the ./templates
directory relative to the binary. Naming scheme for files is <template_name>.html
, where template_name
is the name of the template to be used by the client.
Templated are parsed using html/template
package.
{{.}}
- prints the value of the variable
For docker, workdir in
/app
, hence, templates should be stored in/app/templates
directory.
docker run -d --name email-microservice --env-file app.env -p 5555:5555 crossphoton/email-microservice:v1.0.0
Use the deployment.yml file for the service deployment.
This requires a smtp-secret
secret to be created which contains the following:
SMTP_HOST
- SMTP hostSMTP_PORT
- SMTP portSMTP_EMAIL
- SMTP emailSMTP_PASSWORD
- SMTP password
A template of this is also provided (See secrets.yml)
- Clone the repository
- After setting up the environment variables, run
go run main.go
See examples in the examples directory.
Generate the client code using the proto file email.proto
In examples directory run
./gen_proto.sh
- Prometheus : Port
9090
is exposed for Prometheus metrics. Can be changed using environment variable. - Logging - go.uber.org/zap is used for logging.
- GRPC Middleware - validation, prometheus, zap
- Tracing
- Graceful shutdown
- Switch to Uber Go Style. See the guide here.
GNU General Public License v3.0
Recipients
:
To
[string] - Recipient email addressCc
[string] - Carbon copy email addressBcc
[string] - Blind carbon copy email address
Name <address>
formatting is supported.
Attachment
:
- base64data string - Base64 encoded data of attachment.
- filename string - Name of attachment.