Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating Java SDK to include inline attachments #41591

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions sdk/communication/azure-communication-email/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
# Release History

## 1.1.0-beta.1 (Unreleased)
## 1.1.0-beta.1 (2024-08-14)

### Features Added

### Breaking Changes

### Bugs Fixed

- An `EmailMessage` with null recipient addresses can no longer be sent.

### Other Changes

- Consumers can now provide a value for the `ContentId` property when sending emails with attachments.
This allows consumers to reference attachments in the email body using the `cid` scheme. The `ContentId` property can be set on the `EmailAttachment` object.

## 1.0.15 (2024-07-26)

Expand Down
33 changes: 33 additions & 0 deletions sdk/communication/azure-communication-email/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ This package contains the Java SDK for Azure Communication Services for Email.
To create these resources, you can use the [Azure Portal][communication_resource_create_portal], the [Azure PowerShell][communication_resource_create_power_shell], or the [.NET management client library][communication_resource_create_net].

### Include the package

#### Include the BOM file

Please include the azure-sdk-bom to your project to take dependency on the General Availability (GA) version of the library. In the following snippet, replace the {bom_version_to_target} placeholder with the version number.
Expand Down Expand Up @@ -46,20 +47,24 @@ and then include the direct dependency in the dependencies section without the v
```

#### Include direct dependency

If you want to take dependency on a particular version of the library that is not present in the BOM,
add the direct dependency to your project as follows.

[//]: # ({x-version-update-start;com.azure:azure-communication-email;current})

```xml
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-communication-email</artifactId>
<version>1.0.4</version>
</dependency>
```

[//]: # ({x-version-update-end})

## Key concepts

> More details coming soon.

## Examples
Expand Down Expand Up @@ -91,6 +96,7 @@ EmailClient emailClient = new EmailClientBuilder()
```

### Azure Active Directory Token Authentication

A `DefaultAzureCredential` object must be passed to the `EmailClientBuilder` via the `credential()` method. An endpoint must also be set via the `endpoint()` method.

The `AZURE_CLIENT_SECRET`, `AZURE_CLIENT_ID`, and `AZURE_TENANT_ID` environment variables are needed to create a `DefaultAzureCredential` object.
Expand Down Expand Up @@ -187,7 +193,34 @@ PollResponse<EmailSendResult> response = poller.waitForCompletion();
System.out.println("Operation Id: " + response.getValue().getId());
```

### Send Email with Inline Attachments

Azure Communication Services support sending inline attachments.
Adding an optional `contentId` parameter to an `EmailAttachment` will make the attachment an inline attachment.

```java readme-sample-sendEmailWithInlineAttachment
BinaryData attachmentContent = BinaryData.fromFile(new File("C:/attachment.txt").toPath());
EmailAttachment attachment = new EmailAttachment(
"inlineimage.jpg",
"image/jpeg",
attachmentContent
).setContentId("inline_image");

EmailMessage message = new EmailMessage()
.setSenderAddress("<sender-email-address>")
.setToRecipients("<recipient-email-address>")
.setSubject("test subject")
.setBodyHtml("<h1>test message<img src=\"cid:inline_image\"></h1>")
.setAttachments(attachment);

SyncPoller<EmailSendResult, EmailSendResult> poller = emailClient.beginSend(message);
PollResponse<EmailSendResult> response = poller.waitForCompletion();

