-
Notifications
You must be signed in to change notification settings - Fork 1
/
oJobEmail.yaml
148 lines (134 loc) · 5.46 KB
/
oJobEmail.yaml
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# oJob Email
# Copyright 2023 Nuno Aguiar
jobs:
## ------------
## Send email
## ------------
- name : oJob Send email
typeArgs :
noLog : false
shortcut:
name : email
keyArg: subject
args :
server : server
port : port
from : from
to : to
cc : cc
bcc : bcc
isHTML : isHTML
output : output
altOutput : altOutput
credentials : credentials
useSSL : useSSL
useTLS : useTLS
embedFiles : embedFiles
addAttachments: addAttachments
addImages : addImages
embedURLs : embedURLs
debug : debug
help :
text : This job tries to send an email.
expects:
- name: server
desc: (String) The email server to use
- name: port
desc: (Number) The email server port to use
- name: from
desc: (String) The email from address
- name: to
desc: (Array) The email to addresses
- name: cc
desc: (Array) The email cc addresses
- name: bcc
desc: (Array) The email bcc addresses
- name: isHTML
desc: (Boolean) Specifies if the email is in HTML format
- name: output
desc: (String) The email body message (a hbs template using args as data)
- name: altOutput
desc: (String) The email body alternative message (defaults to message)
- name: credentials
desc: (Map) The email server credentials (user and pass)
- name: useSSL
desc: (Boolean) If the email server uses SSL
- name: useTLS
desc: (Boolean) If the email server uses TLS
- name: embedFiles
desc: (Array) Array of maps (with file and name) to embeded on the email
- name: addAttachments
desc: (Array) Array of maps (with file, isInLine, name) to attach on the email
- name: addImages
desc: (Array) Array of urls to images (only available if isHTML = true)
- name: embedURLs
desc: (Array) Array of maps (with url and name) to embeded on the email
- name: subject
desc: (String) The email subject (a hbs template using args as data)
- name: debug
desc: (Boolean) Determines if it should debug the process
exec : |
if (isString(args.to)) args.to = [ String(args.to) ];
if (isString(args.cc)) args.cc = [ args.cc ];
if (isString(args.bcc)) args.bcc = [ args.bcc ];
var cL = (l) => {
for(var o in l) {
l[o] = String(l[o]);
}
};
_$(args.server).isString().$_("Please provide an email server.");
_$(args.from).isString().$_("Please provide a from email address.");
_$(args.to).isArray().$_("Please provide the to email addresses.");
_$(args.subject).isString().$_("Please provide a subject.");
_$(args.output).isString().$_("Please provide an output.");
cL(args.to);
cL(args.cc);
cL(args.bcc);
args.cc = _$(args.cc).isArray().default([]);
args.bcc = _$(args.bcc).isArray().default([]);
args.debug = _$(args.debug).isBoolean().default(void 0);
args.port = _$(args.port).isNumber().default(void 0);
args.useSSL = _$(args.useSSL).isBoolean().default(true);
args.useTLS = _$(args.useTLS).isBoolean().default(false);
args.embedFiles = _$(args.embedFiles).isArray().default(void 0);
args.embedURLs = _$(args.embedURLs).isArray().default(void 0);
args.addImages = _$(args.addImages).isArray().default(void 0);
args.isHTML = _$(args.isHTML).isBoolean().default(false);
args.altOutput = _$(args.altOutput).isString().default(args.output);
args.credentials = _$(args.credentials).isMap().default(void 0);
plugin("Email");
var email = new Email(args.server, args.from, args.useSSL, args.useTLS, args.isHTML);
if (isDef(args.port)) email.setPort(args.port);
email.setCharset("UTF-8");
if (isDef(args.credentials)) email.setCredentials(args.credentials.user, args.credentials.pass);
if (args.debug) email.getEmailObj().setDebug(true);
if (isDef(args.embedFiles)) {
for(var ii in args.embedFiles) {
email.embedFile(args.embedFiles[ii].file, args.embedFiles[ii].name);
};
}
if (isDef(args.embedURLs)) {
for(var ii in args.embedURLs) {
email.embedURL(args.embedURLs[ii].url, args.embedURLs[ii].name);
};
}
if (isDef(args.addAttachments)) {
for(var ii in args.addAttachments) {
email.addAttachment(args.addAttachments[ii].file, args.addAttachments[ii].isInLine, void 0, args.addAttachments[ii].name);
};
}
if (isDef(args.addImages)) {
for(var ii in args.addImages) {
email.addExternalImage(args.addImages[ii]);
};
}
if (args.isHTML) {
email.setHTML(templify(args.output, args));
} else {
email.setMessage(templify(args.output, args));
}
try {
args.result = email.send(templify(args.subject, args), templify(args.altOutput, args), args.to, args.cc, args.bcc, args.from);
} catch(e) {
e.javaException.printStackTrace();
}