From 7d9e7bca1981df22865e0bfbe27563f81096ff75 Mon Sep 17 00:00:00 2001 From: Nate Kimball Date: Wed, 21 Aug 2024 13:43:40 -0700 Subject: [PATCH 01/16] updating Java SDK to include inline attachments --- .../azure-communication-email/README.md | 34 +++ ...eCommunicationEmailServiceImplBuilder.java | 2 +- .../email/implementation/EmailsImpl.java | 201 +++++++++++++++--- .../models/EmailAttachment.java | 53 ++++- .../implementation/models/EmailMessage.java | 8 +- .../communication/email/ReadmeSamples.java | 28 ++- .../email/EmailAsyncClientTests.java | 26 +++ .../communication/email/EmailClientTests.java | 25 +++ .../swagger/README.md | 2 +- 9 files changed, 333 insertions(+), 46 deletions(-) diff --git a/sdk/communication/azure-communication-email/README.md b/sdk/communication/azure-communication-email/README.md index a4edb96f1cd86..c6c288293cab7 100644 --- a/sdk/communication/azure-communication-email/README.md +++ b/sdk/communication/azure-communication-email/README.md @@ -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. @@ -46,10 +47,12 @@ 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 com.azure @@ -57,9 +60,11 @@ add the direct dependency to your project as follows. 1.0.4 ``` + [//]: # ({x-version-update-end}) ## Key concepts + > More details coming soon. ## Examples @@ -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. @@ -187,7 +193,35 @@ PollResponse 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:/inlineimage.jpg").toPath()); +EmailAttachment attachment = new EmailAttachment( + "inlineimage.jpg", + "image/jpeg", + BinaryData.fromString("test") +); +attachment.contentId = "inline_image"; + +EmailMessage message = new EmailMessage() + .setSenderAddress("") + .setToRecipients("") + .setSubject("test subject") + .setBodyHtml("

test message

") + .setAttachments(attachment); + +SyncPoller poller = emailClient.beginSend(message); +PollResponse response = poller.waitForCompletion(); + +System.out.println("Operation Id: " + response.getValue().getId()); +``` + ## Troubleshooting + > More details coming soon, ## Next steps diff --git a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/AzureCommunicationEmailServiceImplBuilder.java b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/AzureCommunicationEmailServiceImplBuilder.java index e137a68563111..43be1e9fe8065 100644 --- a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/AzureCommunicationEmailServiceImplBuilder.java +++ b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/AzureCommunicationEmailServiceImplBuilder.java @@ -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, diff --git a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/EmailsImpl.java b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/EmailsImpl.java index df2d549ddb87a..801b3ad1928fc 100644 --- a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/EmailsImpl.java +++ b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/EmailsImpl.java @@ -4,10 +4,11 @@ package com.azure.communication.email.implementation; +import com.azure.communication.email.EmailSendResult; import com.azure.communication.email.implementation.models.EmailMessage; import com.azure.communication.email.implementation.models.EmailSendResult; -import com.azure.communication.email.implementation.models.EmailsGetSendResultResponse; -import com.azure.communication.email.implementation.models.EmailsSendResponse; +import com.azure.communication.email.implementation.models.EmailsGetSendResultHeaders; +import com.azure.communication.email.implementation.models.EmailsSendHeaders; import com.azure.communication.email.implementation.models.ErrorResponseException; import com.azure.core.annotation.BodyParam; import com.azure.core.annotation.ExpectedResponses; @@ -22,6 +23,8 @@ import com.azure.core.annotation.ServiceInterface; import com.azure.core.annotation.ServiceMethod; import com.azure.core.annotation.UnexpectedResponseExceptionType; +import com.azure.core.http.rest.Response; +import com.azure.core.http.rest.ResponseBase; import com.azure.core.http.rest.RestProxy; import com.azure.core.util.Context; import com.azure.core.util.FluxUtil; @@ -49,7 +52,7 @@ public final class EmailsImpl { /** * Initializes an instance of EmailsImpl. - * + * * @param client the instance of the service client containing this operation class. */ EmailsImpl(AzureCommunicationEmailServiceImpl client) { @@ -67,14 +70,29 @@ public interface EmailsService { @Get("/emails/operations/{operationId}") @ExpectedResponses({ 200 }) @UnexpectedResponseExceptionType(ErrorResponseException.class) - Mono getSendResult(@HostParam("endpoint") String endpoint, + Mono> getSendResult( + @HostParam("endpoint") String endpoint, @PathParam("operationId") String operationId, + @QueryParam("api-version") String apiVersion, @HeaderParam("Accept") String accept, Context context); + + @Get("/emails/operations/{operationId}") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(ErrorResponseException.class) + Mono> getSendResultNoCustomHeaders(@HostParam("endpoint") String endpoint, @PathParam("operationId") String operationId, @QueryParam("api-version") String apiVersion, @HeaderParam("Accept") String accept, Context context); @Post("/emails:send") @ExpectedResponses({ 202 }) @UnexpectedResponseExceptionType(ErrorResponseException.class) - Mono send(@HostParam("endpoint") String endpoint, + Mono> send(@HostParam("endpoint") String endpoint, + @HeaderParam("Operation-Id") UUID operationId, @HeaderParam("x-ms-client-request-id") UUID clientRequestId, + @QueryParam("api-version") String apiVersion, @BodyParam("application/json") EmailMessage message, + @HeaderParam("Accept") String accept, Context context); + + @Post("/emails:send") + @ExpectedResponses({ 202 }) + @UnexpectedResponseExceptionType(ErrorResponseException.class) + Mono> sendNoCustomHeaders(@HostParam("endpoint") String endpoint, @HeaderParam("Operation-Id") UUID operationId, @HeaderParam("x-ms-client-request-id") UUID clientRequestId, @QueryParam("api-version") String apiVersion, @BodyParam("application/json") EmailMessage message, @HeaderParam("Accept") String accept, Context context); @@ -82,32 +100,34 @@ Mono send(@HostParam("endpoint") String endpoint, /** * Gets the status of the email send operation. - * + * * @param operationId ID of the long running operation (GUID) returned from a previous call to send email. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws ErrorResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return the status of the email send operation on successful completion of {@link Mono}. + * @return the status of the email send operation along with {@link ResponseBase} on successful completion of + * {@link Mono}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono getSendResultWithResponseAsync(String operationId) { - final String accept = "application/json"; - return FluxUtil.withContext(context -> service.getSendResult(this.client.getEndpoint(), operationId, - this.client.getApiVersion(), accept, context)); + public Mono> + getSendResultWithResponseAsync(String operationId) { + return FluxUtil.withContext(context -> getSendResultWithResponseAsync(operationId, context)); } /** * Gets the status of the email send operation. - * + * * @param operationId ID of the long running operation (GUID) returned from a previous call to send email. * @param context The context to associate with this operation. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws ErrorResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return the status of the email send operation on successful completion of {@link Mono}. + * @return the status of the email send operation along with {@link ResponseBase} on successful completion of + * {@link Mono}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono getSendResultWithResponseAsync(String operationId, Context context) { + public Mono> + getSendResultWithResponseAsync(String operationId, Context context) { final String accept = "application/json"; return service.getSendResult(this.client.getEndpoint(), operationId, this.client.getApiVersion(), accept, context); @@ -115,7 +135,7 @@ public Mono getSendResultWithResponseAsync(String o /** * Gets the status of the email send operation. - * + * * @param operationId ID of the long running operation (GUID) returned from a previous call to send email. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws ErrorResponseException thrown if the request is rejected by server. @@ -129,7 +149,7 @@ public Mono getSendResultAsync(String operationId) { /** * Gets the status of the email send operation. - * + * * @param operationId ID of the long running operation (GUID) returned from a previous call to send email. * @param context The context to associate with this operation. * @throws IllegalArgumentException thrown if parameters fail the validation. @@ -142,9 +162,43 @@ public Mono getSendResultAsync(String operationId, Context cont return getSendResultWithResponseAsync(operationId, context).flatMap(res -> Mono.justOrEmpty(res.getValue())); } + /** + * Gets the status of the email send operation. + * + * @param operationId ID of the long running operation (GUID) returned from a previous call to send email. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ErrorResponseException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the status of the email send operation along with {@link Response} on successful completion of + * {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> getSendResultNoCustomHeadersWithResponseAsync(String operationId) { + return FluxUtil.withContext(context -> getSendResultNoCustomHeadersWithResponseAsync(operationId, context)); + } + + /** + * Gets the status of the email send operation. + * + * @param operationId ID of the long running operation (GUID) returned from a previous call to send email. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ErrorResponseException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the status of the email send operation along with {@link Response} on successful completion of + * {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> getSendResultNoCustomHeadersWithResponseAsync(String operationId, + Context context) { + final String accept = "application/json"; + return service.getSendResultNoCustomHeaders(this.client.getEndpoint(), operationId, this.client.getApiVersion(), + accept, context); + } + /** * Queues an email message to be sent to one or more recipients. - * + * * @param message Message payload for sending an email. * @param operationId This is the ID provided by the customer to identify the long running operation. If an ID is * not provided by the customer, the service will generate one. @@ -152,19 +206,18 @@ public Mono getSendResultAsync(String operationId, Context cont * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws ErrorResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return status of the long running operation on successful completion of {@link Mono}. + * @return status of the long running operation along with {@link ResponseBase} on successful completion of + * {@link Mono}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono sendWithResponseAsync(EmailMessage message, UUID operationId, - UUID clientRequestId) { - final String accept = "application/json"; - return FluxUtil.withContext(context -> service.send(this.client.getEndpoint(), operationId, clientRequestId, - this.client.getApiVersion(), message, accept, context)); + public Mono> sendWithResponseAsync(EmailMessage message, + UUID operationId, UUID clientRequestId) { + return FluxUtil.withContext(context -> sendWithResponseAsync(message, operationId, clientRequestId, context)); } /** * Queues an email message to be sent to one or more recipients. - * + * * @param message Message payload for sending an email. * @param operationId This is the ID provided by the customer to identify the long running operation. If an ID is * not provided by the customer, the service will generate one. @@ -173,11 +226,12 @@ public Mono sendWithResponseAsync(EmailMessage message, UUID * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws ErrorResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return status of the long running operation on successful completion of {@link Mono}. + * @return status of the long running operation along with {@link ResponseBase} on successful completion of + * {@link Mono}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono sendWithResponseAsync(EmailMessage message, UUID operationId, UUID clientRequestId, - Context context) { + public Mono> sendWithResponseAsync(EmailMessage message, + UUID operationId, UUID clientRequestId, Context context) { final String accept = "application/json"; return service.send(this.client.getEndpoint(), operationId, clientRequestId, this.client.getApiVersion(), message, accept, context); @@ -185,7 +239,7 @@ public Mono sendWithResponseAsync(EmailMessage message, UUID /** * Queues an email message to be sent to one or more recipients. - * + * * @param message Message payload for sending an email. * @param operationId This is the ID provided by the customer to identify the long running operation. If an ID is * not provided by the customer, the service will generate one. @@ -208,7 +262,7 @@ public PollerFlux beginSendAsync(EmailMessage /** * Queues an email message to be sent to one or more recipients. - * + * * @param message Message payload for sending an email. * @param operationId This is the ID provided by the customer to identify the long running operation. If an ID is * not provided by the customer, the service will generate one. @@ -229,4 +283,93 @@ public PollerFlux beginSendAsync(EmailMessage .setContext(context)), TypeReference.createInstance(EmailSendResult.class), TypeReference.createInstance(EmailSendResult.class)); } + + /** + * Queues an email message to be sent to one or more recipients. + * + * @param message Message payload for sending an email. + * @param operationId This is the ID provided by the customer to identify the long running operation. If an ID is + * not provided by the customer, the service will generate one. + * @param clientRequestId Tracking ID sent with the request to help with debugging. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ErrorResponseException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return status of the long running operation along with {@link Response} on successful completion of + * {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> sendNoCustomHeadersWithResponseAsync(EmailMessage message, UUID operationId, + UUID clientRequestId) { + return FluxUtil.withContext( + context -> sendNoCustomHeadersWithResponseAsync(message, operationId, clientRequestId, context)); + } + + /** + * Queues an email message to be sent to one or more recipients. + * + * @param message Message payload for sending an email. + * @param operationId This is the ID provided by the customer to identify the long running operation. If an ID is + * not provided by the customer, the service will generate one. + * @param clientRequestId Tracking ID sent with the request to help with debugging. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ErrorResponseException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return status of the long running operation along with {@link Response} on successful completion of + * {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> sendNoCustomHeadersWithResponseAsync(EmailMessage message, UUID operationId, + UUID clientRequestId, Context context) { + final String accept = "application/json"; + return service.sendNoCustomHeaders(this.client.getEndpoint(), operationId, clientRequestId, + this.client.getApiVersion(), message, accept, context); + } + + /** + * Queues an email message to be sent to one or more recipients. + * + * @param message Message payload for sending an email. + * @param operationId This is the ID provided by the customer to identify the long running operation. If an ID is + * not provided by the customer, the service will generate one. + * @param clientRequestId Tracking ID sent with the request to help with debugging. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ErrorResponseException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link PollerFlux} for polling of status of the long running operation. + */ + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + public PollerFlux beginSendNoCustomHeadersAsync(EmailMessage message, + UUID operationId, UUID clientRequestId) { + return PollerFlux.create(Duration.ofSeconds(1), + () -> this.sendNoCustomHeadersWithResponseAsync(message, operationId, clientRequestId), + new DefaultPollingStrategy<>(new PollingStrategyOptions(this.client.getHttpPipeline()) + .setEndpoint("{endpoint}".replace("{endpoint}", this.client.getEndpoint())) + .setContext(Context.NONE)), + TypeReference.createInstance(EmailSendResult.class), TypeReference.createInstance(EmailSendResult.class)); + } + + /** + * Queues an email message to be sent to one or more recipients. + * + * @param message Message payload for sending an email. + * @param operationId This is the ID provided by the customer to identify the long running operation. If an ID is + * not provided by the customer, the service will generate one. + * @param clientRequestId Tracking ID sent with the request to help with debugging. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ErrorResponseException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link PollerFlux} for polling of status of the long running operation. + */ + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + public PollerFlux beginSendNoCustomHeadersAsync(EmailMessage message, + UUID operationId, UUID clientRequestId, Context context) { + return PollerFlux.create(Duration.ofSeconds(1), + () -> this.sendNoCustomHeadersWithResponseAsync(message, operationId, clientRequestId, context), + new DefaultPollingStrategy<>(new PollingStrategyOptions(this.client.getHttpPipeline()) + .setEndpoint("{endpoint}".replace("{endpoint}", this.client.getEndpoint())) + .setContext(context)), + TypeReference.createInstance(EmailSendResult.class), TypeReference.createInstance(EmailSendResult.class)); + } } diff --git a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/models/EmailAttachment.java b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/models/EmailAttachment.java index d0f32f9e05c84..1c7e3da112da6 100644 --- a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/models/EmailAttachment.java +++ b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/models/EmailAttachment.java @@ -4,7 +4,8 @@ package com.azure.communication.email.implementation.models; -import com.azure.core.annotation.Immutable; +import com.azure.core.annotation.Fluent; +import com.azure.core.util.CoreUtils; import com.azure.json.JsonReader; import com.azure.json.JsonSerializable; import com.azure.json.JsonToken; @@ -16,7 +17,7 @@ /** * Attachment to the email. */ -@Immutable +@Fluent public final class EmailAttachment implements JsonSerializable { /* * Name of the attachment @@ -31,7 +32,12 @@ public final class EmailAttachment implements JsonSerializable /* * Base64 encoded contents of the attachment */ - private final String contentInBase64; + private final byte[] contentInBase64; + + /* + * Unique identifier (CID) to reference an inline attachment. + */ + private String contentId; /** * Creates an instance of EmailAttachment class. @@ -40,7 +46,7 @@ public final class EmailAttachment implements JsonSerializable * @param contentType the contentType value to set. * @param contentInBase64 the contentInBase64 value to set. */ - public EmailAttachment(String name, String contentType, String contentInBase64) { + public EmailAttachment(String name, String contentType, byte[] contentInBase64) { this.name = name; this.contentType = contentType; this.contentInBase64 = contentInBase64; @@ -69,8 +75,28 @@ public String getContentType() { * * @return the contentInBase64 value. */ - public String getContentInBase64() { - return this.contentInBase64; + public byte[] getContentInBase64() { + return CoreUtils.clone(this.contentInBase64); + } + + /** + * Get the contentId property: Unique identifier (CID) to reference an inline attachment. + * + * @return the contentId value. + */ + public String getContentId() { + return this.contentId; + } + + /** + * Set the contentId property: Unique identifier (CID) to reference an inline attachment. + * + * @param contentId the contentId value to set. + * @return the EmailAttachment object itself. + */ + public EmailAttachment setContentId(String contentId) { + this.contentId = contentId; + return this; } /** @@ -81,7 +107,8 @@ public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { jsonWriter.writeStartObject(); jsonWriter.writeStringField("name", this.name); jsonWriter.writeStringField("contentType", this.contentType); - jsonWriter.writeStringField("contentInBase64", this.contentInBase64); + jsonWriter.writeBinaryField("contentInBase64", this.contentInBase64); + jsonWriter.writeStringField("contentId", this.contentId); return jsonWriter.writeEndObject(); } @@ -101,7 +128,8 @@ public static EmailAttachment fromJson(JsonReader jsonReader) throws IOException boolean contentTypeFound = false; String contentType = null; boolean contentInBase64Found = false; - String contentInBase64 = null; + byte[] contentInBase64 = null; + String contentId = null; while (reader.nextToken() != JsonToken.END_OBJECT) { String fieldName = reader.getFieldName(); reader.nextToken(); @@ -113,14 +141,19 @@ public static EmailAttachment fromJson(JsonReader jsonReader) throws IOException contentType = reader.getString(); contentTypeFound = true; } else if ("contentInBase64".equals(fieldName)) { - contentInBase64 = reader.getString(); + contentInBase64 = reader.getBinary(); contentInBase64Found = true; + } else if ("contentId".equals(fieldName)) { + contentId = reader.getString(); } else { reader.skipChildren(); } } if (nameFound && contentTypeFound && contentInBase64Found) { - return new EmailAttachment(name, contentType, contentInBase64); + EmailAttachment deserializedEmailAttachment = new EmailAttachment(name, contentType, contentInBase64); + deserializedEmailAttachment.contentId = contentId; + + return deserializedEmailAttachment; } List missingProperties = new ArrayList<>(); if (!nameFound) { diff --git a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/models/EmailMessage.java b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/models/EmailMessage.java index e0ca6d366b0a7..81332225d78a9 100644 --- a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/models/EmailMessage.java +++ b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/models/EmailMessage.java @@ -41,8 +41,8 @@ public final class EmailMessage implements JsonSerializable { private final EmailRecipients recipients; /* - * List of attachments. Please note that we limit the total size of an email request (which includes attachments) to - * 10MB. + * List of attachments. Please note that we limit the total size of an email request (which includes both regular + * and inline attachments) to 10MB. */ private List attachments; @@ -119,7 +119,7 @@ public EmailRecipients getRecipients() { /** * Get the attachments property: List of attachments. Please note that we limit the total size of an email request - * (which includes attachments) to 10MB. + * (which includes both regular and inline attachments) to 10MB. * * @return the attachments value. */ @@ -129,7 +129,7 @@ public List getAttachments() { /** * Set the attachments property: List of attachments. Please note that we limit the total size of an email request - * (which includes attachments) to 10MB. + * (which includes both regular and inline attachments) to 10MB. * * @param attachments the attachments value to set. * @return the EmailMessage object itself. diff --git a/sdk/communication/azure-communication-email/src/samples/java/com/azure/communication/email/ReadmeSamples.java b/sdk/communication/azure-communication-email/src/samples/java/com/azure/communication/email/ReadmeSamples.java index 22d60de5ea777..5f3c77f4a481b 100644 --- a/sdk/communication/azure-communication-email/src/samples/java/com/azure/communication/email/ReadmeSamples.java +++ b/sdk/communication/azure-communication-email/src/samples/java/com/azure/communication/email/ReadmeSamples.java @@ -126,7 +126,7 @@ public void sendEmailWithAttachment() { "text/plain", attachmentContent ); - + EmailMessage message = new EmailMessage() .setSenderAddress("") .setToRecipients("") @@ -140,4 +140,30 @@ public void sendEmailWithAttachment() { System.out.println("Operation Id: " + response.getValue().getId()); // END: readme-sample-sendEmailWithAttachment } + + public void sendEmailWithInlineAttachment() { + EmailClient emailClient = createEmailClientWithConnectionString(); + + // BEGIN: readme-sample-sendEmailWithInlineAttachment + BinaryData attachmentContent = BinaryData.fromFile(new File("C:/inlineimage.jpg").toPath()); + EmailAttachment attachment = new EmailAttachment( + "inlineimage.jpg", + "image/jpeg", + BinaryData.fromString("test") + ); + attachment.contentId = "inline_image"; + + EmailMessage message = new EmailMessage() + .setSenderAddress("") + .setToRecipients("") + .setSubject("test subject") + .setBodyHtml("