System.out.println("Operation Id: " + response.getValue().getId());
```

## Troubleshooting

> More details coming soon,

## Next steps
Expand Down
2 changes: 1 addition & 1 deletion sdk/communication/azure-communication-email/assets.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"AssetsRepo": "Azure/azure-sdk-assets",
"AssetsRepoPrefixPath": "java",
"TagPrefix": "java/communication/azure-communication-email",
"Tag": "java/communication/azure-communication-email_e70471d340"
"Tag": "java/communication/azure-communication-email_50f2f82209"
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

import java.time.Duration;
import java.util.ArrayList;
import java.util.Base64;
import java.util.List;
import java.util.Objects;

Expand Down Expand Up @@ -93,11 +92,21 @@ PollerFlux<EmailSendResult, EmailSendResult> beginSend(EmailMessage message, Con
if (message.getAttachments() != null) {
attachmentsImpl = new ArrayList<>();
for (EmailAttachment attachment: message.getAttachments()) {
attachmentsImpl.add(new com.azure.communication.email.implementation.models.EmailAttachment(
com.azure.communication.email.implementation.models.EmailAttachment attachmentImpl = null;

attachmentImpl = new com.azure.communication.email.implementation.models.EmailAttachment(
attachment.getName(),
attachment.getContentType(),
Base64.getEncoder().encodeToString(attachment.getContent().toBytes())
));
attachment.getContentInBase64()
);

String contentId = attachment.getContentId();

if (contentId != null) {
attachmentImpl.setContentId(contentId);
}

attachmentsImpl.add(attachmentImpl);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@

import com.azure.core.util.ServiceVersion;

/** Service version of AzureCommunicationServicesClient. */
/** Service version of EmailCommunicationServicesClient. */
public enum EmailServiceVersion implements ServiceVersion {
/** Enum value 2023-03-31. */
V2023_03_31("2023-03-31");
V2023_03_31("2023-03-31"),

/** Enum value 2024-07-01-preview. */
V2024_07_01_Preview("2024-07-01-preview");

private final String version;

Expand All @@ -28,6 +31,6 @@ public String getVersion() {
* @return The latest {@link EmailServiceVersion}.
*/
public static EmailServiceVersion getLatest() {
return V2023_03_31;
return V2024_07_01_Preview;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public final class AzureCommunicationEmailServiceImpl {

/**
* Gets The communication resource, for example https://my-resource.communication.azure.com.
*
*
* @return the endpoint value.
*/
public String getEndpoint() {
Expand All @@ -36,7 +36,7 @@ public String getEndpoint() {

/**
* Gets Api Version.
*
*
* @return the apiVersion value.
*/
public String getApiVersion() {
Expand All @@ -50,7 +50,7 @@ public String getApiVersion() {

/**
* Gets The HTTP pipeline to send requests through.
*
*
* @return the httpPipeline value.
*/
public HttpPipeline getHttpPipeline() {
Expand All @@ -64,7 +64,7 @@ public HttpPipeline getHttpPipeline() {

/**
* Gets The serializer to serialize an object into a string.
*
*
* @return the serializerAdapter value.
*/
public SerializerAdapter getSerializerAdapter() {
Expand All @@ -78,7 +78,7 @@ public SerializerAdapter getSerializerAdapter() {

/**
* Gets the EmailsImpl object to access its operations.
*
*
* @return the EmailsImpl object.
*/
public EmailsImpl getEmails() {
Expand All @@ -87,7 +87,7 @@ public EmailsImpl getEmails() {

/**
* Initializes an instance of AzureCommunicationEmailService client.
*
*
* @param endpoint The communication resource, for example https://my-resource.communication.azure.com.
* @param apiVersion Api Version.
*/
Expand All @@ -98,7 +98,7 @@ public EmailsImpl getEmails() {

/**
* Initializes an instance of AzureCommunicationEmailService client.
*
*
* @param httpPipeline The HTTP pipeline to send requests through.
* @param endpoint The communication resource, for example https://my-resource.communication.azure.com.
* @param apiVersion Api Version.
Expand All @@ -109,7 +109,7 @@ public EmailsImpl getEmails() {

/**
* Initializes an instance of AzureCommunicationEmailService client.
*
*
* @param httpPipeline The HTTP pipeline to send requests through.
* @param serializerAdapter The serializer to serialize an object into a string.
* @param endpoint The communication resource, for example https://my-resource.communication.azure.com.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ public AzureCommunicationEmailServiceImplBuilder retryPolicy(RetryPolicy retryPo
public AzureCommunicationEmailServiceImpl buildClient() {
this.validateClient();
HttpPipeline localPipeline = (pipeline != null) ? pipeline : createHttpPipeline();
String localApiVersion = (apiVersion != null) ? apiVersion : "2023-03-31";
String localApiVersion = (apiVersion != null) ? apiVersion : "2024-07-01-preview";
SerializerAdapter localSerializerAdapter
= (serializerAdapter != null) ? serializerAdapter : JacksonAdapter.createDefaultSerializerAdapter();
AzureCommunicationEmailServiceImpl client = new AzureCommunicationEmailServiceImpl(localPipeline,
Expand Down
Loading