Skip to content

Commit b2cdc90

Browse files
Update .NET SDK for inline attachments (Azure#45360)
* update .NET SDK with inline attachments * updating samples * Updating tests and samples * reverting change to test environment * updating changelog and reverting target api for client * updating changelog * updating assets.json * updating autorest to point input file to main repo * addressing PR feedback, updating tests * updating csproj version * reverting formatting changes in samples * updating indentation in correct place and regenerating samples * Removing older preview versions from targetable client options
1 parent 3fe6168 commit b2cdc90

22 files changed

+332
-26
lines changed

sdk/communication/Azure.Communication.Email/CHANGELOG.md

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

3-
## 1.1.0-beta.2 (Unreleased)
3+
## 1.1.0-beta.2 (2024-08-14)
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.1.0-beta.1 (2024-07-10)
1411

sdk/communication/Azure.Communication.Email/README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,50 @@ catch ( RequestFailedException ex )
242242
}
243243
```
244244

245+
### Send email with inline attachments
246+
Azure Communication Services support sending inline attachments.
247+
Adding an optional `contentId` parameter to the `EmailAttachment` constructor will make the attachment an inline attachment.
248+
```C# Snippet:Azure_Communication_Email_Send_With_Inline_Attachments
249+
// Create the email content and reference any inline attachments.
250+
var emailContent = new EmailContent("This is the subject")
251+
{
252+
PlainText = "This is the body",
253+
Html = "<html><body>This is the html body<img src=\"cid:myInlineAttachmentContentId\"></body></html>"
254+
};
255+
256+
// Create the EmailMessage
257+
var emailMessage = new EmailMessage(
258+
senderAddress: "<Send email address>" // The email address of the domain registered with the Communication Services resource
259+
recipientAddress: "<recipient email address>"
260+
content: emailContent);
261+
262+
var filePath = "<path to your file>";
263+
var attachmentName = "<name of your attachment>";
264+
var contentType = MediaTypeNames.Text.Plain;
265+
var contentId = "myInlineAttachmentContentId";
266+
267+
var content = new BinaryData(System.IO.File.ReadAllBytes(filePath));
268+
var emailAttachment = new EmailAttachment(attachmentName, contentType, content);
269+
emailAttachment.ContentId = contentId;
270+
271+
emailMessage.Attachments.Add(emailAttachment);
272+
273+
try
274+
{
275+
EmailSendOperation emailSendOperation = emailClient.Send(WaitUntil.Completed, emailMessage);
276+
Console.WriteLine($"Email Sent. Status = {emailSendOperation.Value.Status}");
277+
278+
/// Get the OperationId so that it can be used for tracking the message for troubleshooting
279+
string operationId = emailSendOperation.Id;
280+
Console.WriteLine($"Email operation id = {operationId}");
281+
}
282+
catch ( RequestFailedException ex )
283+
{
284+
/// OperationID is contained in the exception message and can be used for troubleshooting purposes
285+
Console.WriteLine($"Email send operation failed with error code: {ex.ErrorCode}, message: {ex.Message}");
286+
}
287+
```
288+
245289
## Troubleshooting
246290
A `RequestFailedException` is thrown as a service response for any unsuccessful requests. The exception contains information about what response code was returned from the service.
247291

sdk/communication/Azure.Communication.Email/api/Azure.Communication.Email.netstandard2.0.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public partial class EmailAttachment
1414
{
1515
public EmailAttachment(string name, string contentType, System.BinaryData content) { }
1616
public System.BinaryData Content { get { throw null; } }
17+
public string ContentId { get { throw null; } set { } }
1718
public string ContentType { get { throw null; } }
1819
public string Name { get { throw null; } }
1920
}
@@ -35,12 +36,13 @@ public EmailClient(System.Uri endpoint, Azure.Core.TokenCredential credential, A
3536
}
3637
public partial class EmailClientOptions : Azure.Core.ClientOptions
3738
{
38-
public EmailClientOptions(Azure.Communication.Email.EmailClientOptions.ServiceVersion version = Azure.Communication.Email.EmailClientOptions.ServiceVersion.V2023_03_31) { }
39+
public EmailClientOptions(Azure.Communication.Email.EmailClientOptions.ServiceVersion version = Azure.Communication.Email.EmailClientOptions.ServiceVersion.V2024_07_01_Preview) { }
3940
public enum ServiceVersion
4041
{
4142
V2021_10_01_Preview = 1,
4243
V2023_01_15_Preview = 2,
4344
V2023_03_31 = 3,
45+
V2024_07_01_Preview = 4,
4446
}
4547
}
4648
public partial class EmailContent

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": "net",
44
"TagPrefix": "net/communication/Azure.Communication.Email",
5-
"Tag": "net/communication/Azure.Communication.Email_7a9919913d"
5+
"Tag": "net/communication/Azure.Communication.Email_00a51dd0e7"
66
}

sdk/communication/Azure.Communication.Email/samples/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ This client library allows to do following operations:
1919
- Send a simple email message with manual polling for status
2020
- Specify optional paramters while sending Emails
2121
- Send an email message to multiple recipients
22-
- Send an email message with attachments
22+
- Send an email message with attachments and inline attachments
2323

2424
#### You can find samples for each of these functions below.
2525
- Send simple email message with automatic polling for status [synchronously][sample_simpleemail_autopolling] or [asynchronously][sample_simpleemail_autopolling_async]
2626
- Send simple email message with manual polling for status [asynchronously][sample_simpleemail_manualpolling_async]
2727
- Specify optional paramters while sending Emails [synchronously][sample_emailwithoptions] or [asynchronously][sample_emailwithoptions_async]
2828
- Send an email message to multiple recipients [synchronously][sample_email_multiplerecipients] or [asynchronously][sample_email_multiplerecipients_async]
29-
- Send an email message with attachments [synchronously][sample_email_attachments] or [asynchronously][sample_email_attachments_async]
29+
- Send an email message with attachments and inline attachments [synchronously][sample_email_attachments] or [asynchronously][sample_email_attachments_async]
3030

3131
<!-- LINKS -->
3232
[sample_simpleemail_autopolling]: https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/communication/Azure.Communication.Email/samples/Sample1_SendSimpleEmailWithAutomaticPollingForStatus.md

sdk/communication/Azure.Communication.Email/samples/Sample1_SendSimpleEmailWithAutomaticPollingForStatus.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,4 @@ catch ( RequestFailedException ex )
3737
}
3838
```
3939

40-
[README]: https://learn.microsoft.com/azure/communication-services/quickstarts/email/send-email?tabs=windows&pivots=platform-azcli#prerequisites
40+
[README]: https://learn.microsoft.com/azure/communication-services/quickstarts/email/send-email?tabs=windows&pivots=platform-azcli#prerequisites

sdk/communication/Azure.Communication.Email/samples/Sample3_SendEmailWithMoreOptions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,4 @@ catch ( RequestFailedException ex )
4747
}
4848
```
4949

50-
[README]: https://learn.microsoft.com/azure/communication-services/quickstarts/email/send-email?tabs=windows&pivots=platform-azcli#prerequisites
50+
[README]: https://learn.microsoft.com/azure/communication-services/quickstarts/email/send-email?tabs=windows&pivots=platform-azcli#prerequisites

sdk/communication/Azure.Communication.Email/samples/Sample4_SendEmailToMultipleRecipients.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,4 @@ catch ( RequestFailedException ex )
8181
}
8282
```
8383

84-
[README]: https://learn.microsoft.com/azure/communication-services/quickstarts/email/send-email?tabs=windows&pivots=platform-azcli#prerequisites
84+
[README]: https://learn.microsoft.com/azure/communication-services/quickstarts/email/send-email?tabs=windows&pivots=platform-azcli#prerequisites

sdk/communication/Azure.Communication.Email/samples/Sample5_SendEmailWithAttachment.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,4 @@ catch ( RequestFailedException ex )
4747
}
4848
```
4949

50-
[README]: https://learn.microsoft.com/azure/communication-services/quickstarts/email/send-email?tabs=windows&pivots=platform-azcli#prerequisites
50+
[README]: https://learn.microsoft.com/azure/communication-services/quickstarts/email/send-email?tabs=windows&pivots=platform-azcli#prerequisites

sdk/communication/Azure.Communication.Email/samples/Sample5_SendEmailWithAttachmentAsync.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,4 @@ catch ( RequestFailedException ex )
4747
}
4848
```
4949

50-
[README]: https://learn.microsoft.com/azure/communication-services/quickstarts/email/send-email?tabs=windows&pivots=platform-azcli#prerequisites
50+
[README]: https://learn.microsoft.com/azure/communication-services/quickstarts/email/send-email?tabs=windows&pivots=platform-azcli#prerequisites

0 commit comments

Comments
 (0)