Skip to content

Instantly share code, notes, and snippets.

View recursivecodes's full-sized avatar
💯
Living the dream

Todd Sharp recursivecodes

💯
Living the dream
View GitHub Profile
@recursivecodes
recursivecodes / test-text-email.sh
Created February 28, 2022 18:03
test-text-email.sh
$ curl localhost:8080/email
Email sent.
@recursivecodes
recursivecodes / EmailController.java
Created February 28, 2022 18:03
EmailController.java
@Post(uri="/attachment", produces="text/plain", consumes = MediaType.MULTIPART_FORM_DATA)
public String attachment(CompletedFileUpload file) throws IOException {
Email.Builder emailBuilder = Email.builder()
.to("pipar27174@shackvine.com")
.subject("Micronaut Email Attachment Test: " + LocalDateTime.now())
.body("This is an email")
.attachment(
Attachment.builder()
.filename(file.getFilename())
.contentType(file.getContentType().isPresent() ? file.getContentType().get().toString() : MediaType.APPLICATION_OCTET_STREAM)
@recursivecodes
recursivecodes / email.html
Created February 28, 2022 18:03
email.html
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<body>
<p>
Hello, <span th:text="${name}"></span>!
</p>
</body>
@recursivecodes
recursivecodes / test-email-attachment.sh
Created February 28, 2022 18:03
test-email-attachment.sh
$ curl -X POST \
-H "Content-Type: multipart/form-data" \
-F "file=@/Users/trsharp/Pictures/demo/apple.jpg" \
localhost:8080/email/attachment
Email sent.
@recursivecodes
recursivecodes / EmailController.java
Created February 28, 2022 18:03
EmailController.java
@Get(uri="/template/{name}", produces="text/plain")
public String template(@PathVariable String name) {
Map model = CollectionUtils.mapOf("name", name);
Email.Builder emailBuilder = Email.builder()
.to("pipar27174@shackvine.com")
.subject("Micronaut Email Template Test: " + LocalDateTime.now())
.body(new TemplateBody<>(BodyType.HTML, new ModelAndView<>("email", model)));
emailSender.send(emailBuilder);
return "Email sent.";
}
@recursivecodes
recursivecodes / EmailController.java
Created February 28, 2022 18:03
EmailController.java
@Controller("/email")
public class EmailController {
private final EmailSender emailSender;
public EmailController(EmailSender emailSender) {
this.emailSender = emailSender;
}
}
@recursivecodes
recursivecodes / test-templated-email.sh
Created February 28, 2022 18:03
test-templated-email.sh
$ curl localhost:8080/email/template/Todd%20Sharp
Email sent.
@recursivecodes
recursivecodes / OciSessionProvider.java
Created February 28, 2022 18:03
OciSessionProvider.java
@Singleton
public class OciSessionProvider implements SessionProvider {
private final Properties properties;
private final String user;
private final String password;
public OciSessionProvider(
MailPropertiesProvider properties,
@Property(name = "codes.recursive.smtp.user") String user,
@Property(name = "codes.recursive.smtp.password") String password
@recursivecodes
recursivecodes / application.yml
Created February 28, 2022 18:03
application.yml
javamail:
properties:
mail:
smtp:
port: 587
auth: true
starttls:
enable: true
host:
@recursivecodes
recursivecodes / application.yml
Created February 28, 2022 18:03
application.yml
micronaut:
application:
name: mnOciEmail
email:
from:
email: default@email.com
name: Email User