-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
the ability to send multipart mime messages with base64 encoding (#209)
* the ability to send multipart mime messages with base64 encoding * the ability to send multipart mime messages with base64 encoding * test, fixed sending the HTML body * cosmetic * removed usused import * fixed violations
- Loading branch information
Showing
10 changed files
with
153 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
...roovy/com/agorapulse/micronaut/amazon/awssdk/ses/SimpleEmailServiceIntegrationSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Copyright 2018-2024 Agorapulse. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.agorapulse.micronaut.amazon.awssdk.ses | ||
|
||
import com.agorapulse.gru.Gru | ||
import com.agorapulse.gru.minions.JsonMinion | ||
import com.agorapulse.micronaut.amazon.awssdk.itest.localstack.LocalstackContainerHolder | ||
import com.fasterxml.jackson.databind.ObjectMapper | ||
import io.micronaut.context.annotation.Property | ||
import io.micronaut.test.extensions.spock.annotation.MicronautTest | ||
import jakarta.inject.Inject | ||
import software.amazon.awssdk.services.ses.SesClient | ||
import spock.lang.Specification | ||
import spock.lang.TempDir | ||
|
||
import static org.testcontainers.containers.localstack.LocalStackContainer.Service.SES | ||
|
||
/** | ||
* Tests for simple email service. | ||
*/ | ||
@MicronautTest | ||
@Property(name = 'aws.ses.use-base64-encoding-for-multipart-emails', value = 'true') | ||
@Property(name = 'localstack.tag', value = '3.0.2') | ||
class SimpleEmailServiceIntegrationSpec extends Specification { | ||
|
||
@TempDir File tempDir | ||
|
||
@Inject SimpleEmailService simpleEmailService | ||
@Inject SesClient sesClient | ||
@Inject LocalstackContainerHolder localstack | ||
@Inject ObjectMapper objectMapper | ||
|
||
void "send email with attachemnt and base64 settings"() { | ||
given: | ||
sesClient.verifyDomainIdentity { it.domain('groovycalamari.com') } | ||
|
||
File file = new File(tempDir, 'test.testme') | ||
file << 'Hello!' | ||
|
||
when: | ||
Map<String, String> customTags = [key1: 'value1', key2: 'value2'] | ||
TransactionalEmail transactionalEmail = SimpleEmailService.email { | ||
subject 'Hi Paul' | ||
from '[email protected]' | ||
to '[email protected]' | ||
htmlBody '<p>This is an example body</p>' | ||
tags customTags | ||
attachment { | ||
filename 'test.testme' | ||
filepath file.absolutePath | ||
mimeType 'x-application/testme' | ||
description 'An example file' | ||
} | ||
} | ||
|
||
EmailDeliveryStatus status = simpleEmailService.send(transactionalEmail) | ||
|
||
then: | ||
status == EmailDeliveryStatus.STATUS_DELIVERED | ||
|
||
when: | ||
Gru gru = Gru.create(localstack.getEndpointOverride(SES).toString()) | ||
|
||
gru.test { | ||
get('/_aws/ses') | ||
expect { | ||
json 'emails.json' | ||
} | ||
} | ||
|
||
then: | ||
gru.verify() | ||
|
||
when: | ||
String content = gru.squad.ask(JsonMinion) { JsonMinion minion -> minion.responseText } | ||
|
||
then: | ||
content | ||
|
||
when: | ||
Map messagesResponse = objectMapper.readValue(content, Map) | ||
String rawData = messagesResponse['messages'][0]['RawData'] | ||
File emailFile = new File(tempDir, 'email.eml') | ||
emailFile << rawData | ||
|
||
then: | ||
// you can inspect the file here using Desktop.getDesktop().open(emailFile) | ||
noExceptionThrown() | ||
} | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
.../com/agorapulse/micronaut/amazon/awssdk/ses/SimpleEmailServiceIntegrationSpec/emails.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"messages": [ | ||
{ | ||
"Id": "${json-unit:any-string}", | ||
"Region": "us-east-1", | ||
"Source": "[email protected]", | ||
"RawData": "${json-unit:any-string}", | ||
"Timestamp": "${json-unit:any-string}" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters