Skip to content

Commit 142916f

Browse files
Update ACS Email python SDK for inline attachments (#37069)
* Initial commit for inline attachments * Updating changelog and test recordings * ignore spelling of myinlineimage * Address PR feedback
1 parent b057362 commit 142916f

20 files changed

+338
-35
lines changed

sdk/communication/azure-communication-email/CHANGELOG.md

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
# Release History
22

3-
## 1.0.1 (Unreleased)
3+
## 1.0.1b1 (2024-08-28)
44

55
### Features Added
66

7-
### Breaking Changes
8-
9-
### Bugs Fixed
10-
11-
### Other Changes
7+
- Consumers can now provide a value for the `contentId` property when sending emails with attachments.
8+
This allows consumers to reference attachments in the email body using the `cid` scheme. The `contentId` property can be set on the `EmailAttachment` object.
129

1310
## 1.0.0 (2023-03-31)
1411

@@ -26,7 +23,7 @@ The public release of the Azure Communication Services SDK for Email has the fol
2623

2724
### Breaking Changes
2825
- Made the SDK Model-less. Objects are now constructed using a dictionary instead of a model.
29-
- Reworked the SDK to follow the LRO (long running operation) approach. The 'begin_send' method returns a poller that can be used to check for the status of sending the email and retrieve the result. The return object has been adjusted to fit this approach.
26+
- Reworked the SDK to follow the LRO (long running operation) approach. The 'begin_send' method returns a poller that can be used to check for the status of sending the email and retrieve the result. The return object has been adjusted to fit this approach.
3027
- The `get_send_status` method has been removed.
3128
- The `sender` property has been changed to `senderAddress`.
3229
- The `email` property under the recipient object has been changed to `address`.

sdk/communication/azure-communication-email/README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,48 @@ poller = email_client.begin_send(message)
157157
result = poller.result()
158158
```
159159

160+
### Send Email with Inline Attachments
161+
162+
Azure Communication Services support sending inline attachments.
163+
Adding an optional `contentId` parameter to an attachment will make it an inline attachment.
164+
165+
```python
166+
import base64
167+
168+
with open("C://inline_image.jpg", "r") as file:
169+
file_contents = file.read()
170+
171+
file_bytes_b64 = base64.b64encode(bytes(file_contents, 'utf-8'))
172+
173+
message = {
174+
"content": {
175+
"subject": "This is the subject",
176+
"plainText": "This is the body",
177+
"html": "<html>This is the body<br /><img src=\"cid:my-inline-image\" /></html>"
178+
},
179+
"recipients": {
180+
"to": [
181+
{
182+
"address": "[email protected]",
183+
"displayName": "Customer Name"
184+
}
185+
]
186+
},
187+
"senderAddress": "[email protected]",
188+
"attachments": [
189+
{
190+
"name": "inline_image.jpg",
191+
"contentType": "image/jpeg",
192+
"contentInBase64": file_bytes_b64.decode(),
193+
"contentId": "my-inline-image"
194+
}
195+
]
196+
}
197+
198+
poller = email_client.begin_send(message)
199+
result = poller.result()
200+
```
201+
160202
## Troubleshooting
161203

162204
Email operations will throw an exception if the request to the server fails. The Email client will raise exceptions defined in [Azure Core](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/core/azure-core/README.md).

sdk/communication/azure-communication-email/assets.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"AssetsRepo": "Azure/azure-sdk-assets",
33
"AssetsRepoPrefixPath": "python",
44
"TagPrefix": "python/communication/azure-communication-email",
5-
"Tag": "python/communication/azure-communication-email_b3ba97a69e"
5+
"Tag": "python/communication/azure-communication-email_1fa1cede8e"
66
}

sdk/communication/azure-communication-email/azure/communication/email/_api_versions.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@
88

99

1010
class ApiVersion(str, Enum, metaclass=CaseInsensitiveEnumMeta):
11-
V2021_10_01_PREVIEW = "2021-10-01-preview"
12-
V2023_01_15_PREVIEW = "2023-01-15-preview"
1311
V2023_03_31 = "2023-03-31"
12+
V2024_07_01_PREVIEW = "2024-07-01-preview"
1413

1514

16-
DEFAULT_VERSION = ApiVersion.V2023_03_31
15+
DEFAULT_VERSION = ApiVersion.V2024_07_01_PREVIEW

sdk/communication/azure-communication-email/azure/communication/email/_email_client.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class EmailClient(object):
3333
:param Union[TokenCredential, AzureKeyCredential] credential:
3434
The credential we use to authenticate against the service.
3535
:keyword api_version: Azure Communication Email API version.
36-
Default value is "2023-03-31".
36+
Default value is "2024-07-01-preview".
3737
Note that overriding this default value may result in unsupported behavior.
3838
:paramtype api_version: str
3939
"""
@@ -137,7 +137,9 @@ def begin_send(
137137
attachment. Required.
138138
"contentType": "str", # MIME type of the content being
139139
attached. Required.
140-
"name": "str" # Name of the attachment. Required.
140+
"name": "str", # Name of the attachment. Required.
141+
"contentId": "str" # Optional. Unique identifier (CID) to
142+
reference an inline attachment.
141143
}
142144
],
143145
"userEngagementTrackingDisabled": bool, # Optional. Indicates whether user

sdk/communication/azure-communication-email/azure/communication/email/_generated/_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ class AzureCommunicationEmailService: # pylint: disable=client-accepts-api-vers
2929
:param endpoint: The communication resource, for example
3030
https://my-resource.communication.azure.com. Required.
3131
:type endpoint: str
32-
:keyword api_version: Api Version. Default value is "2023-03-31". Note that overriding this
33-
default value may result in unsupported behavior.
32+
:keyword api_version: Api Version. Default value is "2024-07-01-preview". Note that overriding
33+
this default value may result in unsupported behavior.
3434
:paramtype api_version: str
3535
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no
3636
Retry-After header is present.

sdk/communication/azure-communication-email/azure/communication/email/_generated/_configuration.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ class AzureCommunicationEmailServiceConfiguration(Configuration): # pylint: dis
2323
:param endpoint: The communication resource, for example
2424
https://my-resource.communication.azure.com. Required.
2525
:type endpoint: str
26-
:keyword api_version: Api Version. Default value is "2023-03-31". Note that overriding this
27-
default value may result in unsupported behavior.
26+
:keyword api_version: Api Version. Default value is "2024-07-01-preview". Note that overriding
27+
this default value may result in unsupported behavior.
2828
:paramtype api_version: str
2929
"""
3030

3131
def __init__(self, endpoint: str, **kwargs: Any) -> None:
3232
super(AzureCommunicationEmailServiceConfiguration, self).__init__(**kwargs)
33-
api_version = kwargs.pop("api_version", "2023-03-31") # type: str
33+
api_version = kwargs.pop("api_version", "2024-07-01-preview") # type: str
3434

3535
if endpoint is None:
3636
raise ValueError("Parameter 'endpoint' must not be None.")

sdk/communication/azure-communication-email/azure/communication/email/_generated/aio/_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ class AzureCommunicationEmailService: # pylint: disable=client-accepts-api-vers
2929
:param endpoint: The communication resource, for example
3030
https://my-resource.communication.azure.com. Required.
3131
:type endpoint: str
32-
:keyword api_version: Api Version. Default value is "2023-03-31". Note that overriding this
33-
default value may result in unsupported behavior.
32+
:keyword api_version: Api Version. Default value is "2024-07-01-preview". Note that overriding
33+
this default value may result in unsupported behavior.
3434
:paramtype api_version: str
3535
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no
3636
Retry-After header is present.

sdk/communication/azure-communication-email/azure/communication/email/_generated/aio/_configuration.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ class AzureCommunicationEmailServiceConfiguration(Configuration): # pylint: dis
2323
:param endpoint: The communication resource, for example
2424
https://my-resource.communication.azure.com. Required.
2525
:type endpoint: str
26-
:keyword api_version: Api Version. Default value is "2023-03-31". Note that overriding this
27-
default value may result in unsupported behavior.
26+
:keyword api_version: Api Version. Default value is "2024-07-01-preview". Note that overriding
27+
this default value may result in unsupported behavior.
2828
:paramtype api_version: str
2929
"""
3030

3131
def __init__(self, endpoint: str, **kwargs: Any) -> None:
3232
super(AzureCommunicationEmailServiceConfiguration, self).__init__(**kwargs)
33-
api_version = kwargs.pop("api_version", "2023-03-31") # type: str
33+
api_version = kwargs.pop("api_version", "2024-07-01-preview") # type: str
3434

3535
if endpoint is None:
3636
raise ValueError("Parameter 'endpoint' must not be None.")

sdk/communication/azure-communication-email/azure/communication/email/_generated/aio/operations/_operations.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,9 @@ async def begin_send(
271271
attachment. Required.
272272
"contentType": "str", # MIME type of the content being
273273
attached. Required.
274-
"name": "str" # Name of the attachment. Required.
274+
"name": "str", # Name of the attachment. Required.
275+
"contentId": "str" # Optional. Unique identifier (CID) to
276+
reference an inline attachment.
275277
}
276278
],
277279
"headers": {

0 commit comments

Comments
 (0)