forked from DavideD/quarkus-quickstarts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExtraMailResource.java
59 lines (50 loc) · 1.57 KB
/
ExtraMailResource.java
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
package org.acme.extra;
import io.quarkus.mailer.Mail;
import io.quarkus.mailer.MailTemplate;
import io.quarkus.mailer.Mailer;
import io.quarkus.qute.CheckedTemplate;
import io.quarkus.qute.Location;
import io.smallrye.common.annotation.Blocking;
import io.smallrye.mutiny.Uni;
import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
@Path("/extra")
public class ExtraMailResource {
@Inject
Mailer mailer;
@GET
@Path("/attachment")
@Blocking
public void sendEmailWithAttachment() {
mailer.send(Mail.withText("[email protected]", "An email from quarkus with attachment",
"This is my body")
.addAttachment("my-file-1.txt",
"content of my file".getBytes(), "text/plain")
);
}
@CheckedTemplate
static class Templates {
public static native MailTemplate.MailTemplateInstance hello(String name); // <1>
}
@GET
@Path("/template")
public Uni<Void> sendTypeSafeTemplate() {
// the template looks like: Hello {name}!
return Templates.hello("John")
.to("[email protected]")
.subject("Hello from Qute template")
.send();
}
@Inject
@Location("foo")
MailTemplate foo; // <1>
@GET
@Path("/template2")
public Uni<Void> sendTemplate2() {
return foo.to("[email protected]") // <2>
.subject("Hello from Qute template")
.data("name", "John") // <3>
.send(); // <4>
}
}