test message

") + .setAttachments(attachment); + + SyncPoller poller = emailClient.beginSend(message); + PollResponse response = poller.waitForCompletion(); + + System.out.println("Operation Id: " + response.getValue().getId()); + // END: readme-sample-sendEmailWithInlineAttachment + } } diff --git a/sdk/communication/azure-communication-email/src/test/java/com/azure/communication/email/EmailAsyncClientTests.java b/sdk/communication/azure-communication-email/src/test/java/com/azure/communication/email/EmailAsyncClientTests.java index 9efa1c6d0f3ff..3b8c52a319fb9 100644 --- a/sdk/communication/azure-communication-email/src/test/java/com/azure/communication/email/EmailAsyncClientTests.java +++ b/sdk/communication/azure-communication-email/src/test/java/com/azure/communication/email/EmailAsyncClientTests.java @@ -87,4 +87,30 @@ public void sendEmailWithAttachment(HttpClient httpClient) { }) .verifyComplete(); } + + @ParameterizedTest + @MethodSource("getTestParameters") + public void sendEmailWithInlineAttachment(HttpClient httpClient) { + emailAsyncClient = getEmailAsyncClient(httpClient); + + EmailAttachment attachment = new EmailAttachment( + "inlineimage.jpg", + "image/jpeg", + BinaryData.fromString("test") + ); + attachment.contentId = "inline_image"; + + EmailMessage message = new EmailMessage() + .setSenderAddress(SENDER_ADDRESS) + .setToRecipients(RECIPIENT_ADDRESS) + .setSubject("test subject") + .setBodyHtml("

test message

") + .setAttachments(attachment); + + StepVerifier.create(emailAsyncClient.beginSend(message).last()) + .assertNext(response -> { + assertEquals(response.getValue().getStatus(), EmailSendStatus.SUCCEEDED); + }) + .verifyComplete(); + } } diff --git a/sdk/communication/azure-communication-email/src/test/java/com/azure/communication/email/EmailClientTests.java b/sdk/communication/azure-communication-email/src/test/java/com/azure/communication/email/EmailClientTests.java index 590e474ab91b7..9f5fdc1d12b89 100644 --- a/sdk/communication/azure-communication-email/src/test/java/com/azure/communication/email/EmailClientTests.java +++ b/sdk/communication/azure-communication-email/src/test/java/com/azure/communication/email/EmailClientTests.java @@ -84,4 +84,29 @@ public void sendEmailWithAttachment(HttpClient httpClient) { assertEquals(response.getValue().getStatus(), EmailSendStatus.SUCCEEDED); } + + @ParameterizedTest + @MethodSource("getTestParameters") + public void sendEmailWithInlineAttachment(HttpClient httpClient) { + emailClient = getEmailClient(httpClient); + + EmailAttachment attachment = new EmailAttachment( + "inlineimage.jpg", + "image/jpeg", + BinaryData.fromString("test") + ); + attachment.contentId = "inline_image"; + + EmailMessage message = new EmailMessage() + .setSenderAddress(SENDER_ADDRESS) + .setToRecipients(RECIPIENT_ADDRESS) + .setSubject("test subject") + .setBodyHtml("

test message

