Send email from front-end js file

In the release o.4, I will continue work my friend Secure Camera project in the Github.

I use socket.on Listening for client connections, the callback function will pass the socket for this connection.

For define an mailOptions object to store the mail properties.

This is Code I addin the trust.js

const transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: '',
pass: 'xxxxx'
router.socket.on('send email', function(emailInfo) {
let mailOptions = {
from: '',
to: `${}`,
html: '<p>An unknowned face is detected!!!</p>',
attachments: [
filename: 'face.png',
path: `${emailInfo.imgUrl}`,
cid: '123456789'
transporter.sendMail(mailOptions, (error, info) => {
if (error) {
return console.log(error);
console.log('Message %s sent: %s', info.messageId, info.response);

Code I add in deviceMesBox.js

function checkFace(imgUrl) {
let trustFacesObj = {
faceList: null,
faceInSnapshot: null
socket.emit('request trustFaces');
socket.on('get trustFaces', function(faceList) {
if (trustFacesObj.faceList === null) {
trustFacesObj.faceList = faceList;
faceList.forEach((element, index, array) => {
compareFaces(element.url, imgUrl, function(result) {
if (result) {
let firstFace = result.FaceMatches[0];
let similarity = firstFace.Similarity;
if (similarity < 70) {
let emailInfo = {} = $('#headerUserDropBtn').data('email');
emailInfo.imgUrl = imgUrl;
socket.emit('send email', emailInfo);

The code for this section is mainly to check whether the face image of the new camera is similar to the face of the trust. If the similarity is less than 70%, this triggers the function of sending mail to the user.

I this PR I have learned how to use Use of emit and on in

What is WebSocket?

1)Both WebSocket and HTTP are application layer protocols. Http is stateless, single-communication, the server has a message update can not be notified to the client in time (have done a similar snap-up function, you need to use polling to view the snap-up status).

2) Based on the TCP protocol, use HTTP/HTTPS to make a handshake request, and create a tcp connection.

3) SocketIO encapsulates WebSocket, AJAX and other communication methods into a unified communication interface.

In addition, we use the Google AI & Machine Learning Products API to process human face picture information. and the whole project is host on the Google cloud.