sending emails when new post to profiles
This commit is contained in:
53
notifications.js
Normal file
53
notifications.js
Normal file
@@ -0,0 +1,53 @@
|
||||
const nodemailer = require("nodemailer");
|
||||
const DBGetter = require("./mongoDB.js");
|
||||
|
||||
const Notifications = {
|
||||
async sendEmail(to, subject, html) {
|
||||
// create reusable transporter object using the default SMTP transport
|
||||
let transporter = nodemailer.createTransport({
|
||||
host: "mail.emmint.com",
|
||||
port: 465,
|
||||
secure: true, // true for 465, false for other ports
|
||||
auth: {
|
||||
user: "noreply@emmint.com", // generated ethereal user
|
||||
pass: process.env.EMAILPASS, // generated ethereal password
|
||||
},
|
||||
});
|
||||
|
||||
// send mail with defined transport object
|
||||
let info = await transporter.sendMail({
|
||||
from: '"EMI Social" <noreply@emmint.com', // sender address
|
||||
to, // list of receivers
|
||||
subject, // Subject line
|
||||
//text: "Hello world?", // plain text body
|
||||
html, // html body
|
||||
});
|
||||
|
||||
console.log("Message sent: %s", info.messageId);
|
||||
},
|
||||
async youGotANewPost(toProfileId, whoPostedId, Message){
|
||||
const DB = await DBGetter.getDB;
|
||||
const profile = await DB.getProfileCache(toProfileId);
|
||||
const user = await DB.getUserById(profile.userid);
|
||||
const senderProfile = await DB.getProfileCache(whoPostedId);
|
||||
let subject = senderProfile.profile.firstName + " post on your profile";
|
||||
let message = `
|
||||
<p>Hello ${profile.profile.firstName},</p>
|
||||
|
||||
<p>You got a new post:</p>
|
||||
|
||||
<blockquote cite="https://social.emmint.com/">
|
||||
<p>${Message}</p>
|
||||
</blockquote>
|
||||
<figcaption>— ${senderProfile.profile.firstName} ${senderProfile.profile.lastName}</figcaption>
|
||||
|
||||
<p><a href="https://social.emmint.com/">Check it on the site</a></p>
|
||||
|
||||
<p>Blessings</p>
|
||||
|
||||
`;
|
||||
this.sendEmail(user.username, subject, message)
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Notifications
|
||||
Reference in New Issue
Block a user