") + .setAttachments(attachment); + + SyncPoller poller = emailClient.beginSend(message); + PollResponse response = poller.waitForCompletion(); + + assertEquals(response.getValue().getStatus(), EmailSendStatus.SUCCEEDED); + } } diff --git a/sdk/communication/azure-communication-email/swagger/README.md b/sdk/communication/azure-communication-email/swagger/README.md index 24c8f181323b9..b1f2fd51c919f 100644 --- a/sdk/communication/azure-communication-email/swagger/README.md +++ b/sdk/communication/azure-communication-email/swagger/README.md @@ -1,7 +1,7 @@ ## Generate autorest code ```yaml -require: https://raw.githubusercontent.com/Azure/azure-rest-api-specs/ac29c822ecd5f6054cd17c46839e7c04a1114c6d/specification/communication/data-plane/Email/readme.md +require: https://raw.githubusercontent.com/Azure/azure-rest-api-specs/e64ad693df24b47d4009eece6663c8d95cf94be6/specification/communication/data-plane/Email/readme.md output-folder: ../ license-header: MICROSOFT_MIT_SMALL title: Azure Communication Email Service From 6e555cf919c8c05eae433798462e1dcb4a1db8e2 Mon Sep 17 00:00:00 2001 From: Nate Kimball Date: Wed, 21 Aug 2024 13:51:29 -0700 Subject: [PATCH 02/16] minor updates --- sdk/communication/azure-communication-email/CHANGELOG.md | 7 +++++++ sdk/communication/azure-communication-email/pom.xml | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/sdk/communication/azure-communication-email/CHANGELOG.md b/sdk/communication/azure-communication-email/CHANGELOG.md index fa0fcbb66524f..9d7b454cd6d62 100644 --- a/sdk/communication/azure-communication-email/CHANGELOG.md +++ b/sdk/communication/azure-communication-email/CHANGELOG.md @@ -1,5 +1,12 @@ # Release History +## 1.1.0-beta.2 (2024-08-14) + +### Features Added + +- 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.1.0-beta.1 (Unreleased) ### Features Added diff --git a/sdk/communication/azure-communication-email/pom.xml b/sdk/communication/azure-communication-email/pom.xml index e7d22af6505b5..9e90070f9c61e 100644 --- a/sdk/communication/azure-communication-email/pom.xml +++ b/sdk/communication/azure-communication-email/pom.xml @@ -12,7 +12,7 @@ com.azure azure-communication-email - 1.1.0-beta.1 + 1.1.0-beta.2 jar Microsoft Azure Communications SDK for Email From 740aa31fc51d26939cec653d7612364ed78bb59f Mon Sep 17 00:00:00 2001 From: Nate Kimball Date: Thu, 22 Aug 2024 10:40:06 -0700 Subject: [PATCH 03/16] updating classes with correct API version --- .../communication/email/EmailAsyncClient.java | 2 +- .../email/implementation/EmailsImpl.java | 183 ++---------------- .../swagger/README.md | 2 +- 3 files changed, 22 insertions(+), 165 deletions(-) diff --git a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/EmailAsyncClient.java b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/EmailAsyncClient.java index 2df9abaf69b33..e6498bc1da0d7 100644 --- a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/EmailAsyncClient.java +++ b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/EmailAsyncClient.java @@ -96,7 +96,7 @@ PollerFlux beginSend(EmailMessage message, Con attachmentsImpl.add(new com.azure.communication.email.implementation.models.EmailAttachment( attachment.getName(), attachment.getContentType(), - Base64.getEncoder().encodeToString(attachment.getContent().toBytes()) + attachment.getContent().toBytes() )); } } diff --git a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/EmailsImpl.java b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/EmailsImpl.java index 801b3ad1928fc..e235dc47b6889 100644 --- a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/EmailsImpl.java +++ b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/EmailsImpl.java @@ -4,11 +4,10 @@ package com.azure.communication.email.implementation; -import com.azure.communication.email.EmailSendResult; import com.azure.communication.email.implementation.models.EmailMessage; import com.azure.communication.email.implementation.models.EmailSendResult; -import com.azure.communication.email.implementation.models.EmailsGetSendResultHeaders; -import com.azure.communication.email.implementation.models.EmailsSendHeaders; +import com.azure.communication.email.implementation.models.EmailsGetSendResultResponse; +import com.azure.communication.email.implementation.models.EmailsSendResponse; import com.azure.communication.email.implementation.models.ErrorResponseException; import com.azure.core.annotation.BodyParam; import com.azure.core.annotation.ExpectedResponses; @@ -23,8 +22,6 @@ import com.azure.core.annotation.ServiceInterface; import com.azure.core.annotation.ServiceMethod; import com.azure.core.annotation.UnexpectedResponseExceptionType; -import com.azure.core.http.rest.Response; -import com.azure.core.http.rest.ResponseBase; import com.azure.core.http.rest.RestProxy; import com.azure.core.util.Context; import com.azure.core.util.FluxUtil; @@ -70,29 +67,14 @@ public interface EmailsService { @Get("/emails/operations/{operationId}") @ExpectedResponses({ 200 }) @UnexpectedResponseExceptionType(ErrorResponseException.class) - Mono> getSendResult( - @HostParam("endpoint") String endpoint, @PathParam("operationId") String operationId, - @QueryParam("api-version") String apiVersion, @HeaderParam("Accept") String accept, Context context); - - @Get("/emails/operations/{operationId}") - @ExpectedResponses({ 200 }) - @UnexpectedResponseExceptionType(ErrorResponseException.class) - Mono> getSendResultNoCustomHeaders(@HostParam("endpoint") String endpoint, + Mono getSendResult(@HostParam("endpoint") String endpoint, @PathParam("operationId") String operationId, @QueryParam("api-version") String apiVersion, @HeaderParam("Accept") String accept, Context context); @Post("/emails:send") @ExpectedResponses({ 202 }) @UnexpectedResponseExceptionType(ErrorResponseException.class) - Mono> send(@HostParam("endpoint") String endpoint, - @HeaderParam("Operation-Id") UUID operationId, @HeaderParam("x-ms-client-request-id") UUID clientRequestId, - @QueryParam("api-version") String apiVersion, @BodyParam("application/json") EmailMessage message, - @HeaderParam("Accept") String accept, Context context); - - @Post("/emails:send") - @ExpectedResponses({ 202 }) - @UnexpectedResponseExceptionType(ErrorResponseException.class) - Mono> sendNoCustomHeaders(@HostParam("endpoint") String endpoint, + Mono send(@HostParam("endpoint") String endpoint, @HeaderParam("Operation-Id") UUID operationId, @HeaderParam("x-ms-client-request-id") UUID clientRequestId, @QueryParam("api-version") String apiVersion, @BodyParam("application/json") EmailMessage message, @HeaderParam("Accept") String accept, Context context); @@ -105,13 +87,13 @@ Mono> sendNoCustomHeaders(@HostParam("endpoint") Strin * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws ErrorResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return the status of the email send operation along with {@link ResponseBase} on successful completion of - * {@link Mono}. + * @return the status of the email send operation on successful completion of {@link Mono}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> - getSendResultWithResponseAsync(String operationId) { - return FluxUtil.withContext(context -> getSendResultWithResponseAsync(operationId, context)); + public Mono getSendResultWithResponseAsync(String operationId) { + final String accept = "application/json"; + return FluxUtil.withContext(context -> service.getSendResult(this.client.getEndpoint(), operationId, + this.client.getApiVersion(), accept, context)); } /** @@ -122,12 +104,10 @@ Mono> sendNoCustomHeaders(@HostParam("endpoint") Strin * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws ErrorResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return the status of the email send operation along with {@link ResponseBase} on successful completion of - * {@link Mono}. + * @return the status of the email send operation on successful completion of {@link Mono}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> - getSendResultWithResponseAsync(String operationId, Context context) { + public Mono getSendResultWithResponseAsync(String operationId, Context context) { final String accept = "application/json"; return service.getSendResult(this.client.getEndpoint(), operationId, this.client.getApiVersion(), accept, context); @@ -162,40 +142,6 @@ public Mono getSendResultAsync(String operationId, Context cont return getSendResultWithResponseAsync(operationId, context).flatMap(res -> Mono.justOrEmpty(res.getValue())); } - /** - * Gets the status of the email send operation. - * - * @param operationId ID of the long running operation (GUID) returned from a previous call to send email. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws ErrorResponseException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return the status of the email send operation along with {@link Response} on successful completion of - * {@link Mono}. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> getSendResultNoCustomHeadersWithResponseAsync(String operationId) { - return FluxUtil.withContext(context -> getSendResultNoCustomHeadersWithResponseAsync(operationId, context)); - } - - /** - * Gets the status of the email send operation. - * - * @param operationId ID of the long running operation (GUID) returned from a previous call to send email. - * @param context The context to associate with this operation. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws ErrorResponseException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return the status of the email send operation along with {@link Response} on successful completion of - * {@link Mono}. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> getSendResultNoCustomHeadersWithResponseAsync(String operationId, - Context context) { - final String accept = "application/json"; - return service.getSendResultNoCustomHeaders(this.client.getEndpoint(), operationId, this.client.getApiVersion(), - accept, context); - } - /** * Queues an email message to be sent to one or more recipients. * @@ -206,13 +152,14 @@ public Mono> getSendResultNoCustomHeadersWithResponseA * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws ErrorResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return status of the long running operation along with {@link ResponseBase} on successful completion of - * {@link Mono}. + * @return status of the long running operation on successful completion of {@link Mono}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> sendWithResponseAsync(EmailMessage message, - UUID operationId, UUID clientRequestId) { - return FluxUtil.withContext(context -> sendWithResponseAsync(message, operationId, clientRequestId, context)); + public Mono sendWithResponseAsync(EmailMessage message, UUID operationId, + UUID clientRequestId) { + final String accept = "application/json"; + return FluxUtil.withContext(context -> service.send(this.client.getEndpoint(), operationId, clientRequestId, + this.client.getApiVersion(), message, accept, context)); } /** @@ -226,12 +173,11 @@ public Mono> sendWithResponseAs * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws ErrorResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return status of the long running operation along with {@link ResponseBase} on successful completion of - * {@link Mono}. + * @return status of the long running operation on successful completion of {@link Mono}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> sendWithResponseAsync(EmailMessage message, - UUID operationId, UUID clientRequestId, Context context) { + public Mono sendWithResponseAsync(EmailMessage message, UUID operationId, UUID clientRequestId, + Context context) { final String accept = "application/json"; return service.send(this.client.getEndpoint(), operationId, clientRequestId, this.client.getApiVersion(), message, accept, context); @@ -283,93 +229,4 @@ public PollerFlux beginSendAsync(EmailMessage .setContext(context)), TypeReference.createInstance(EmailSendResult.class), TypeReference.createInstance(EmailSendResult.class)); } - - /** - * Queues an email message to be sent to one or more recipients. - * - * @param message Message payload for sending an email. - * @param operationId This is the ID provided by the customer to identify the long running operation. If an ID is - * not provided by the customer, the service will generate one. - * @param clientRequestId Tracking ID sent with the request to help with debugging. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws ErrorResponseException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return status of the long running operation along with {@link Response} on successful completion of - * {@link Mono}. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> sendNoCustomHeadersWithResponseAsync(EmailMessage message, UUID operationId, - UUID clientRequestId) { - return FluxUtil.withContext( - context -> sendNoCustomHeadersWithResponseAsync(message, operationId, clientRequestId, context)); - } - - /** - * Queues an email message to be sent to one or more recipients. - * - * @param message Message payload for sending an email. - * @param operationId This is the ID provided by the customer to identify the long running operation. If an ID is - * not provided by the customer, the service will generate one. - * @param clientRequestId Tracking ID sent with the request to help with debugging. - * @param context The context to associate with this operation. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws ErrorResponseException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return status of the long running operation along with {@link Response} on successful completion of - * {@link Mono}. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> sendNoCustomHeadersWithResponseAsync(EmailMessage message, UUID operationId, - UUID clientRequestId, Context context) { - final String accept = "application/json"; - return service.sendNoCustomHeaders(this.client.getEndpoint(), operationId, clientRequestId, - this.client.getApiVersion(), message, accept, context); - } - - /** - * Queues an email message to be sent to one or more recipients. - * - * @param message Message payload for sending an email. - * @param operationId This is the ID provided by the customer to identify the long running operation. If an ID is - * not provided by the customer, the service will generate one. - * @param clientRequestId Tracking ID sent with the request to help with debugging. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws ErrorResponseException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return the {@link PollerFlux} for polling of status of the long running operation. - */ - @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) - public PollerFlux beginSendNoCustomHeadersAsync(EmailMessage message, - UUID operationId, UUID clientRequestId) { - return PollerFlux.create(Duration.ofSeconds(1), - () -> this.sendNoCustomHeadersWithResponseAsync(message, operationId, clientRequestId), - new DefaultPollingStrategy<>(new PollingStrategyOptions(this.client.getHttpPipeline()) - .setEndpoint("{endpoint}".replace("{endpoint}", this.client.getEndpoint())) - .setContext(Context.NONE)), - TypeReference.createInstance(EmailSendResult.class), TypeReference.createInstance(EmailSendResult.class)); - } - - /** - * Queues an email message to be sent to one or more recipients. - * - * @param message Message payload for sending an email. - * @param operationId This is the ID provided by the customer to identify the long running operation. If an ID is - * not provided by the customer, the service will generate one. - * @param clientRequestId Tracking ID sent with the request to help with debugging. - * @param context The context to associate with this operation. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws ErrorResponseException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return the {@link PollerFlux} for polling of status of the long running operation. - */ - @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) - public PollerFlux beginSendNoCustomHeadersAsync(EmailMessage message, - UUID operationId, UUID clientRequestId, Context context) { - return PollerFlux.create(Duration.ofSeconds(1), - () -> this.sendNoCustomHeadersWithResponseAsync(message, operationId, clientRequestId, context), - new DefaultPollingStrategy<>(new PollingStrategyOptions(this.client.getHttpPipeline()) - .setEndpoint("{endpoint}".replace("{endpoint}", this.client.getEndpoint())) - .setContext(context)), - TypeReference.createInstance(EmailSendResult.class), TypeReference.createInstance(EmailSendResult.class)); - } } diff --git a/sdk/communication/azure-communication-email/swagger/README.md b/sdk/communication/azure-communication-email/swagger/README.md index b1f2fd51c919f..81e6d0afffbc3 100644 --- a/sdk/communication/azure-communication-email/swagger/README.md +++ b/sdk/communication/azure-communication-email/swagger/README.md @@ -22,7 +22,7 @@ required-fields-as-ctor-args: true generate-client-as-impl: true url-as-string: true service-versions: -- 2023-03-31 +- 2024-07-01-preview polling: default: intermediate-type: EmailSendResult From 702377c26b1bd96ff395054f1504d41814a7d9c2 Mon Sep 17 00:00:00 2001 From: Nate Kimball Date: Thu, 22 Aug 2024 14:38:57 -0700 Subject: [PATCH 04/16] updating tests --- .../azure-communication-email/README.md | 6 +-- .../communication/email/EmailAsyncClient.java | 2 +- .../email/EmailServiceVersion.java | 6 +-- .../email/models/EmailAttachment.java | 50 ++++++++++++++----- .../communication/email/ReadmeSamples.java | 6 +-- .../email/EmailAsyncClientTests.java | 6 +-- .../communication/email/EmailClientTests.java | 6 +-- 7 files changed, 54 insertions(+), 28 deletions(-) diff --git a/sdk/communication/azure-communication-email/README.md b/sdk/communication/azure-communication-email/README.md index c6c288293cab7..6a59340ee7615 100644 --- a/sdk/communication/azure-communication-email/README.md +++ b/sdk/communication/azure-communication-email/README.md @@ -177,7 +177,7 @@ BinaryData attachmentContent = BinaryData.fromFile(new File("C:/attachment.txt") EmailAttachment attachment = new EmailAttachment( "attachment.txt", "text/plain", - attachmentContent + attachmentContent.toBytes() ); EmailMessage message = new EmailMessage() @@ -203,9 +203,9 @@ BinaryData attachmentContent = BinaryData.fromFile(new File("C:/inlineimage.jpg" EmailAttachment attachment = new EmailAttachment( "inlineimage.jpg", "image/jpeg", - BinaryData.fromString("test") + BinaryData.fromString("test").toBytes() ); -attachment.contentId = "inline_image"; +attachment.setContentId("inline_image"); EmailMessage message = new EmailMessage() .setSenderAddress("") diff --git a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/EmailAsyncClient.java b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/EmailAsyncClient.java index e6498bc1da0d7..0b99469d4d596 100644 --- a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/EmailAsyncClient.java +++ b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/EmailAsyncClient.java @@ -96,7 +96,7 @@ PollerFlux beginSend(EmailMessage message, Con attachmentsImpl.add(new com.azure.communication.email.implementation.models.EmailAttachment( attachment.getName(), attachment.getContentType(), - attachment.getContent().toBytes() + attachment.getContentInBase64() )); } } diff --git a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/EmailServiceVersion.java b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/EmailServiceVersion.java index 2e9efe6b31414..ad39b542b2646 100644 --- a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/EmailServiceVersion.java +++ b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/EmailServiceVersion.java @@ -8,8 +8,8 @@ /** Service version of AzureCommunicationServicesClient. */ public enum EmailServiceVersion implements ServiceVersion { - /** Enum value 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; @@ -28,6 +28,6 @@ public String getVersion() { * @return The latest {@link EmailServiceVersion}. */ public static EmailServiceVersion getLatest() { - return V2023_03_31; + return V2024_07_01_Preview; } } diff --git a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/models/EmailAttachment.java b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/models/EmailAttachment.java index 6a8ec1785e926..ab8d90ecbe7ed 100644 --- a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/models/EmailAttachment.java +++ b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/models/EmailAttachment.java @@ -4,6 +4,7 @@ package com.azure.communication.email.models; import com.azure.core.util.BinaryData; +import com.azure.core.util.CoreUtils; /** Attachment to the email. */ public final class EmailAttachment { @@ -20,24 +21,29 @@ public final class EmailAttachment { /* * Base64 encoded contents of the attachment */ - private final BinaryData content; + private final byte[] contentInBase64; + + /* + * Unique identifier (CID) to reference an inline attachment. + */ + private String contentId; /** * Creates an instance of EmailAttachment class. - * + * * @param name the name value to set. * @param contentType the contentType value to set. - * @param content the content value to set. + * @param contentInBase64 the contentInBase64 value to set. */ - public EmailAttachment(String name, String contentType, BinaryData content) { + public EmailAttachment(String name, String contentType, byte[] contentInBase64) { this.name = name; this.contentType = contentType; - this.content = content; + this.contentInBase64 = contentInBase64; } /** * Get the name property: Name of the attachment. - * + * * @return the name value. */ public String getName() { @@ -46,7 +52,7 @@ public String getName() { /** * Get the contentType property: MIME type of the content being attached. - * + * * @return the contentType value. */ public String getContentType() { @@ -54,11 +60,31 @@ public String getContentType() { } /** - * Get the content property: Contents of the attachment. - * - * @return the content value. + * Get the contentInBase64 property: Base64 encoded contents of the attachment. + * + * @return the contentInBase64 value. + */ + public byte[] getContentInBase64() { + return CoreUtils.clone(this.contentInBase64); + } + + /** + * Get the contentId property: Unique identifier (CID) to reference an inline attachment. + * + * @return the contentId value. + */ + public String getContentId() { + return this.contentId; + } + + /** + * Set the contentId property: Unique identifier (CID) to reference an inline attachment. + * + * @param contentId the contentId value to set. + * @return the EmailAttachment object itself. */ - public BinaryData getContent() { - return this.content; + public EmailAttachment setContentId(String contentId) { + this.contentId = contentId; + return this; } } diff --git a/sdk/communication/azure-communication-email/src/samples/java/com/azure/communication/email/ReadmeSamples.java b/sdk/communication/azure-communication-email/src/samples/java/com/azure/communication/email/ReadmeSamples.java index 5f3c77f4a481b..d1374ff023190 100644 --- a/sdk/communication/azure-communication-email/src/samples/java/com/azure/communication/email/ReadmeSamples.java +++ b/sdk/communication/azure-communication-email/src/samples/java/com/azure/communication/email/ReadmeSamples.java @@ -124,7 +124,7 @@ public void sendEmailWithAttachment() { EmailAttachment attachment = new EmailAttachment( "attachment.txt", "text/plain", - attachmentContent + attachmentContent.toBytes() ); EmailMessage message = new EmailMessage() @@ -149,9 +149,9 @@ public void sendEmailWithInlineAttachment() { EmailAttachment attachment = new EmailAttachment( "inlineimage.jpg", "image/jpeg", - BinaryData.fromString("test") + BinaryData.fromString("test").toBytes() ); - attachment.contentId = "inline_image"; + attachment.setContentId("inline_image"); EmailMessage message = new EmailMessage() .setSenderAddress("") diff --git a/sdk/communication/azure-communication-email/src/test/java/com/azure/communication/email/EmailAsyncClientTests.java b/sdk/communication/azure-communication-email/src/test/java/com/azure/communication/email/EmailAsyncClientTests.java index 3b8c52a319fb9..06f8afaae0673 100644 --- a/sdk/communication/azure-communication-email/src/test/java/com/azure/communication/email/EmailAsyncClientTests.java +++ b/sdk/communication/azure-communication-email/src/test/java/com/azure/communication/email/EmailAsyncClientTests.java @@ -71,7 +71,7 @@ public void sendEmailWithAttachment(HttpClient httpClient) { EmailAttachment attachment = new EmailAttachment( "attachment.txt", "text/plain", - BinaryData.fromString("test") + BinaryData.fromString("test").toBytes() ); EmailMessage message = new EmailMessage() @@ -96,9 +96,9 @@ public void sendEmailWithInlineAttachment(HttpClient httpClient) { EmailAttachment attachment = new EmailAttachment( "inlineimage.jpg", "image/jpeg", - BinaryData.fromString("test") + BinaryData.fromString("test").toBytes() ); - attachment.contentId = "inline_image"; + attachment.setContentId("inline_image"); EmailMessage message = new EmailMessage() .setSenderAddress(SENDER_ADDRESS) diff --git a/sdk/communication/azure-communication-email/src/test/java/com/azure/communication/email/EmailClientTests.java b/sdk/communication/azure-communication-email/src/test/java/com/azure/communication/email/EmailClientTests.java index 9f5fdc1d12b89..42b3ff8d0adde 100644 --- a/sdk/communication/azure-communication-email/src/test/java/com/azure/communication/email/EmailClientTests.java +++ b/sdk/communication/azure-communication-email/src/test/java/com/azure/communication/email/EmailClientTests.java @@ -69,7 +69,7 @@ public void sendEmailWithAttachment(HttpClient httpClient) { EmailAttachment attachment = new EmailAttachment( "attachment.txt", "text/plain", - BinaryData.fromString("test") + BinaryData.fromString("test").toBytes() ); EmailMessage message = new EmailMessage() @@ -93,9 +93,9 @@ public void sendEmailWithInlineAttachment(HttpClient httpClient) { EmailAttachment attachment = new EmailAttachment( "inlineimage.jpg", "image/jpeg", - BinaryData.fromString("test") + BinaryData.fromString("test").toBytes() ); - attachment.contentId = "inline_image"; + attachment.setContentId("inline_image"); EmailMessage message = new EmailMessage() .setSenderAddress(SENDER_ADDRESS) From d0a91dc21259f1f07f6c18c6807ba6a3c32d40ae Mon Sep 17 00:00:00 2001 From: Nate Kimball Date: Thu, 22 Aug 2024 15:00:54 -0700 Subject: [PATCH 05/16] assets.json --- sdk/communication/azure-communication-email/assets.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/communication/azure-communication-email/assets.json b/sdk/communication/azure-communication-email/assets.json index 13cdcb26bb679..6b41ebc3d5ef8 100644 --- a/sdk/communication/azure-communication-email/assets.json +++ b/sdk/communication/azure-communication-email/assets.json @@ -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_565857179a" } From f5ed3b13d4afb766699384c5154a1958c11a9415 Mon Sep 17 00:00:00 2001 From: Nate Kimball Date: Thu, 22 Aug 2024 15:18:36 -0700 Subject: [PATCH 06/16] reverting version number --- .../azure-communication-email/CHANGELOG.md | 15 +-------------- .../azure-communication-email/pom.xml | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/sdk/communication/azure-communication-email/CHANGELOG.md b/sdk/communication/azure-communication-email/CHANGELOG.md index 9d7b454cd6d62..55d942f6ab588 100644 --- a/sdk/communication/azure-communication-email/CHANGELOG.md +++ b/sdk/communication/azure-communication-email/CHANGELOG.md @@ -1,25 +1,12 @@ # Release History -## 1.1.0-beta.2 (2024-08-14) +## 1.1.0-beta.1 (2024-08-14) ### Features Added - 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.1.0-beta.1 (Unreleased) - -### Features Added - -### Breaking Changes - -### Bugs Fixed - -- An `EmailMessage` with null recipient addresses can no longer be sent. - -### Other Changes - - ## 1.0.15 (2024-07-26) diff --git a/sdk/communication/azure-communication-email/pom.xml b/sdk/communication/azure-communication-email/pom.xml index 9e90070f9c61e..6695c214ddabd 100644 --- a/sdk/communication/azure-communication-email/pom.xml +++ b/sdk/communication/azure-communication-email/pom.xml @@ -12,7 +12,7 @@ com.azure azure-communication-email - 1.1.0-beta.2 + 1.1.0-beta.1 jar Microsoft Azure Communications SDK for Email @@ -109,6 +109,19 @@ + + maven-assembly-plugin + + + + com.azure.communication.email.App + + + + jar-with-dependencies + + + com.azure.tools codesnippet-maven-plugin From e2070dd692ee1cadd23deef9337ddeb8b20e24d4 Mon Sep 17 00:00:00 2001 From: Nate Kimball Date: Thu, 22 Aug 2024 16:19:34 -0700 Subject: [PATCH 07/16] content should be string --- .../azure-communication-email/README.md | 8 ++++---- .../azure-communication-email/assets.json | 2 +- .../azure-communication-email/pom.xml | 13 ------------- .../communication/email/EmailAsyncClient.java | 15 +++++++++++++-- .../implementation/models/EmailAttachment.java | 15 +++++++-------- .../email/models/EmailAttachment.java | 9 ++++----- .../azure/communication/email/ReadmeSamples.java | 8 ++++---- .../email/EmailAsyncClientTests.java | 4 ++-- .../communication/email/EmailClientTests.java | 4 ++-- 9 files changed, 37 insertions(+), 41 deletions(-) diff --git a/sdk/communication/azure-communication-email/README.md b/sdk/communication/azure-communication-email/README.md index 6a59340ee7615..b798a9c9c501f 100644 --- a/sdk/communication/azure-communication-email/README.md +++ b/sdk/communication/azure-communication-email/README.md @@ -173,11 +173,11 @@ System.out.println("Operation Id: " + response.getValue().getId()); Azure Communication Services support sending email with attachments. ```java readme-sample-sendEmailWithAttachment -BinaryData attachmentContent = BinaryData.fromFile(new File("C:/attachment.txt").toPath()); +String attachmentContent = BinaryData.fromFile(new File("C:/attachment.txt").toPath()).toString(); EmailAttachment attachment = new EmailAttachment( "attachment.txt", "text/plain", - attachmentContent.toBytes() + attachmentContent ); EmailMessage message = new EmailMessage() @@ -199,11 +199,11 @@ 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:/inlineimage.jpg").toPath()); +String attachmentContent = BinaryData.fromFile(new File("C:/attachment.txt").toPath()).toString(); EmailAttachment attachment = new EmailAttachment( "inlineimage.jpg", "image/jpeg", - BinaryData.fromString("test").toBytes() + "test" ); attachment.setContentId("inline_image"); diff --git a/sdk/communication/azure-communication-email/assets.json b/sdk/communication/azure-communication-email/assets.json index 6b41ebc3d5ef8..46bce5c30fb20 100644 --- a/sdk/communication/azure-communication-email/assets.json +++ b/sdk/communication/azure-communication-email/assets.json @@ -2,5 +2,5 @@ "AssetsRepo": "Azure/azure-sdk-assets", "AssetsRepoPrefixPath": "java", "TagPrefix": "java/communication/azure-communication-email", - "Tag": "java/communication/azure-communication-email_565857179a" + "Tag": "java/communication/azure-communication-email_320d0c4c7c" } diff --git a/sdk/communication/azure-communication-email/pom.xml b/sdk/communication/azure-communication-email/pom.xml index 6695c214ddabd..e7d22af6505b5 100644 --- a/sdk/communication/azure-communication-email/pom.xml +++ b/sdk/communication/azure-communication-email/pom.xml @@ -109,19 +109,6 @@ - - maven-assembly-plugin - - - - com.azure.communication.email.App - - - - jar-with-dependencies - - - com.azure.tools codesnippet-maven-plugin diff --git a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/EmailAsyncClient.java b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/EmailAsyncClient.java index 0b99469d4d596..e4a86fa4a630e 100644 --- a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/EmailAsyncClient.java +++ b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/EmailAsyncClient.java @@ -93,11 +93,22 @@ PollerFlux 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(), attachment.getContentInBase64() - )); + ); + + String contentId = attachment.getContentId(); + + if (contentId != null) + { + attachmentImpl.setContentId(contentId); + } + + attachmentsImpl.add(attachmentImpl); } } diff --git a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/models/EmailAttachment.java b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/models/EmailAttachment.java index 1c7e3da112da6..511048939c1f4 100644 --- a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/models/EmailAttachment.java +++ b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/models/EmailAttachment.java @@ -5,7 +5,6 @@ package com.azure.communication.email.implementation.models; import com.azure.core.annotation.Fluent; -import com.azure.core.util.CoreUtils; import com.azure.json.JsonReader; import com.azure.json.JsonSerializable; import com.azure.json.JsonToken; @@ -32,7 +31,7 @@ public final class EmailAttachment implements JsonSerializable /* * Base64 encoded contents of the attachment */ - private final byte[] contentInBase64; + private final String contentInBase64; /* * Unique identifier (CID) to reference an inline attachment. @@ -46,7 +45,7 @@ public final class EmailAttachment implements JsonSerializable * @param contentType the contentType value to set. * @param contentInBase64 the contentInBase64 value to set. */ - public EmailAttachment(String name, String contentType, byte[] contentInBase64) { + public EmailAttachment(String name, String contentType, String contentInBase64) { this.name = name; this.contentType = contentType; this.contentInBase64 = contentInBase64; @@ -75,8 +74,8 @@ public String getContentType() { * * @return the contentInBase64 value. */ - public byte[] getContentInBase64() { - return CoreUtils.clone(this.contentInBase64); + public String getContentInBase64() { + return this.contentInBase64; } /** @@ -107,7 +106,7 @@ public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { jsonWriter.writeStartObject(); jsonWriter.writeStringField("name", this.name); jsonWriter.writeStringField("contentType", this.contentType); - jsonWriter.writeBinaryField("contentInBase64", this.contentInBase64); + jsonWriter.writeStringField("contentInBase64", this.contentInBase64); jsonWriter.writeStringField("contentId", this.contentId); return jsonWriter.writeEndObject(); } @@ -128,7 +127,7 @@ public static EmailAttachment fromJson(JsonReader jsonReader) throws IOException boolean contentTypeFound = false; String contentType = null; boolean contentInBase64Found = false; - byte[] contentInBase64 = null; + String contentInBase64 = null; String contentId = null; while (reader.nextToken() != JsonToken.END_OBJECT) { String fieldName = reader.getFieldName(); @@ -141,7 +140,7 @@ public static EmailAttachment fromJson(JsonReader jsonReader) throws IOException contentType = reader.getString(); contentTypeFound = true; } else if ("contentInBase64".equals(fieldName)) { - contentInBase64 = reader.getBinary(); + contentInBase64 = reader.getString(); contentInBase64Found = true; } else if ("contentId".equals(fieldName)) { contentId = reader.getString(); diff --git a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/models/EmailAttachment.java b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/models/EmailAttachment.java index ab8d90ecbe7ed..ccd9baf449b8e 100644 --- a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/models/EmailAttachment.java +++ b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/models/EmailAttachment.java @@ -4,7 +4,6 @@ package com.azure.communication.email.models; import com.azure.core.util.BinaryData; -import com.azure.core.util.CoreUtils; /** Attachment to the email. */ public final class EmailAttachment { @@ -21,7 +20,7 @@ public final class EmailAttachment { /* * Base64 encoded contents of the attachment */ - private final byte[] contentInBase64; + private final String contentInBase64; /* * Unique identifier (CID) to reference an inline attachment. @@ -35,7 +34,7 @@ public final class EmailAttachment { * @param contentType the contentType value to set. * @param contentInBase64 the contentInBase64 value to set. */ - public EmailAttachment(String name, String contentType, byte[] contentInBase64) { + public EmailAttachment(String name, String contentType, String contentInBase64) { this.name = name; this.contentType = contentType; this.contentInBase64 = contentInBase64; @@ -64,8 +63,8 @@ public String getContentType() { * * @return the contentInBase64 value. */ - public byte[] getContentInBase64() { - return CoreUtils.clone(this.contentInBase64); + public String getContentInBase64() { + return this.contentInBase64; } /** diff --git a/sdk/communication/azure-communication-email/src/samples/java/com/azure/communication/email/ReadmeSamples.java b/sdk/communication/azure-communication-email/src/samples/java/com/azure/communication/email/ReadmeSamples.java index d1374ff023190..71beb3f8f1d11 100644 --- a/sdk/communication/azure-communication-email/src/samples/java/com/azure/communication/email/ReadmeSamples.java +++ b/sdk/communication/azure-communication-email/src/samples/java/com/azure/communication/email/ReadmeSamples.java @@ -120,11 +120,11 @@ public void sendEmailWithAttachment() { EmailClient emailClient = createEmailClientWithConnectionString(); // BEGIN: readme-sample-sendEmailWithAttachment - BinaryData attachmentContent = BinaryData.fromFile(new File("C:/attachment.txt").toPath()); + String attachmentContent = BinaryData.fromFile(new File("C:/attachment.txt").toPath()).toString(); EmailAttachment attachment = new EmailAttachment( "attachment.txt", "text/plain", - attachmentContent.toBytes() + attachmentContent ); EmailMessage message = new EmailMessage() @@ -145,11 +145,11 @@ public void sendEmailWithInlineAttachment() { EmailClient emailClient = createEmailClientWithConnectionString(); // BEGIN: readme-sample-sendEmailWithInlineAttachment - BinaryData attachmentContent = BinaryData.fromFile(new File("C:/inlineimage.jpg").toPath()); + String attachmentContent = BinaryData.fromFile(new File("C:/attachment.txt").toPath()).toString(); EmailAttachment attachment = new EmailAttachment( "inlineimage.jpg", "image/jpeg", - BinaryData.fromString("test").toBytes() + "test" ); attachment.setContentId("inline_image"); diff --git a/sdk/communication/azure-communication-email/src/test/java/com/azure/communication/email/EmailAsyncClientTests.java b/sdk/communication/azure-communication-email/src/test/java/com/azure/communication/email/EmailAsyncClientTests.java index 06f8afaae0673..e3a71b3e11677 100644 --- a/sdk/communication/azure-communication-email/src/test/java/com/azure/communication/email/EmailAsyncClientTests.java +++ b/sdk/communication/azure-communication-email/src/test/java/com/azure/communication/email/EmailAsyncClientTests.java @@ -71,7 +71,7 @@ public void sendEmailWithAttachment(HttpClient httpClient) { EmailAttachment attachment = new EmailAttachment( "attachment.txt", "text/plain", - BinaryData.fromString("test").toBytes() + "test" ); EmailMessage message = new EmailMessage() @@ -96,7 +96,7 @@ public void sendEmailWithInlineAttachment(HttpClient httpClient) { EmailAttachment attachment = new EmailAttachment( "inlineimage.jpg", "image/jpeg", - BinaryData.fromString("test").toBytes() + "test" ); attachment.setContentId("inline_image"); diff --git a/sdk/communication/azure-communication-email/src/test/java/com/azure/communication/email/EmailClientTests.java b/sdk/communication/azure-communication-email/src/test/java/com/azure/communication/email/EmailClientTests.java index 42b3ff8d0adde..b4792ef7590d9 100644 --- a/sdk/communication/azure-communication-email/src/test/java/com/azure/communication/email/EmailClientTests.java +++ b/sdk/communication/azure-communication-email/src/test/java/com/azure/communication/email/EmailClientTests.java @@ -69,7 +69,7 @@ public void sendEmailWithAttachment(HttpClient httpClient) { EmailAttachment attachment = new EmailAttachment( "attachment.txt", "text/plain", - BinaryData.fromString("test").toBytes() + "test" ); EmailMessage message = new EmailMessage() @@ -93,7 +93,7 @@ public void sendEmailWithInlineAttachment(HttpClient httpClient) { EmailAttachment attachment = new EmailAttachment( "inlineimage.jpg", "image/jpeg", - BinaryData.fromString("test").toBytes() + "test" ); attachment.setContentId("inline_image"); From 873fa57130845b50a5996dfef7cb84c3c319f273 Mon Sep 17 00:00:00 2001 From: Nate Kimball Date: Thu, 22 Aug 2024 16:47:20 -0700 Subject: [PATCH 08/16] actually it should be BinaryData, my bad --- .../azure-communication-email/README.md | 4 ++-- .../azure-communication-email/assets.json | 2 +- .../azure-communication-email/pom.xml | 13 ------------- .../communication/email/EmailAsyncClient.java | 15 +++++++++++++-- .../implementation/models/EmailAttachment.java | 15 ++++++++------- .../email/models/EmailAttachment.java | 8 ++++---- .../azure/communication/email/ReadmeSamples.java | 4 ++-- .../email/EmailAsyncClientTests.java | 4 ++-- .../communication/email/EmailClientTests.java | 4 ++-- 9 files changed, 34 insertions(+), 35 deletions(-) diff --git a/sdk/communication/azure-communication-email/README.md b/sdk/communication/azure-communication-email/README.md index 6a59340ee7615..2d9a0acc29e77 100644 --- a/sdk/communication/azure-communication-email/README.md +++ b/sdk/communication/azure-communication-email/README.md @@ -177,7 +177,7 @@ BinaryData attachmentContent = BinaryData.fromFile(new File("C:/attachment.txt") EmailAttachment attachment = new EmailAttachment( "attachment.txt", "text/plain", - attachmentContent.toBytes() + attachmentContent ); EmailMessage message = new EmailMessage() @@ -203,7 +203,7 @@ BinaryData attachmentContent = BinaryData.fromFile(new File("C:/inlineimage.jpg" EmailAttachment attachment = new EmailAttachment( "inlineimage.jpg", "image/jpeg", - BinaryData.fromString("test").toBytes() + BinaryData.fromString("test") ); attachment.setContentId("inline_image"); diff --git a/sdk/communication/azure-communication-email/assets.json b/sdk/communication/azure-communication-email/assets.json index 6b41ebc3d5ef8..4eb46ba0aa887 100644 --- a/sdk/communication/azure-communication-email/assets.json +++ b/sdk/communication/azure-communication-email/assets.json @@ -2,5 +2,5 @@ "AssetsRepo": "Azure/azure-sdk-assets", "AssetsRepoPrefixPath": "java", "TagPrefix": "java/communication/azure-communication-email", - "Tag": "java/communication/azure-communication-email_565857179a" + "Tag": "java/communication/azure-communication-email_50f2f82209" } diff --git a/sdk/communication/azure-communication-email/pom.xml b/sdk/communication/azure-communication-email/pom.xml index 6695c214ddabd..e7d22af6505b5 100644 --- a/sdk/communication/azure-communication-email/pom.xml +++ b/sdk/communication/azure-communication-email/pom.xml @@ -109,19 +109,6 @@ - - maven-assembly-plugin - - - - com.azure.communication.email.App - - - - jar-with-dependencies - - - com.azure.tools codesnippet-maven-plugin diff --git a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/EmailAsyncClient.java b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/EmailAsyncClient.java index 0b99469d4d596..e4a86fa4a630e 100644 --- a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/EmailAsyncClient.java +++ b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/EmailAsyncClient.java @@ -93,11 +93,22 @@ PollerFlux 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(), attachment.getContentInBase64() - )); + ); + + String contentId = attachment.getContentId(); + + if (contentId != null) + { + attachmentImpl.setContentId(contentId); + } + + attachmentsImpl.add(attachmentImpl); } } diff --git a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/models/EmailAttachment.java b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/models/EmailAttachment.java index 1c7e3da112da6..dbc74db020a55 100644 --- a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/models/EmailAttachment.java +++ b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/models/EmailAttachment.java @@ -5,6 +5,7 @@ package com.azure.communication.email.implementation.models; import com.azure.core.annotation.Fluent; +import com.azure.core.util.BinaryData; import com.azure.core.util.CoreUtils; import com.azure.json.JsonReader; import com.azure.json.JsonSerializable; @@ -32,7 +33,7 @@ public final class EmailAttachment implements JsonSerializable /* * Base64 encoded contents of the attachment */ - private final byte[] contentInBase64; + private final BinaryData contentInBase64; /* * Unique identifier (CID) to reference an inline attachment. @@ -46,7 +47,7 @@ public final class EmailAttachment implements JsonSerializable * @param contentType the contentType value to set. * @param contentInBase64 the contentInBase64 value to set. */ - public EmailAttachment(String name, String contentType, byte[] contentInBase64) { + public EmailAttachment(String name, String contentType, BinaryData contentInBase64) { this.name = name; this.contentType = contentType; this.contentInBase64 = contentInBase64; @@ -75,8 +76,8 @@ public String getContentType() { * * @return the contentInBase64 value. */ - public byte[] getContentInBase64() { - return CoreUtils.clone(this.contentInBase64); + public BinaryData getContentInBase64() { + return this.contentInBase64; } /** @@ -107,7 +108,7 @@ public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { jsonWriter.writeStartObject(); jsonWriter.writeStringField("name", this.name); jsonWriter.writeStringField("contentType", this.contentType); - jsonWriter.writeBinaryField("contentInBase64", this.contentInBase64); + jsonWriter.writeStringField("contentInBase64", this.contentInBase64.toString()); jsonWriter.writeStringField("contentId", this.contentId); return jsonWriter.writeEndObject(); } @@ -128,7 +129,7 @@ public static EmailAttachment fromJson(JsonReader jsonReader) throws IOException boolean contentTypeFound = false; String contentType = null; boolean contentInBase64Found = false; - byte[] contentInBase64 = null; + BinaryData contentInBase64 = null; String contentId = null; while (reader.nextToken() != JsonToken.END_OBJECT) { String fieldName = reader.getFieldName(); @@ -141,7 +142,7 @@ public static EmailAttachment fromJson(JsonReader jsonReader) throws IOException contentType = reader.getString(); contentTypeFound = true; } else if ("contentInBase64".equals(fieldName)) { - contentInBase64 = reader.getBinary(); + contentInBase64 = BinaryData.fromString(reader.getBinary().toString()); contentInBase64Found = true; } else if ("contentId".equals(fieldName)) { contentId = reader.getString(); diff --git a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/models/EmailAttachment.java b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/models/EmailAttachment.java index ab8d90ecbe7ed..1385472c6cafb 100644 --- a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/models/EmailAttachment.java +++ b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/models/EmailAttachment.java @@ -21,7 +21,7 @@ public final class EmailAttachment { /* * Base64 encoded contents of the attachment */ - private final byte[] contentInBase64; + private final BinaryData contentInBase64; /* * Unique identifier (CID) to reference an inline attachment. @@ -35,7 +35,7 @@ public final class EmailAttachment { * @param contentType the contentType value to set. * @param contentInBase64 the contentInBase64 value to set. */ - public EmailAttachment(String name, String contentType, byte[] contentInBase64) { + public EmailAttachment(String name, String contentType, BinaryData contentInBase64) { this.name = name; this.contentType = contentType; this.contentInBase64 = contentInBase64; @@ -64,8 +64,8 @@ public String getContentType() { * * @return the contentInBase64 value. */ - public byte[] getContentInBase64() { - return CoreUtils.clone(this.contentInBase64); + public BinaryData getContentInBase64() { + return this.contentInBase64; } /** diff --git a/sdk/communication/azure-communication-email/src/samples/java/com/azure/communication/email/ReadmeSamples.java b/sdk/communication/azure-communication-email/src/samples/java/com/azure/communication/email/ReadmeSamples.java index d1374ff023190..01e7698a2e414 100644 --- a/sdk/communication/azure-communication-email/src/samples/java/com/azure/communication/email/ReadmeSamples.java +++ b/sdk/communication/azure-communication-email/src/samples/java/com/azure/communication/email/ReadmeSamples.java @@ -124,7 +124,7 @@ public void sendEmailWithAttachment() { EmailAttachment attachment = new EmailAttachment( "attachment.txt", "text/plain", - attachmentContent.toBytes() + attachmentContent ); EmailMessage message = new EmailMessage() @@ -149,7 +149,7 @@ public void sendEmailWithInlineAttachment() { EmailAttachment attachment = new EmailAttachment( "inlineimage.jpg", "image/jpeg", - BinaryData.fromString("test").toBytes() + BinaryData.fromString("test") ); attachment.setContentId("inline_image"); diff --git a/sdk/communication/azure-communication-email/src/test/java/com/azure/communication/email/EmailAsyncClientTests.java b/sdk/communication/azure-communication-email/src/test/java/com/azure/communication/email/EmailAsyncClientTests.java index 06f8afaae0673..b18e615514b46 100644 --- a/sdk/communication/azure-communication-email/src/test/java/com/azure/communication/email/EmailAsyncClientTests.java +++ b/sdk/communication/azure-communication-email/src/test/java/com/azure/communication/email/EmailAsyncClientTests.java @@ -71,7 +71,7 @@ public void sendEmailWithAttachment(HttpClient httpClient) { EmailAttachment attachment = new EmailAttachment( "attachment.txt", "text/plain", - BinaryData.fromString("test").toBytes() + BinaryData.fromString("test") ); EmailMessage message = new EmailMessage() @@ -96,7 +96,7 @@ public void sendEmailWithInlineAttachment(HttpClient httpClient) { EmailAttachment attachment = new EmailAttachment( "inlineimage.jpg", "image/jpeg", - BinaryData.fromString("test").toBytes() + BinaryData.fromString("test") ); attachment.setContentId("inline_image"); diff --git a/sdk/communication/azure-communication-email/src/test/java/com/azure/communication/email/EmailClientTests.java b/sdk/communication/azure-communication-email/src/test/java/com/azure/communication/email/EmailClientTests.java index 42b3ff8d0adde..a64dd3e1d73c8 100644 --- a/sdk/communication/azure-communication-email/src/test/java/com/azure/communication/email/EmailClientTests.java +++ b/sdk/communication/azure-communication-email/src/test/java/com/azure/communication/email/EmailClientTests.java @@ -69,7 +69,7 @@ public void sendEmailWithAttachment(HttpClient httpClient) { EmailAttachment attachment = new EmailAttachment( "attachment.txt", "text/plain", - BinaryData.fromString("test").toBytes() + BinaryData.fromString("test") ); EmailMessage message = new EmailMessage() @@ -93,7 +93,7 @@ public void sendEmailWithInlineAttachment(HttpClient httpClient) { EmailAttachment attachment = new EmailAttachment( "inlineimage.jpg", "image/jpeg", - BinaryData.fromString("test").toBytes() + BinaryData.fromString("test") ); attachment.setContentId("inline_image"); From f379458d17a98ae3ded921a6c80c05842711dfd0 Mon Sep 17 00:00:00 2001 From: Nate Kimball Date: Thu, 22 Aug 2024 16:56:40 -0700 Subject: [PATCH 09/16] merge miss --- sdk/communication/azure-communication-email/README.md | 4 ++-- .../java/com/azure/communication/email/ReadmeSamples.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/sdk/communication/azure-communication-email/README.md b/sdk/communication/azure-communication-email/README.md index 889db3a8495c4..4329a7edaffe2 100644 --- a/sdk/communication/azure-communication-email/README.md +++ b/sdk/communication/azure-communication-email/README.md @@ -173,7 +173,7 @@ System.out.println("Operation Id: " + response.getValue().getId()); Azure Communication Services support sending email with attachments. ```java readme-sample-sendEmailWithAttachment -String attachmentContent = BinaryData.fromFile(new File("C:/attachment.txt").toPath()).toString(); +BinaryData attachmentContent = BinaryData.fromFile(new File("C:/attachment.txt").toPath()); EmailAttachment attachment = new EmailAttachment( "attachment.txt", "text/plain", @@ -199,7 +199,7 @@ 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 -String attachmentContent = BinaryData.fromFile(new File("C:/attachment.txt").toPath()).toString(); +BinaryData attachmentContent = BinaryData.fromFile(new File("C:/attachment.txt").toPath()); EmailAttachment attachment = new EmailAttachment( "inlineimage.jpg", "image/jpeg", diff --git a/sdk/communication/azure-communication-email/src/samples/java/com/azure/communication/email/ReadmeSamples.java b/sdk/communication/azure-communication-email/src/samples/java/com/azure/communication/email/ReadmeSamples.java index 4bbf611f8cdde..22d32bca6279b 100644 --- a/sdk/communication/azure-communication-email/src/samples/java/com/azure/communication/email/ReadmeSamples.java +++ b/sdk/communication/azure-communication-email/src/samples/java/com/azure/communication/email/ReadmeSamples.java @@ -120,7 +120,7 @@ public void sendEmailWithAttachment() { EmailClient emailClient = createEmailClientWithConnectionString(); // BEGIN: readme-sample-sendEmailWithAttachment - String attachmentContent = BinaryData.fromFile(new File("C:/attachment.txt").toPath()).toString(); + BinaryData attachmentContent = BinaryData.fromFile(new File("C:/attachment.txt").toPath()); EmailAttachment attachment = new EmailAttachment( "attachment.txt", "text/plain", @@ -145,7 +145,7 @@ public void sendEmailWithInlineAttachment() { EmailClient emailClient = createEmailClientWithConnectionString(); // BEGIN: readme-sample-sendEmailWithInlineAttachment - String attachmentContent = BinaryData.fromFile(new File("C:/attachment.txt").toPath()).toString(); + BinaryData attachmentContent = BinaryData.fromFile(new File("C:/attachment.txt").toPath()); EmailAttachment attachment = new EmailAttachment( "inlineimage.jpg", "image/jpeg", From 41541fed88cb161fd9ba5141a530969c198b297d Mon Sep 17 00:00:00 2001 From: Nate Kimball Date: Thu, 22 Aug 2024 17:13:42 -0700 Subject: [PATCH 10/16] fixing linting errors and sample --- sdk/communication/azure-communication-email/README.md | 2 +- .../java/com/azure/communication/email/EmailAsyncClient.java | 5 ++--- .../java/com/azure/communication/email/ReadmeSamples.java | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/sdk/communication/azure-communication-email/README.md b/sdk/communication/azure-communication-email/README.md index 4329a7edaffe2..c4a6f09d0324f 100644 --- a/sdk/communication/azure-communication-email/README.md +++ b/sdk/communication/azure-communication-email/README.md @@ -203,7 +203,7 @@ BinaryData attachmentContent = BinaryData.fromFile(new File("C:/attachment.txt") EmailAttachment attachment = new EmailAttachment( "inlineimage.jpg", "image/jpeg", - BinaryData.fromString("test") + attachmentContent ); attachment.setContentId("inline_image"); diff --git a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/EmailAsyncClient.java b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/EmailAsyncClient.java index e4a86fa4a630e..68b976ad3ca2a 100644 --- a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/EmailAsyncClient.java +++ b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/EmailAsyncClient.java @@ -103,10 +103,9 @@ PollerFlux beginSend(EmailMessage message, Con String contentId = attachment.getContentId(); - if (contentId != null) - { + if (contentId != null) { attachmentImpl.setContentId(contentId); - } + } attachmentsImpl.add(attachmentImpl); } diff --git a/sdk/communication/azure-communication-email/src/samples/java/com/azure/communication/email/ReadmeSamples.java b/sdk/communication/azure-communication-email/src/samples/java/com/azure/communication/email/ReadmeSamples.java index 22d32bca6279b..8229461473825 100644 --- a/sdk/communication/azure-communication-email/src/samples/java/com/azure/communication/email/ReadmeSamples.java +++ b/sdk/communication/azure-communication-email/src/samples/java/com/azure/communication/email/ReadmeSamples.java @@ -149,7 +149,7 @@ public void sendEmailWithInlineAttachment() { EmailAttachment attachment = new EmailAttachment( "inlineimage.jpg", "image/jpeg", - BinaryData.fromString("test") + attachmentContent ); attachment.setContentId("inline_image"); From a897f73d409213e6ec2d6d848237e068fa79c863 Mon Sep 17 00:00:00 2001 From: Nate Kimball Date: Thu, 22 Aug 2024 17:14:38 -0700 Subject: [PATCH 11/16] linting error --- .../java/com/azure/communication/email/EmailAsyncClient.java | 1 - 1 file changed, 1 deletion(-) diff --git a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/EmailAsyncClient.java b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/EmailAsyncClient.java index 68b976ad3ca2a..8c8e5a171f8f2 100644 --- a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/EmailAsyncClient.java +++ b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/EmailAsyncClient.java @@ -23,7 +23,6 @@ import java.time.Duration; import java.util.ArrayList; -import java.util.Base64; import java.util.List; import java.util.Objects; From fd9ce5ac4f2b0fdb7a77797ea11d348653b1b1a4 Mon Sep 17 00:00:00 2001 From: Nate Kimball Date: Thu, 22 Aug 2024 17:34:27 -0700 Subject: [PATCH 12/16] another linting error --- .../email/implementation/models/EmailAttachment.java | 1 - 1 file changed, 1 deletion(-) diff --git a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/models/EmailAttachment.java b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/models/EmailAttachment.java index dbc74db020a55..3fc56c9dec836 100644 --- a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/models/EmailAttachment.java +++ b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/models/EmailAttachment.java @@ -6,7 +6,6 @@ import com.azure.core.annotation.Fluent; import com.azure.core.util.BinaryData; -import com.azure.core.util.CoreUtils; import com.azure.json.JsonReader; import com.azure.json.JsonSerializable; import com.azure.json.JsonToken; From 25378754e41e227e3e2a311b3c4329204f942170 Mon Sep 17 00:00:00 2001 From: Nate Kimball Date: Fri, 23 Aug 2024 10:28:55 -0700 Subject: [PATCH 13/16] adding older methods to bypass linting errors --- .../communication/email/EmailServiceVersion.java | 7 +++++-- .../email/implementation/models/EmailAttachment.java | 11 +++++++++++ .../communication/email/models/EmailAttachment.java | 11 +++++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/EmailServiceVersion.java b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/EmailServiceVersion.java index ad39b542b2646..a115a5dfa6b3f 100644 --- a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/EmailServiceVersion.java +++ b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/EmailServiceVersion.java @@ -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 2024-07-01-preview. */ - V2024_07_01_Preview("2024-07-01-preview"); + V2024_07_01_Preview("2024-07-01-preview"), + + /** Enum value 2023-03-31. */ + V2023_03_31("2023-03-31"); private final String version; diff --git a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/models/EmailAttachment.java b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/models/EmailAttachment.java index 3fc56c9dec836..db726727d4a4c 100644 --- a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/models/EmailAttachment.java +++ b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/models/EmailAttachment.java @@ -70,6 +70,17 @@ public String getContentType() { return this.contentType; } + /** + * @deprecated Use {@link #getContentInBase64()} instead. + * Returns the content of the attachment. + * + * @return The content of the attachment as BinaryData. + */ + @Deprecated + public BinaryData getContent() { + return this.contentInBase64; + } + /** * Get the contentInBase64 property: Base64 encoded contents of the attachment. * diff --git a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/models/EmailAttachment.java b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/models/EmailAttachment.java index 07af300a48ef4..9855cee6df283 100644 --- a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/models/EmailAttachment.java +++ b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/models/EmailAttachment.java @@ -58,6 +58,17 @@ public String getContentType() { return this.contentType; } + /** + * @deprecated Use {@link #getContentInBase64()} instead. + * Returns the content of the attachment. + * + * @return The content of the attachment as BinaryData. + */ + @Deprecated + public BinaryData getContent() { + return this.contentInBase64; + } + /** * Get the contentInBase64 property: Base64 encoded contents of the attachment. * From 9f6d7efe516157fa2a1ff7b9116ebe1e36b7c0a8 Mon Sep 17 00:00:00 2001 From: Nate Kimball Date: Fri, 23 Aug 2024 12:10:28 -0700 Subject: [PATCH 14/16] reordering enum for linting error in pipeline --- .../azure/communication/email/EmailServiceVersion.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/EmailServiceVersion.java b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/EmailServiceVersion.java index a115a5dfa6b3f..1f7267ac72ae7 100644 --- a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/EmailServiceVersion.java +++ b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/EmailServiceVersion.java @@ -8,11 +8,11 @@ /** Service version of EmailCommunicationServicesClient. */ public enum EmailServiceVersion implements ServiceVersion { - /** Enum value 2024-07-01-preview. */ - V2024_07_01_Preview("2024-07-01-preview"), - /** 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; From c19f2d250d6b8375af374dbd514010bb0fd5f6cc Mon Sep 17 00:00:00 2001 From: Nate Kimball Date: Fri, 23 Aug 2024 16:27:29 -0700 Subject: [PATCH 15/16] cleaning up trailing whitespace --- .../communication/email/EmailAsyncClient.java | 2 +- .../AzureCommunicationEmailServiceImpl.java | 16 ++++++------ .../email/implementation/EmailsImpl.java | 18 ++++++------- .../models/EmailAttachment.java | 14 +++++----- .../implementation/models/EmailMessage.java | 26 +++++++++---------- .../email/models/EmailAttachment.java | 12 ++++----- .../communication/email/ReadmeSamples.java | 4 +-- 7 files changed, 46 insertions(+), 46 deletions(-) diff --git a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/EmailAsyncClient.java b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/EmailAsyncClient.java index 8c8e5a171f8f2..e1c85aa87bb20 100644 --- a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/EmailAsyncClient.java +++ b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/EmailAsyncClient.java @@ -93,7 +93,7 @@ PollerFlux beginSend(EmailMessage message, Con attachmentsImpl = new ArrayList<>(); for (EmailAttachment attachment: message.getAttachments()) { com.azure.communication.email.implementation.models.EmailAttachment attachmentImpl = null; - + attachmentImpl = new com.azure.communication.email.implementation.models.EmailAttachment( attachment.getName(), attachment.getContentType(), diff --git a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/AzureCommunicationEmailServiceImpl.java b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/AzureCommunicationEmailServiceImpl.java index 0dbab18ecf066..d70c8449f935f 100644 --- a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/AzureCommunicationEmailServiceImpl.java +++ b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/AzureCommunicationEmailServiceImpl.java @@ -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() { @@ -36,7 +36,7 @@ public String getEndpoint() { /** * Gets Api Version. - * + * * @return the apiVersion value. */ public String getApiVersion() { @@ -50,7 +50,7 @@ public String getApiVersion() { /** * Gets The HTTP pipeline to send requests through. - * + * * @return the httpPipeline value. */ public HttpPipeline getHttpPipeline() { @@ -64,7 +64,7 @@ public HttpPipeline getHttpPipeline() { /** * Gets The serializer to serialize an object into a string. - * + * * @return the serializerAdapter value. */ public SerializerAdapter getSerializerAdapter() { @@ -78,7 +78,7 @@ public SerializerAdapter getSerializerAdapter() { /** * Gets the EmailsImpl object to access its operations. - * + * * @return the EmailsImpl object. */ public EmailsImpl getEmails() { @@ -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. */ @@ -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. @@ -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. diff --git a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/EmailsImpl.java b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/EmailsImpl.java index e235dc47b6889..df2d549ddb87a 100644 --- a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/EmailsImpl.java +++ b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/EmailsImpl.java @@ -49,7 +49,7 @@ public final class EmailsImpl { /** * Initializes an instance of EmailsImpl. - * + * * @param client the instance of the service client containing this operation class. */ EmailsImpl(AzureCommunicationEmailServiceImpl client) { @@ -82,7 +82,7 @@ Mono send(@HostParam("endpoint") String endpoint, /** * Gets the status of the email send operation. - * + * * @param operationId ID of the long running operation (GUID) returned from a previous call to send email. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws ErrorResponseException thrown if the request is rejected by server. @@ -98,7 +98,7 @@ public Mono getSendResultWithResponseAsync(String o /** * Gets the status of the email send operation. - * + * * @param operationId ID of the long running operation (GUID) returned from a previous call to send email. * @param context The context to associate with this operation. * @throws IllegalArgumentException thrown if parameters fail the validation. @@ -115,7 +115,7 @@ public Mono getSendResultWithResponseAsync(String o /** * Gets the status of the email send operation. - * + * * @param operationId ID of the long running operation (GUID) returned from a previous call to send email. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws ErrorResponseException thrown if the request is rejected by server. @@ -129,7 +129,7 @@ public Mono getSendResultAsync(String operationId) { /** * Gets the status of the email send operation. - * + * * @param operationId ID of the long running operation (GUID) returned from a previous call to send email. * @param context The context to associate with this operation. * @throws IllegalArgumentException thrown if parameters fail the validation. @@ -144,7 +144,7 @@ public Mono getSendResultAsync(String operationId, Context cont /** * Queues an email message to be sent to one or more recipients. - * + * * @param message Message payload for sending an email. * @param operationId This is the ID provided by the customer to identify the long running operation. If an ID is * not provided by the customer, the service will generate one. @@ -164,7 +164,7 @@ public Mono sendWithResponseAsync(EmailMessage message, UUID /** * Queues an email message to be sent to one or more recipients. - * + * * @param message Message payload for sending an email. * @param operationId This is the ID provided by the customer to identify the long running operation. If an ID is * not provided by the customer, the service will generate one. @@ -185,7 +185,7 @@ public Mono sendWithResponseAsync(EmailMessage message, UUID /** * Queues an email message to be sent to one or more recipients. - * + * * @param message Message payload for sending an email. * @param operationId This is the ID provided by the customer to identify the long running operation. If an ID is * not provided by the customer, the service will generate one. @@ -208,7 +208,7 @@ public PollerFlux beginSendAsync(EmailMessage /** * Queues an email message to be sent to one or more recipients. - * + * * @param message Message payload for sending an email. * @param operationId This is the ID provided by the customer to identify the long running operation. If an ID is * not provided by the customer, the service will generate one. diff --git a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/models/EmailAttachment.java b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/models/EmailAttachment.java index db726727d4a4c..8ebca3d865db5 100644 --- a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/models/EmailAttachment.java +++ b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/models/EmailAttachment.java @@ -41,7 +41,7 @@ public final class EmailAttachment implements JsonSerializable /** * Creates an instance of EmailAttachment class. - * + * * @param name the name value to set. * @param contentType the contentType value to set. * @param contentInBase64 the contentInBase64 value to set. @@ -54,7 +54,7 @@ public EmailAttachment(String name, String contentType, BinaryData contentInBase /** * Get the name property: Name of the attachment. - * + * * @return the name value. */ public String getName() { @@ -63,7 +63,7 @@ public String getName() { /** * Get the contentType property: MIME type of the content being attached. - * + * * @return the contentType value. */ public String getContentType() { @@ -83,7 +83,7 @@ public BinaryData getContent() { /** * Get the contentInBase64 property: Base64 encoded contents of the attachment. - * + * * @return the contentInBase64 value. */ public BinaryData getContentInBase64() { @@ -92,7 +92,7 @@ public BinaryData getContentInBase64() { /** * Get the contentId property: Unique identifier (CID) to reference an inline attachment. - * + * * @return the contentId value. */ public String getContentId() { @@ -101,7 +101,7 @@ public String getContentId() { /** * Set the contentId property: Unique identifier (CID) to reference an inline attachment. - * + * * @param contentId the contentId value to set. * @return the EmailAttachment object itself. */ @@ -125,7 +125,7 @@ public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { /** * Reads an instance of EmailAttachment from the JsonReader. - * + * * @param jsonReader The JsonReader being read. * @return An instance of EmailAttachment if the JsonReader was pointing to an instance of it, or null if it was * pointing to JSON null. diff --git a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/models/EmailMessage.java b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/models/EmailMessage.java index 81332225d78a9..77c47a92d9926 100644 --- a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/models/EmailMessage.java +++ b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/implementation/models/EmailMessage.java @@ -59,7 +59,7 @@ public final class EmailMessage implements JsonSerializable { /** * Creates an instance of EmailMessage class. - * + * * @param senderAddress the senderAddress value to set. * @param content the content value to set. * @param recipients the recipients value to set. @@ -72,7 +72,7 @@ public EmailMessage(String senderAddress, EmailContent content, EmailRecipients /** * Get the headers property: Custom email headers to be passed. - * + * * @return the headers value. */ public Map getHeaders() { @@ -81,7 +81,7 @@ public Map getHeaders() { /** * Set the headers property: Custom email headers to be passed. - * + * * @param headers the headers value to set. * @return the EmailMessage object itself. */ @@ -92,7 +92,7 @@ public EmailMessage setHeaders(Map headers) { /** * Get the senderAddress property: Sender email address from a verified domain. - * + * * @return the senderAddress value. */ public String getSenderAddress() { @@ -101,7 +101,7 @@ public String getSenderAddress() { /** * Get the content property: Email content to be sent. - * + * * @return the content value. */ public EmailContent getContent() { @@ -110,7 +110,7 @@ public EmailContent getContent() { /** * Get the recipients property: Recipients for the email. - * + * * @return the recipients value. */ public EmailRecipients getRecipients() { @@ -120,7 +120,7 @@ public EmailRecipients getRecipients() { /** * Get the attachments property: List of attachments. Please note that we limit the total size of an email request * (which includes both regular and inline attachments) to 10MB. - * + * * @return the attachments value. */ public List getAttachments() { @@ -130,7 +130,7 @@ public List getAttachments() { /** * Set the attachments property: List of attachments. Please note that we limit the total size of an email request * (which includes both regular and inline attachments) to 10MB. - * + * * @param attachments the attachments value to set. * @return the EmailMessage object itself. */ @@ -141,7 +141,7 @@ public EmailMessage setAttachments(List attachments) { /** * Get the replyTo property: Email addresses where recipients' replies will be sent to. - * + * * @return the replyTo value. */ public List getReplyTo() { @@ -150,7 +150,7 @@ public List getReplyTo() { /** * Set the replyTo property: Email addresses where recipients' replies will be sent to. - * + * * @param replyTo the replyTo value to set. * @return the EmailMessage object itself. */ @@ -162,7 +162,7 @@ public EmailMessage setReplyTo(List replyTo) { /** * Get the userEngagementTrackingDisabled property: Indicates whether user engagement tracking should be disabled * for this request if the resource-level user engagement tracking setting was already enabled in the control plane. - * + * * @return the userEngagementTrackingDisabled value. */ public Boolean isUserEngagementTrackingDisabled() { @@ -172,7 +172,7 @@ public Boolean isUserEngagementTrackingDisabled() { /** * Set the userEngagementTrackingDisabled property: Indicates whether user engagement tracking should be disabled * for this request if the resource-level user engagement tracking setting was already enabled in the control plane. - * + * * @param userEngagementTrackingDisabled the userEngagementTrackingDisabled value to set. * @return the EmailMessage object itself. */ @@ -199,7 +199,7 @@ public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { /** * Reads an instance of EmailMessage from the JsonReader. - * + * * @param jsonReader The JsonReader being read. * @return An instance of EmailMessage if the JsonReader was pointing to an instance of it, or null if it was * pointing to JSON null. diff --git a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/models/EmailAttachment.java b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/models/EmailAttachment.java index 9855cee6df283..3e67120fd9b93 100644 --- a/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/models/EmailAttachment.java +++ b/sdk/communication/azure-communication-email/src/main/java/com/azure/communication/email/models/EmailAttachment.java @@ -29,7 +29,7 @@ public final class EmailAttachment { /** * Creates an instance of EmailAttachment class. - * + * * @param name the name value to set. * @param contentType the contentType value to set. * @param contentInBase64 the contentInBase64 value to set. @@ -42,7 +42,7 @@ public EmailAttachment(String name, String contentType, BinaryData contentInBase /** * Get the name property: Name of the attachment. - * + * * @return the name value. */ public String getName() { @@ -51,7 +51,7 @@ public String getName() { /** * Get the contentType property: MIME type of the content being attached. - * + * * @return the contentType value. */ public String getContentType() { @@ -71,7 +71,7 @@ public BinaryData getContent() { /** * Get the contentInBase64 property: Base64 encoded contents of the attachment. - * + * * @return the contentInBase64 value. */ public BinaryData getContentInBase64() { @@ -80,7 +80,7 @@ public BinaryData getContentInBase64() { /** * Get the contentId property: Unique identifier (CID) to reference an inline attachment. - * + * * @return the contentId value. */ public String getContentId() { @@ -89,7 +89,7 @@ public String getContentId() { /** * Set the contentId property: Unique identifier (CID) to reference an inline attachment. - * + * * @param contentId the contentId value to set. * @return the EmailAttachment object itself. */ diff --git a/sdk/communication/azure-communication-email/src/samples/java/com/azure/communication/email/ReadmeSamples.java b/sdk/communication/azure-communication-email/src/samples/java/com/azure/communication/email/ReadmeSamples.java index 8229461473825..aac17c2b82501 100644 --- a/sdk/communication/azure-communication-email/src/samples/java/com/azure/communication/email/ReadmeSamples.java +++ b/sdk/communication/azure-communication-email/src/samples/java/com/azure/communication/email/ReadmeSamples.java @@ -126,7 +126,7 @@ public void sendEmailWithAttachment() { "text/plain", attachmentContent ); - + EmailMessage message = new EmailMessage() .setSenderAddress("") .setToRecipients("") @@ -152,7 +152,7 @@ public void sendEmailWithInlineAttachment() { attachmentContent ); attachment.setContentId("inline_image"); - + EmailMessage message = new EmailMessage() .setSenderAddress("") .setToRecipients("") From 477d54128e5a5bd257a054193c20742dcfd58f4e Mon Sep 17 00:00:00 2001 From: Nate Kimball Date: Mon, 26 Aug 2024 18:20:56 -0700 Subject: [PATCH 16/16] appending setContentId to end of constructor call --- sdk/communication/azure-communication-email/README.md | 3 +-- .../java/com/azure/communication/email/ReadmeSamples.java | 3 +-- .../com/azure/communication/email/EmailAsyncClientTests.java | 3 +-- .../java/com/azure/communication/email/EmailClientTests.java | 3 +-- 4 files changed, 4 insertions(+), 8 deletions(-) diff --git a/sdk/communication/azure-communication-email/README.md b/sdk/communication/azure-communication-email/README.md index c4a6f09d0324f..cb2f80efcedba 100644 --- a/sdk/communication/azure-communication-email/README.md +++ b/sdk/communication/azure-communication-email/README.md @@ -204,8 +204,7 @@ EmailAttachment attachment = new EmailAttachment( "inlineimage.jpg", "image/jpeg", attachmentContent -); -attachment.setContentId("inline_image"); +).setContentId("inline_image"); EmailMessage message = new EmailMessage() .setSenderAddress("") diff --git a/sdk/communication/azure-communication-email/src/samples/java/com/azure/communication/email/ReadmeSamples.java b/sdk/communication/azure-communication-email/src/samples/java/com/azure/communication/email/ReadmeSamples.java index aac17c2b82501..19c68741aac09 100644 --- a/sdk/communication/azure-communication-email/src/samples/java/com/azure/communication/email/ReadmeSamples.java +++ b/sdk/communication/azure-communication-email/src/samples/java/com/azure/communication/email/ReadmeSamples.java @@ -150,8 +150,7 @@ public void sendEmailWithInlineAttachment() { "inlineimage.jpg", "image/jpeg", attachmentContent - ); - attachment.setContentId("inline_image"); + ).setContentId("inline_image"); EmailMessage message = new EmailMessage() .setSenderAddress("") diff --git a/sdk/communication/azure-communication-email/src/test/java/com/azure/communication/email/EmailAsyncClientTests.java b/sdk/communication/azure-communication-email/src/test/java/com/azure/communication/email/EmailAsyncClientTests.java index b18e615514b46..7d2e4ffe29cb2 100644 --- a/sdk/communication/azure-communication-email/src/test/java/com/azure/communication/email/EmailAsyncClientTests.java +++ b/sdk/communication/azure-communication-email/src/test/java/com/azure/communication/email/EmailAsyncClientTests.java @@ -97,8 +97,7 @@ public void sendEmailWithInlineAttachment(HttpClient httpClient) { "inlineimage.jpg", "image/jpeg", BinaryData.fromString("test") - ); - attachment.setContentId("inline_image"); + ).setContentId("inline_image"); EmailMessage message = new EmailMessage() .setSenderAddress(SENDER_ADDRESS) diff --git a/sdk/communication/azure-communication-email/src/test/java/com/azure/communication/email/EmailClientTests.java b/sdk/communication/azure-communication-email/src/test/java/com/azure/communication/email/EmailClientTests.java index a64dd3e1d73c8..db383b54bfbc6 100644 --- a/sdk/communication/azure-communication-email/src/test/java/com/azure/communication/email/EmailClientTests.java +++ b/sdk/communication/azure-communication-email/src/test/java/com/azure/communication/email/EmailClientTests.java @@ -94,8 +94,7 @@ public void sendEmailWithInlineAttachment(HttpClient httpClient) { "inlineimage.jpg", "image/jpeg", BinaryData.fromString("test") - ); - attachment.setContentId("inline_image"); + ).setContentId("inline_image"); EmailMessage message = new EmailMessage() .setSenderAddress(SENDER_ADDRESS)