-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmailer.js
64 lines (57 loc) · 1.52 KB
/
mailer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import nodemailer from 'nodemailer';
import { isDev } from './utils.js';
const devOptions = {
host: process.env.NODEMAILER_HOST,
port: 2525,
auth: {
user: process.env.MAIL_TRAP_USER,
pass: process.env.MAIL_TRAP_PASS,
},
};
const options = {
service: 'gmail',
host: 'smtp.gmail.com',
port: 587,
secure: false,
auth: {
user: process.env.GMAIL_USER,
pass: process.env.GMAIL_PASS,
},
};
function getTransport() {
console.log(isDev() ? devOptions : options);
return nodemailer.createTransport(isDev() ? devOptions : options);
}
export async function sendReport(viableCars) {
console.log('::: sending mail report :::');
const transport = getTransport();
await transport.sendMail({
from: process.env.MAIL_FROM,
to: process.env.MAIL_TO,
subject: 'Your daily dose of auctions',
text: viableCars.length
? `This is a series of auctions you might be interested:
${viableCars
.map(
(car) => `
Auction ID: ${car.auctionId}
Auction date: ${car.auctionDate}
Vin: ${car.vin}
Title: ${car.title}
Make: ${car.make}
Model: ${car.model}
Color: ${car.color}
City: ${car.city}
Price: $${car.price}
ProQuote: $${car.proQuote.avg}
Year: ${car.year}
Odometer: ${car.odometer.value} miles
URL: https://app.acvauctions.com/auction/${car.auctionId}
`
)
.join('\n')}
Regards
`
: `Hello, we were not able to find any good matches in the current run. Enjoy your day.`,
});
}