-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update .NET SDK for inline attachments (#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
- Loading branch information
1 parent
3fe6168
commit b2cdc90
Showing
22 changed files
with
332 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
...tion/Azure.Communication.Email/samples/Sample6_SendEmailWithInlineAttachment.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# Send Email Message | ||
|
||
This sample demonstrates how to send an email message to an individual or a group of recipients. | ||
|
||
To get started you'll need a Communication Service Resource. See [README][README] for prerequisites and instructions. | ||
|
||
## Creating an `EmailClient` | ||
|
||
Email clients can be authenticated using the connection string acquired from an Azure Communication Resource in the Azure Portal. Alternatively, Email clients can also be authenticated using a valid token credential. | ||
|
||
```C# Snippet:Azure_Communication_Email_CreateEmailClient | ||
var connectionString = "<connection_string>"; // Find your Communication Services resource in the Azure portal | ||
EmailClient emailClient = new EmailClient(connectionString); | ||
``` | ||
|
||
### Send email with attachments | ||
Azure Communication Services support sending emails with attachments. Adding an optional `contentId` parameter to the `EmailAttachment` constructor will make the attachment an inline attachment. | ||
See [EmailAttachmentType][email_attachmentTypes] for a list of supported attachments. | ||
```C# Snippet:Azure_Communication_Email_Send_With_Inline_Attachments | ||
// Create the email content and reference any inline attachments. | ||
var emailContent = new EmailContent("This is the subject") | ||
{ | ||
PlainText = "This is the body", | ||
Html = "<html><body>This is the html body<img src=\"cid:myInlineAttachmentContentId\"></body></html>" | ||
}; | ||
|
||
// Create the EmailMessage | ||
var emailMessage = new EmailMessage( | ||
senderAddress: "<Send email address>" // The email address of the domain registered with the Communication Services resource | ||
recipientAddress: "<recipient email address>" | ||
content: emailContent); | ||
|
||
var filePath = "<path to your file>"; | ||
var attachmentName = "<name of your attachment>"; | ||
var contentType = MediaTypeNames.Text.Plain; | ||
var contentId = "myInlineAttachmentContentId"; | ||
|
||
var content = new BinaryData(System.IO.File.ReadAllBytes(filePath)); | ||
var emailAttachment = new EmailAttachment(attachmentName, contentType, content); | ||
emailAttachment.ContentId = contentId; | ||
|
||
emailMessage.Attachments.Add(emailAttachment); | ||
|
||
try | ||
{ | ||
EmailSendOperation emailSendOperation = emailClient.Send(WaitUntil.Completed, emailMessage); | ||
Console.WriteLine($"Email Sent. Status = {emailSendOperation.Value.Status}"); | ||
|
||
/// Get the OperationId so that it can be used for tracking the message for troubleshooting | ||
string operationId = emailSendOperation.Id; | ||
Console.WriteLine($"Email operation id = {operationId}"); | ||
} | ||
catch ( RequestFailedException ex ) | ||
{ | ||
/// OperationID is contained in the exception message and can be used for troubleshooting purposes | ||
Console.WriteLine($"Email send operation failed with error code: {ex.ErrorCode}, message: {ex.Message}"); | ||
} | ||
``` | ||
|
||
[README]: https://learn.microsoft.com/azure/communication-services/quickstarts/email/send-email?tabs=windows&pivots=platform-azcli#prerequisites |
60 changes: 60 additions & 0 deletions
60
...Azure.Communication.Email/samples/Sample6_SendEmailWithInlineAttachmentAsync.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# Send Email Message | ||
|
||
This sample demonstrates how to send an email message to an individual or a group of recipients. | ||
|
||
To get started you'll need a Communication Service Resource. See [README][README] for prerequisites and instructions. | ||
|
||
## Creating an `EmailClient` | ||
|
||
Email clients can be authenticated using the connection string acquired from an Azure Communication Resource in the Azure Portal. Alternatively, Email clients can also be authenticated using a valid token credential. | ||
|
||
```C# Snippet:Azure_Communication_Email_CreateEmailClient | ||
var connectionString = "<connection_string>"; // Find your Communication Services resource in the Azure portal | ||
EmailClient emailClient = new EmailClient(connectionString); | ||
``` | ||
|
||
### Send email with attachments | ||
Azure Communication Services support sending emails with attachments. Adding an optional `contentId` parameter to the `EmailAttachment` constructor will make the attachment an inline attachment. | ||
See [EmailAttachmentType][email_attachmentTypes] for a list of supported attachments. | ||
```C# Snippet:Azure_Communication_Email_Send_With_Inline_Attachments_Async | ||
// Create the email content and reference any inline attachments. | ||
var emailContent = new EmailContent("This is the subject") | ||
{ | ||
PlainText = "This is the body", | ||
Html = "<html><body>This is the html body<img src=\"cid:myInlineAttachmentContentId\"></body></html>" | ||
}; | ||
|
||
// Create the EmailMessage | ||
var emailMessage = new EmailMessage( | ||
senderAddress: "<Send email address>" // The email address of the domain registered with the Communication Services resource | ||
recipientAddress: "<recipient email address>" | ||
content: emailContent); | ||
|
||
var filePath = "<path to your file>"; | ||
var attachmentName = "<name of your attachment>"; | ||
var contentType = MediaTypeNames.Text.Plain; | ||
var contentId = "myInlineAttachmentContentId"; | ||
|
||
var content = new BinaryData(System.IO.File.ReadAllBytes(filePath)); | ||
var emailAttachment = new EmailAttachment(attachmentName, contentType, content); | ||
emailAttachment.ContentId = contentId; | ||
|
||
emailMessage.Attachments.Add(emailAttachment); | ||
|
||
try | ||
{ | ||
EmailSendOperation emailSendOperation = await emailClient.SendAsync(WaitUntil.Completed, emailMessage); | ||
Console.WriteLine($"Email Sent. Status = {emailSendOperation.Value.Status}"); | ||
|
||
/// Get the OperationId so that it can be used for tracking the message for troubleshooting | ||
string operationId = emailSendOperation.Id; | ||
Console.WriteLine($"Email operation id = {operationId}"); | ||
} | ||
catch ( RequestFailedException ex ) | ||
{ | ||
/// OperationID is contained in the exception message and can be used for troubleshooting purposes | ||
Console.WriteLine($"Email send operation failed with error code: {ex.ErrorCode}, message: {ex.Message}"); | ||
} | ||
``` | ||
|
||
[README]: https://learn.microsoft.com/azure/communication-services/quickstarts/email/send-email?tabs=windows&pivots=platform-azcli#prerequisites |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
sdk/communication/Azure.Communication.Email/src/Generated/EmailRestClient.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
5 changes: 5 additions & 0 deletions
5
...unication/Azure.Communication.Email/src/Generated/Models/EmailAttachment.Serialization.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
13 changes: 13 additions & 0 deletions
13
sdk/communication/Azure.Communication.Email/src/Generated/Models/EmailAttachment.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
4 changes: 2 additions & 2 deletions
4
sdk/communication/Azure.Communication.Email/src/Generated/Models/EmailMessage.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.