embulk-output-send_email 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/{LICENSE.txt → LICENSE} +0 -0
- data/README.md +84 -74
- data/build.gradle +1 -1
- data/classpath/embulk-output-send_email-0.1.2.jar +0 -0
- data/example/config.yml +13 -6
- data/screenshots/logo.png +0 -0
- data/src/main/java/org/embulk/output/send_email/SendEmailOutputPlugin.java +331 -286
- metadata +5 -4
- data/classpath/embulk-output-send_email-0.1.0.jar +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1d743b7a2618d438df8a6540d7f5ad92fb7005a9754f7b45a326bf2016b277f7
|
4
|
+
data.tar.gz: 5598dbcd74d2308226b532f858eda91d36f835c4d41fe15575300a122431934f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ceca7db99426add847bf14ec4c44e04c8ee598ce314ed42d2177f2d241e3af2e0215bbb5eee3639307607d9a88176d4189ff42b796590146843a82ae55ac709b
|
7
|
+
data.tar.gz: 94e8863a4d8ac4fa4139db6035b9381aba8b0d2447b538ab8f6c04dbab2aa3e9e62d5f9d2035b7e2388930b9b2e5f8e91d85459529007e9bcfc47e999f973453
|
data/{LICENSE.txt → LICENSE}
RENAMED
File without changes
|
data/README.md
CHANGED
@@ -1,74 +1,84 @@
|
|
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
|
-
```
|
1
|
+
<p align="center">
|
2
|
+
<a href="https://www.infoobjects.com/" target="blank"><img src="screenshots/logo.png" width="150" alt="InfoObjects Logo" /></a>
|
3
|
+
</p>
|
4
|
+
<p align="center">Infoobjects is a consulting company that helps enterprises transform how and where they run applications and infrastructure.
|
5
|
+
From strategy, to implementation, to ongoing managed services, Infoobjects creates tailored cloud solutions for enterprises at all stages of the cloud journey.</p>
|
6
|
+
|
7
|
+
#Send email output plugin for Embulk
|
8
|
+
[](LICENSE)
|
9
|
+
|
10
|
+
An output plugin for Embulk to send email with data
|
11
|
+
|
12
|
+
## Configuration
|
13
|
+
|
14
|
+
- **send_email**: Required attribute for this output plugin
|
15
|
+
- **to**: To whom you want to send email mention the email ID(required)
|
16
|
+
- **from**: From which email ID you want to send (required)
|
17
|
+
- **password**: Password of your email ID from which you want to send (required)
|
18
|
+
- **port**: Port of email (for gmail its `587`)(required)
|
19
|
+
- **host**: Host of your email (For gmail `smtp.gmail.com`) (required)
|
20
|
+
- **row**: How many row you want to send with email mention like 1,2,3(required)
|
21
|
+
- **file_type**: Mention file type like (example: json,html) (required)
|
22
|
+
|
23
|
+
## Example - columns
|
24
|
+
|
25
|
+
Say input.csv is as follows:
|
26
|
+
|
27
|
+
|
28
|
+
```
|
29
|
+
year country_code country_name literacy_rate
|
30
|
+
|
31
|
+
1990 1 India 80%
|
32
|
+
1993 2 USA 83%
|
33
|
+
1997 3 JAPAN
|
34
|
+
1999 4 China 72%
|
35
|
+
2000 5 Ukraine 68%
|
36
|
+
2002 6 Italy 79%
|
37
|
+
2004 7 UK 75%
|
38
|
+
2011 8 NULL 42%
|
39
|
+
```
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
```yaml
|
44
|
+
out:
|
45
|
+
type: send_email
|
46
|
+
to: abc@example.com
|
47
|
+
from: abc@example.com
|
48
|
+
password: XXXXXX
|
49
|
+
port: 587
|
50
|
+
host: smtp.gmail.com
|
51
|
+
row: 3
|
52
|
+
filetype: html
|
53
|
+
```
|
54
|
+
|
55
|
+
|
56
|
+
## Development
|
57
|
+
|
58
|
+
Run example:
|
59
|
+
|
60
|
+
```
|
61
|
+
$ ./gradlew package
|
62
|
+
$ embulk run -I ./lib seed.yml
|
63
|
+
```
|
64
|
+
|
65
|
+
Deployment Steps:
|
66
|
+
|
67
|
+
```
|
68
|
+
Install ruby in your machine
|
69
|
+
$ gem install gemcutter (For windows OS)
|
70
|
+
|
71
|
+
$ ./gradlew gemPush
|
72
|
+
$ gem build NameOfYourPlugins (example: embulk-output-send_email)
|
73
|
+
$ gem push embulk-output-send_email-0.1.0.gem (You will get this name after running above command)
|
74
|
+
```
|
75
|
+
|
76
|
+
|
77
|
+
Release gem:
|
78
|
+
|
79
|
+
```
|
80
|
+
$ ./gradlew gemPush
|
81
|
+
```
|
82
|
+
## Licensing
|
83
|
+
|
84
|
+
InfoObjects [license](LICENSE) (MIT License)
|
data/build.gradle
CHANGED
Binary file
|
data/example/config.yml
CHANGED
@@ -3,7 +3,7 @@ exec:
|
|
3
3
|
min_output_tasks: 4
|
4
4
|
in:
|
5
5
|
type: file
|
6
|
-
path_prefix: C:\Users\Abhishek Gupta\Desktop\
|
6
|
+
path_prefix: C:\Users\Abhishek Gupta\Desktop\github\embulk-output-send_email\calendar.csv
|
7
7
|
parser:
|
8
8
|
type: csv
|
9
9
|
columns:
|
@@ -22,12 +22,19 @@ filters:
|
|
22
22
|
- {name: attr3, type: string}
|
23
23
|
out:
|
24
24
|
type: send_email
|
25
|
-
to:
|
26
|
-
|
27
|
-
|
25
|
+
to:
|
26
|
+
- ankit.kumar@infoobjects.com
|
27
|
+
- abhishek.gupta@infoobjects.com
|
28
|
+
from: abhishek.gupta@infoobjects.com
|
29
|
+
password: 11234
|
28
30
|
port: 587
|
31
|
+
username: abhishek.gupta@infoobjects.com
|
29
32
|
host: smtp.gmail.com
|
30
|
-
|
31
|
-
|
33
|
+
subject: XYZ123
|
34
|
+
# row: 3
|
35
|
+
file_type: html
|
36
|
+
protocol: TLSv1.2
|
37
|
+
auth: true
|
38
|
+
smtp_enable: true
|
32
39
|
|
33
40
|
|
Binary file
|
@@ -1,286 +1,331 @@
|
|
1
|
-
package org.embulk.output.send_email;
|
2
|
-
|
3
|
-
|
4
|
-
import java.util.*;
|
5
|
-
import
|
6
|
-
|
7
|
-
import
|
8
|
-
import
|
9
|
-
import
|
10
|
-
import javax.mail
|
11
|
-
import javax.mail.internet.
|
12
|
-
import javax.mail.internet.
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
@Config("
|
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
|
-
@Override
|
142
|
-
public void
|
143
|
-
if (pageReader.isNull(column)) {
|
144
|
-
map.put(column.getName(), "");
|
145
|
-
} else {
|
146
|
-
map.put(column.getName(), pageReader.
|
147
|
-
}
|
148
|
-
}
|
149
|
-
|
150
|
-
@Override
|
151
|
-
public void
|
152
|
-
if (pageReader.isNull(column)) {
|
153
|
-
map.put(column.getName(), "");
|
154
|
-
} else {
|
155
|
-
map.put(column.getName(), pageReader.
|
156
|
-
}
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
}
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
1
|
+
package org.embulk.output.send_email;
|
2
|
+
|
3
|
+
|
4
|
+
import java.util.*;
|
5
|
+
import java.util.stream.Collectors;
|
6
|
+
|
7
|
+
import com.fasterxml.jackson.databind.ObjectMapper;
|
8
|
+
import org.embulk.config.*;
|
9
|
+
import org.embulk.spi.*;
|
10
|
+
import javax.mail.*;
|
11
|
+
import javax.mail.internet.InternetAddress;
|
12
|
+
import javax.mail.internet.MimeBodyPart;
|
13
|
+
import javax.mail.internet.MimeMessage;
|
14
|
+
import javax.mail.internet.MimeMultipart;
|
15
|
+
import javax.validation.constraints.Null;
|
16
|
+
|
17
|
+
import static ch.qos.logback.core.joran.action.ActionConst.NULL;
|
18
|
+
|
19
|
+
public class SendEmailOutputPlugin
|
20
|
+
implements OutputPlugin {
|
21
|
+
public interface PluginTask
|
22
|
+
extends Task {
|
23
|
+
|
24
|
+
@Config("file_type")
|
25
|
+
@ConfigDefault("\"json\"")
|
26
|
+
public String getFileType();
|
27
|
+
|
28
|
+
@Config("to")
|
29
|
+
public List<String> getTO();
|
30
|
+
|
31
|
+
|
32
|
+
@Config("cc")
|
33
|
+
@ConfigDefault("[]")
|
34
|
+
public List<String> getCC();
|
35
|
+
|
36
|
+
@Config("from")
|
37
|
+
public String getFrom();
|
38
|
+
|
39
|
+
@Config("password")
|
40
|
+
@ConfigDefault("\"password\"")
|
41
|
+
public String getPassword();
|
42
|
+
|
43
|
+
@Config("port")
|
44
|
+
public String getPort();
|
45
|
+
|
46
|
+
@Config("subject")
|
47
|
+
public String getSubject();
|
48
|
+
|
49
|
+
@Config("auth")
|
50
|
+
@ConfigDefault("false")
|
51
|
+
public boolean getAuth();
|
52
|
+
|
53
|
+
@Config("host")
|
54
|
+
public String getHost();
|
55
|
+
|
56
|
+
@Config("protocol")
|
57
|
+
@ConfigDefault("\"TLSv1.2\"")
|
58
|
+
public String getProtocol();
|
59
|
+
|
60
|
+
@Config("row")
|
61
|
+
@ConfigDefault("-1")
|
62
|
+
public int getRow();
|
63
|
+
|
64
|
+
@Config("username")
|
65
|
+
@ConfigDefault("")
|
66
|
+
public String getUserName();
|
67
|
+
|
68
|
+
@Config("smtp_enable")
|
69
|
+
@ConfigDefault("true")
|
70
|
+
public String getSmtpEnable();
|
71
|
+
}
|
72
|
+
|
73
|
+
@Override
|
74
|
+
public ConfigDiff transaction(ConfigSource config,
|
75
|
+
Schema schema, int taskCount,
|
76
|
+
OutputPlugin.Control control) {
|
77
|
+
PluginTask task = config.loadConfig(PluginTask.class);
|
78
|
+
control.run(task.dump());
|
79
|
+
return Exec.newConfigDiff();
|
80
|
+
}
|
81
|
+
|
82
|
+
@Override
|
83
|
+
public ConfigDiff resume(TaskSource taskSource,
|
84
|
+
Schema schema, int taskCount,
|
85
|
+
OutputPlugin.Control control) {
|
86
|
+
throw new UnsupportedOperationException("myp output plugin does not support resuming");
|
87
|
+
}
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
@Override
|
92
|
+
public void cleanup(TaskSource taskSource,
|
93
|
+
Schema schema, int taskCount,
|
94
|
+
List<TaskReport> successTaskReports) {
|
95
|
+
}
|
96
|
+
|
97
|
+
@Override
|
98
|
+
public TransactionalPageOutput open(TaskSource taskSource, Schema schema, int taskIndex) {
|
99
|
+
PageReader pageReader;
|
100
|
+
PluginTask task = taskSource.loadTask(PluginTask.class);
|
101
|
+
pageReader = new PageReader(schema);
|
102
|
+
return new PageTransactionalOutput(task, pageReader, schema);
|
103
|
+
}
|
104
|
+
|
105
|
+
public static class PageTransactionalOutput implements TransactionalPageOutput {
|
106
|
+
PluginTask task;
|
107
|
+
PageReader pageReader;
|
108
|
+
Schema schema;
|
109
|
+
|
110
|
+
public PageTransactionalOutput(PluginTask task, PageReader pageReader, Schema schema) {
|
111
|
+
this.task = task;
|
112
|
+
this.pageReader = pageReader;
|
113
|
+
this.schema = schema;
|
114
|
+
}
|
115
|
+
|
116
|
+
@Override
|
117
|
+
public void add(Page page) {
|
118
|
+
ArrayList<LinkedHashMap<String, Object>> mapList = new ArrayList<>();
|
119
|
+
|
120
|
+
pageReader.setPage(page);
|
121
|
+
int rows = task.getRow();
|
122
|
+
if (task.getRow() == -1) {
|
123
|
+
rows = Integer.MAX_VALUE;
|
124
|
+
}
|
125
|
+
|
126
|
+
readingAndSettingDataToMap(pageReader, rows, mapList);
|
127
|
+
pageReader.close();
|
128
|
+
try {
|
129
|
+
Transport.send(prepareMessage(getSession(task), task.getFrom(), task.getTO(), task.getCC(), mapList, schema, task));
|
130
|
+
} catch (Exception e) {
|
131
|
+
e.printStackTrace();
|
132
|
+
throw new RuntimeException(e);
|
133
|
+
}
|
134
|
+
}
|
135
|
+
|
136
|
+
private void readingAndSettingDataToMap(PageReader pageReader, int rows, ArrayList<LinkedHashMap<String, Object>> mapList) {
|
137
|
+
while (pageReader.nextRecord() && rows-- > 0) {
|
138
|
+
LinkedHashMap<String, Object> map = new LinkedHashMap<>();
|
139
|
+
|
140
|
+
pageReader.getSchema().visitColumns(new ColumnVisitor() {
|
141
|
+
@Override
|
142
|
+
public void booleanColumn(Column column) {
|
143
|
+
if (pageReader.isNull(column)) {
|
144
|
+
map.put(column.getName(), "");
|
145
|
+
} else {
|
146
|
+
map.put(column.getName(), pageReader.getBoolean(column));
|
147
|
+
}
|
148
|
+
}
|
149
|
+
|
150
|
+
@Override
|
151
|
+
public void longColumn(Column column) {
|
152
|
+
if (pageReader.isNull(column)) {
|
153
|
+
map.put(column.getName(), "");
|
154
|
+
} else {
|
155
|
+
map.put(column.getName(), pageReader.getLong(column));
|
156
|
+
}
|
157
|
+
}
|
158
|
+
|
159
|
+
@Override
|
160
|
+
public void doubleColumn(Column column) {
|
161
|
+
if (pageReader.isNull(column)) {
|
162
|
+
map.put(column.getName(), "");
|
163
|
+
} else {
|
164
|
+
map.put(column.getName(), pageReader.getDouble(column));
|
165
|
+
}
|
166
|
+
|
167
|
+
}
|
168
|
+
|
169
|
+
@Override
|
170
|
+
public void stringColumn(Column column) {
|
171
|
+
if (pageReader.isNull(column)) {
|
172
|
+
map.put(column.getName(), "");
|
173
|
+
} else {
|
174
|
+
map.put(column.getName(), pageReader.getString(column));
|
175
|
+
}
|
176
|
+
}
|
177
|
+
|
178
|
+
@Override
|
179
|
+
public void timestampColumn(Column column) {
|
180
|
+
if (pageReader.isNull(column)) {
|
181
|
+
map.put(column.getName(), "");
|
182
|
+
} else {
|
183
|
+
map.put(column.getName(), pageReader.getTimestamp(column));
|
184
|
+
}
|
185
|
+
|
186
|
+
}
|
187
|
+
|
188
|
+
@Override
|
189
|
+
public void jsonColumn(Column column) {
|
190
|
+
if (pageReader.isNull(column)) {
|
191
|
+
map.put(column.getName(), "");
|
192
|
+
} else {
|
193
|
+
map.put(column.getName(), pageReader.getJson(column));
|
194
|
+
}
|
195
|
+
|
196
|
+
}
|
197
|
+
});
|
198
|
+
mapList.add(map);
|
199
|
+
}
|
200
|
+
}
|
201
|
+
|
202
|
+
private Session getSession(PluginTask task) {
|
203
|
+
try {
|
204
|
+
Properties properties = new Properties();
|
205
|
+
properties.put("mail.smtp.auth", task.getAuth());
|
206
|
+
properties.put("mail.smtp.starttls.enable", task.getSmtpEnable());
|
207
|
+
|
208
|
+
properties.put("mail.smtp.ssl.protocols", task.getProtocol());
|
209
|
+
properties.put("mail.smtp.host", task.getHost());
|
210
|
+
properties.put("mail.smtp.port", task.getPort());
|
211
|
+
|
212
|
+
if(task.getAuth()) {
|
213
|
+
|
214
|
+
return Session.getInstance(properties, new javax.mail.Authenticator() {
|
215
|
+
protected PasswordAuthentication getPasswordAuthentication() {
|
216
|
+
return new PasswordAuthentication(task.getFrom(), task.getPassword());
|
217
|
+
}
|
218
|
+
});
|
219
|
+
}else{
|
220
|
+
properties.put("mail.smtp.user", task.getUserName());
|
221
|
+
return Session.getDefaultInstance(properties);
|
222
|
+
}
|
223
|
+
} catch (Exception e) {
|
224
|
+
e.printStackTrace();
|
225
|
+
throw e;
|
226
|
+
}
|
227
|
+
}
|
228
|
+
|
229
|
+
private static Message prepareMessage(Session session, String from, List<String> to, List<String> cc, ArrayList<LinkedHashMap<String, Object>> mapList, Schema schema, PluginTask task) {
|
230
|
+
try {
|
231
|
+
String listStringCC=null;
|
232
|
+
String listStringTo = to.stream().map(Object::toString)
|
233
|
+
.collect(Collectors.joining(","));
|
234
|
+
if(!(cc.size() ==0)) {
|
235
|
+
listStringCC = cc.stream().map(Object::toString)
|
236
|
+
.collect(Collectors.joining(","));
|
237
|
+
}
|
238
|
+
Message message = new MimeMessage(session);
|
239
|
+
message.setFrom(new InternetAddress(from));
|
240
|
+
if(listStringCC!=null) {
|
241
|
+
message.addRecipients(Message.RecipientType.CC, InternetAddress.parse(listStringCC));
|
242
|
+
}
|
243
|
+
message.addRecipients(Message.RecipientType.TO, InternetAddress.parse(listStringTo));
|
244
|
+
message.setSubject(task.getSubject());
|
245
|
+
|
246
|
+
if (task.getFileType().equalsIgnoreCase("html")) {
|
247
|
+
setHtmlContent(message, mapList, schema);
|
248
|
+
} else if (task.getFileType().equalsIgnoreCase("json")) {
|
249
|
+
setJsonContent(message, mapList, schema);
|
250
|
+
}
|
251
|
+
return message;
|
252
|
+
} catch (Exception e) {
|
253
|
+
e.printStackTrace();
|
254
|
+
throw new RuntimeException(e);
|
255
|
+
}
|
256
|
+
}
|
257
|
+
|
258
|
+
private static void setHtmlContent(Message message, ArrayList<LinkedHashMap<String, Object>> mapList, Schema schema) {
|
259
|
+
|
260
|
+
try {
|
261
|
+
MimeMultipart multipart = new MimeMultipart();
|
262
|
+
BodyPart messageBodyPart = new MimeBodyPart();
|
263
|
+
StringBuilder email = new StringBuilder();
|
264
|
+
|
265
|
+
email.append("<!DOCTYPE html><html><body>"
|
266
|
+
+ "<table style='border:1px solid #96D4D4;border-collapse: collapse;width: 100%'>");
|
267
|
+
|
268
|
+
email.append("<tr>");
|
269
|
+
for (int i = 0; i < schema.size(); i++) {
|
270
|
+
email.append("<th style='border:2px solid black; border-collapse: collapse;border-color: #96D4D4'>");
|
271
|
+
email.append(schema.getColumn(i).getName().split("/")[0]);
|
272
|
+
email.append("</th>");
|
273
|
+
}
|
274
|
+
email.append("</tr>");
|
275
|
+
|
276
|
+
for (int i = 0; i < mapList.size(); i++) {
|
277
|
+
Map<String, Object> map = mapList.get(i);
|
278
|
+
email.append("<tr >");
|
279
|
+
for (Map.Entry<String, Object> entry : map.entrySet()) {
|
280
|
+
email.append("<td style='border:1px solid black;border-collapse: collapse;text-align:center;border-color: #96D4D4'>");
|
281
|
+
email.append(entry.getValue());
|
282
|
+
email.append("</td>");
|
283
|
+
}
|
284
|
+
email.append("<tr>");
|
285
|
+
}
|
286
|
+
email.append("</table></body></html>");
|
287
|
+
|
288
|
+
messageBodyPart.setContent(email.toString(), "text/html");
|
289
|
+
multipart.addBodyPart(messageBodyPart);
|
290
|
+
message.setContent(multipart);
|
291
|
+
} catch (Exception e) {
|
292
|
+
System.out.println("Not able to send data");
|
293
|
+
throw new RuntimeException(e);
|
294
|
+
}
|
295
|
+
|
296
|
+
}
|
297
|
+
|
298
|
+
private static void setJsonContent(Message message, ArrayList<LinkedHashMap<String, Object>> mapList, Schema schema) {
|
299
|
+
try {
|
300
|
+
ObjectMapper objectMapper = new ObjectMapper();
|
301
|
+
String value = null;
|
302
|
+
value = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(mapList);
|
303
|
+
message.setText(value);
|
304
|
+
} catch (Exception e) {
|
305
|
+
e.printStackTrace();
|
306
|
+
throw new RuntimeException(e);
|
307
|
+
}
|
308
|
+
|
309
|
+
}
|
310
|
+
|
311
|
+
@Override
|
312
|
+
public void finish() {
|
313
|
+
|
314
|
+
}
|
315
|
+
|
316
|
+
@Override
|
317
|
+
public void close() {
|
318
|
+
|
319
|
+
}
|
320
|
+
|
321
|
+
@Override
|
322
|
+
public void abort() {
|
323
|
+
|
324
|
+
}
|
325
|
+
|
326
|
+
@Override
|
327
|
+
public TaskReport commit() {
|
328
|
+
return null;
|
329
|
+
}
|
330
|
+
}
|
331
|
+
}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: embulk-output-send_email
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Infoobjects Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-09-
|
11
|
+
date: 2022-09-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -46,14 +46,14 @@ extensions: []
|
|
46
46
|
extra_rdoc_files: []
|
47
47
|
files:
|
48
48
|
- ".gitignore"
|
49
|
-
- LICENSE
|
49
|
+
- LICENSE
|
50
50
|
- README.md
|
51
51
|
- build.gradle
|
52
52
|
- calendar.csv
|
53
53
|
- classpath/activation-1.1.jar
|
54
54
|
- classpath/commons-codec-1.10.jar
|
55
55
|
- classpath/commons-logging-1.2.jar
|
56
|
-
- classpath/embulk-output-send_email-0.1.
|
56
|
+
- classpath/embulk-output-send_email-0.1.2.jar
|
57
57
|
- classpath/google-api-client-1.26.0.jar
|
58
58
|
- classpath/google-api-client-java6-1.26.0.jar
|
59
59
|
- classpath/google-api-services-gmail-v1-rev83-1.23.0.jar
|
@@ -76,6 +76,7 @@ files:
|
|
76
76
|
- gradlew
|
77
77
|
- gradlew.bat
|
78
78
|
- lib/embulk/output/send_email.rb
|
79
|
+
- screenshots/logo.png
|
79
80
|
- src/main/java/org/embulk/output/send_email/SendEmailOutputPlugin.java
|
80
81
|
- src/test/java/org/embulk/output/send_email/TestSendEmailOutputPlugin.java
|
81
82
|
homepage:
|
Binary file
|