Skip to content

yue-best-practices/email-service

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

EmailService

Introduction

EmailService provides an http interface, a mailing queue, a mailing result notification, and a notification failure retry queue.

Usage

1.Clone The Project

git clone https://github.com/yue-best-practices/email-service.git temp_folder

2.Build Docker Image

make docker

This command will build the application and package it as a docker image file.The default image is email-service:0.0.1.You can modify it in the docker-config/Dockerfile file.

make clean

This command will clear the dependency files generated by building the docker image file.

3.Configuration

You need to configure the docker-compose.xml file according to your own information. The following is the meaning of the specific environment variable configuration information.

ENV Variable Comment Default
PORT Http service port 8001
MAX_QUEUE_LEN Mail queue channel buffer length. This number can increase the number of concurrent. 5
RETRY_QUEUE_LEN Notification failure retry queue channel buffer length. 5
RETRY_TIME_EXPRESS The notification fails the retry strategy. Multiple notifications are separated by the symbol |, and the system will send the notification again after the failure. (Unit: minute) 5|15|30
USER Default mail sender account. If not set, set it when adding a send mail task.
PASSWORD Default password of the sender's account
SMTP_HOST Default mail sending account host
SMTP_PORT Default sending account host port
NICK_NAME Default sender's nickname

4.Run Server

Use the command make run or use the docker-compose.xml file.

5.Stop Server

Use the command make stop or use the docker-compose.xml file.

6.API Explain

  • Add an email task

URL:/putTask/:id

Method:PUT

Param:

{
	"user":"test@test.com",
	"password":"123456passwd",
	"smtpHost":"smtp.mxhichina.com",
	"smtpPort":"465",
	"contentType":"Content-Type: text/html; charset=UTF-8",
	"to":["test1@test.com","test2@test.com"],
	"subject":"Test",
	"body":"<h1>Test</h1>Hello,world!",
	"notifyUrl":"http://127.0.0.1:8000/test",
	"isSSL":true
}

If you need to send mail via SSL, set the isSSL parameter to true, otherwise you will not pass this parameter.

Response:

{
	"code":200,
	"message":"OK"
}

7.Notification

Url: The notifyUrl that you set

Method:POST

Param:

Parameter Data Type Description
externalId string The id when you requested to add a mailing task
status string Mail delivery result SUCCESS or FAILED
message string If the transmission is successful, it is OK, otherwise it is a failure message.

Response:

statusCode:200

body:success

If the response to the notification interface is not the same, then the notification will be retried