I. Project Introduction

A mail server that can be started locally and supports mail sending with a visual interface. The technical stack uses Express + Nodemailer + Jade. After the development is completed, automated testing (interface testing) is added. The testing framework uses Mocha and the assertion library should.js.

Ii. Project Background

The story begins three years ago, when I just finished my GitHub homepage. There was a connect module that needed to implement a simple message function. Two ideas came to mind:

  1. Buy server, build database, achieve message management
  2. The message content is directly converted into an email and sent to my mailbox

After comprehensive consideration, scheme 2 is the final choice. After all, there is no need to echo messages and the cost of scheme 2 is much lower.

After spending an evening researching mail packages from several major vendors and researching related solutions on Github, I found that I could build my own mail server directly from Node, so my second open source project came out and started development.

Third, the practice process

The first submission time is May 7, 2018

1. Stage 1: Implement the email sending API

  • The SMTP protocol is enabled on the mailbox. (It is recommended that you apply for a new mailbox and enable the SMTP service. The configuration process is not described.)
  • Use Express to send mails

The completion of this phase is marked by the ability to call the interface with postman parameters and successfully send mail after starting the service.

2. Stage 2: UI part is completed

There’s nothing to say about the page section, just a simple reactive layout form that uses H5’s native form validation as a whole.

Because express interface URL and page routing are used at the same time, there is a conflict in page rendering, and the server side rendering is used to deal with this problem. Of course, the rendering here does not use too many page variables, and directly returns the HTML page.

Let’s do the simplest demo

const express = require('express')
const router = express.Router()

router.get('/'.(req, res, next) = > {
  res.render('submit/index.html')})Copy the code

The completion mark is the ability to send an email via page entry, by which point the project is more than half complete.

3. Stage 3: Completion of automated tests

I happened to have used mocha automated test before, but I haven’t built the environment by myself. This time I had the opportunity to build the environment by myself, and the overall difficulty of the environment building process was not high. After that, I also tested the test coverage with Istanbul and improved several test cases based on the results.

The current coverage of the Istanbul test is shown below:

For those of you who are interested in test coverage, I recommend the Istanbul Tutorial, a code coverage tool.

I also recommend a nice github badge, which can be obtained from https://coveralls.io/ after writing the automated test case (Juejin does not support direct display, only a screenshot…).

4. Stage 4: Obfuscate and encrypt default email information

The Simple Mail Transfer Protocol (SMTP) is used to send emails. It can send plain text emails, HTML emails, and emails with attachments. The SMTP service is disabled by default. If the SMTP service is enabled, you can use the email address and the authorization code to automatically send emails. The authorization code is a password for logging in to third-party clients.

Simply put, if you want someone to send emails for you, but you don’t want them to log on to your email and see your email history, you need an authorization code that only gives them authorization to send emails for you.

Obfuscation encryption (here we are at last) actually encrypts the configured mail-related information. In this case, obfuscation encryption basically changes the code to an unreadable form. Of course, later also thought of the method of decryption, here is not self-exposure…

For more details, see the project’s readme.md.

Fourth, summary thinking

The best thing about the wheel is that you can choose from a variety of interesting open source libraries. Of course, there will always be pits. If you try and fail, try another way to continue to try. What? Be frightened by this trouble? Don’t you do it out of love?

Let’s also summarize the shortcomings of this project (ahem, I will make two simple points).

  1. Learn from the best. You don’t have to go to a teacher. There are many excellent open source projects on the Internet, so you can learn from them simply by doing something. Don’t just keep your head down and work hard.

  2. Planning is important. I remember that I listed the functions to be developed in the next period of time at one time. I was in an orderly and busy state after work every night, and the project produced almost every day. However, the day without planning constraints, only know to learn something, related projects, articles casually read a few hours in the past, then look at the results may be limited or even no output.

I almost forgot, this is my GitHub project address, see this, do not like before leaving?

I’m a bit slow on the road to technology, but I hope I can stick to it and go further

END

This article is participating in the “Nuggets 2021 Spring Recruitment Campaign”, click to see the details of the campaign