Skip to content
This repository has been archived by the owner on Aug 9, 2021. It is now read-only.

Commit

Permalink
Emailjs (#346)
Browse files Browse the repository at this point in the history
* switch to emailjs
  • Loading branch information
GP authored Feb 4, 2021
1 parent a6f6d45 commit 98f8665
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 36 deletions.
3 changes: 2 additions & 1 deletion config/app_TEMPLATE.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ const s3 = {
};

const smtpDetails = {
from: "localhost",
host: "localhost",
port: 25,
tls: true,
from_name: "Cacophony Reporting"
//
// service: "gmail",
Expand Down
31 changes: 12 additions & 19 deletions emailUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ import { Recording } from "./models/Recording";
import { TrackTag } from "./models/TrackTag";
import log from "./logging";
import moment, { Moment } from "moment";
import nodemailer from "nodemailer";
import Mail from "nodemailer/lib/mailer";
import { SentMessageInfo } from "nodemailer/lib/smtp-connection";
import { SMTPClient, Message } from "emailjs";

function alertBody(
recording: Recording,
Expand All @@ -29,26 +27,21 @@ async function sendEmail(
to: string,
subject: string
): Promise<boolean> {
const transporter: Mail = nodemailer.createTransport(config.smtpDetails);
const client = new SMTPClient(config.smtpDetails);

var mailOptions: Mail.Options = {
from: config.smtpDetails.from_name,
to: to,
subject: subject,
html: html,
text: text
};
try {
const info: SentMessageInfo = await transporter.sendMail(mailOptions);
if (info.rejected.length > 0) {
log.error(info);
return false;
}
} catch (error) {
log.error(error);
const message = new Message({
text: text,
from: config.smtpDetails.from_name,
to: to,
subject: subject,
attachment: [{ data: text, alternative: true }]
});
await client.sendAsync(message);
} catch (err) {
log.error(err);
return false;
}

return true;
}

Expand Down
18 changes: 5 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
"@types/express-validator": "^3.0.0",
"@types/jsonwebtoken": "^8.3.8",
"@types/moment-timezone": "^0.5.13",
"@types/nodemailer": "^6.4.0",
"apidoc": "^0.17.7",
"aws-sdk": "^2.653.0",
"bcrypt": "^3.0.8",
"body-parser": "^1.19.0",
"commander": "^2.20.3",
"emailjs": "^3.4.0",
"express": "^4.17.1",
"express-validator": "^5.3.1",
"express-winston": "^2.5.0",
Expand All @@ -36,7 +36,6 @@
"node-cmd": "^1.1.1",
"node-gyp": "^4.0.0",
"node-pre-gyp": "^0.10.2",
"nodemailer": "^6.4.16",
"passport": "^0.3.2",
"passport-anonymous": "^1.0.1",
"passport-jwt": "^4.0.0",
Expand Down
1 change: 0 additions & 1 deletion report-service-errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ const winston = require("winston");
import eventUtil from "./api/V1/eventUtil";
import moment, { Moment } from "moment";
import { ServiceErrorMap } from "./api/V1/systemError";
import nodemailer from "nodemailer";
import { sendEmail } from "./emailUtil";

async function main() {
Expand Down

0 comments on commit 98f8665

Please sign in to comment.