-
Notifications
You must be signed in to change notification settings - Fork 0
/
sendEmail.ts
95 lines (90 loc) · 2.34 KB
/
sendEmail.ts
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import { ActionDefinition, ActionContext, OutputObject } from 'connery';
import nodemailer from 'nodemailer';
const actionDefinition: ActionDefinition = {
key: 'sendEmail',
name: 'Send email',
description: 'Send an email to the recipient with the specified subject and body.',
type: 'create',
inputParameters: [
{
key: 'gmailEmailAddress',
name: 'Gmail email address',
description: 'Gmail email address to login with and send emails from.',
type: 'string',
validation: {
required: true,
},
},
{
key: 'gmailAppPassword',
name: 'Gmail app password',
description:
'Since Gmail does not allow to login with a password, you need to create an app password for your Gmail account. See https://support.google.com/accounts/answer/185833?hl=en for more information.',
type: 'string',
validation: {
required: true,
},
},
{
key: 'senderName',
name: 'Sender name',
description: 'The name of the sender that will appear in the email.',
type: 'string',
validation: {
required: true,
},
},
{
key: 'recipient',
name: 'Email Recipient',
description: 'Email address of the email recipient.',
type: 'string',
validation: {
required: true,
},
},
{
key: 'subject',
name: 'Email Subject',
description: 'Subject of the email.',
type: 'string',
validation: {
required: true,
},
},
{
key: 'body',
name: 'Email Body',
description: 'Body of the email.',
type: 'string',
validation: {
required: true,
},
},
],
operation: {
handler: handler,
},
outputParameters: [],
};
export default actionDefinition;
export async function handler({ input }: ActionContext): Promise<OutputObject> {
// Create a reusable transporter object using the SMTP transport
let transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: input.gmailEmailAddress,
pass: input.gmailAppPassword,
},
});
// Email content
let mailOptions = {
from: `"${input.senderName}" <${input.gmailEmailAddress}>`,
to: input.recipient,
subject: input.subject,
text: input.body,
};
// Send the email
await transporter.sendMail(mailOptions);
return {};
}