diff --git a/backend/utils/sendnotification.js b/backend/utils/sendnotification.js index be3251c..81eac63 100644 --- a/backend/utils/sendnotification.js +++ b/backend/utils/sendnotification.js @@ -1,10 +1,8 @@ const scrapTheItems = require("./scraptheitems"); const convertToDate = require("./convertToDate"); -const sgMail = require("@sendgrid/mail"); -// should be process.env.SENDGRID_API_KEY -sgMail.setApiKey( - "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" -); +const AWS = require('aws-sdk'); +AWS.config.update({region: 'eu-central-1'}); + async function sendNotification(marketAlert) { const { id, email, olx_url, last_date } = marketAlert; @@ -18,16 +16,43 @@ async function sendNotification(marketAlert) { (mes, item) => mes + `${item.url} i ${item.price}`, "" ); - const msg = { - to: email, - from: "test@example.com", - subject: "Market Alert", - text: "New items on olx", - html: message + + // Create sendEmail params + var params = { + Destination: { /* required */ + CcAddresses: [ + ], + ToAddresses: [ + email + ] + }, + Message: { /* required */ + Body: { /* required */ + Html: { + Charset: "UTF-8", + Data: message + }, + Text: { + Charset: "UTF-8", + Data: message // TODO: convert to text + } + }, + Subject: { + Charset: 'UTF-8', + Data: 'Javimi alert' + } + }, + Source: 'info@saburly.com', /* required */ + ReplyToAddresses: [ + 'info@saburly.com', + ], }; + if (message) { - await sgMail.send(msg); + const sendPromise = new AWS.SES({apiVersion: '2010-12-01'}).sendEmail(params).promise(); + await sendPromise; return { id, date: String(convertToDate(lastDate)) }; } } + module.exports = sendNotification;