Skip to content

Commit 5b74733

Browse files
yogeshmoYogesh Mohanrajvcolin7
authored
Adding Azure Communications Service SDK for Email (Azure#30064)
* Adding Email SDK * Updating project dependencies * Adding tag * Fixed issues with README. * Fixed ci.yml * Fixed an issue with Java9+ builds. Re-ordered the POM a bit. Added "EnableBatchRelease: true" to ci.yml * Changed the dependency on azure-communication-common to use the source version, as this library needs an "exports" statement recently added to get compiled. * Updating models to have a constructor for required properties * Replacing list with iterable Co-authored-by: Yogesh Mohanraj <ymohanraj@microsoft.com> Co-authored-by: vcolin7 <vicolina@microsoft.com>
1 parent 2ae715f commit 5b74733

File tree

50 files changed

+3530
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+3530
-0
lines changed

eng/versioning/version_client.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ com.azure:azure-template-perf;1.0.0-beta.1;1.0.0-beta.1
155155
com.azure:azure-media-videoanalyzer-edge;1.0.0-beta.6;1.0.0-beta.7
156156
com.azure:azure-verticals-agrifood-farming;1.0.0-beta.2;1.0.0-beta.3
157157
com.azure:perf-test-core;1.0.0-beta.1;1.0.0-beta.1
158+
com.azure:azure-communication-email;1.0.0-beta.1;1.0.0-beta.1
158159
com.microsoft.azure:spring-cloud-azure-appconfiguration-config-web;1.3.0;1.4.0-beta.1
159160
com.microsoft.azure:spring-cloud-azure-appconfiguration-config;1.3.0;1.4.0-beta.1
160161
com.microsoft.azure:spring-cloud-azure-feature-management-web;1.3.0;1.4.0-beta.1

sdk/communication/azure-communication-common/src/main/java/module-info.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
to com.fasterxml.jackson.databind;
1313

1414
exports com.azure.communication.common.implementation to
15+
com.azure.communication.email,
1516
com.azure.communication.sms,
1617
com.azure.communication.identity,
1718
com.azure.communication.phonenumbers,
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Release History
2+
3+
## 1.0.0-beta.1 (Unreleased)
4+
5+
The initial release of the Azure Communication Services SDK for Email has the following features:
6+
7+
- send emails to multiple recipients with attachments
8+
- get the status of a sent message
9+
Lines changed: 225 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,225 @@
1+
# Azure Communication Email client library for Java
2+
3+
This package contains the Java SDK for Azure Communication Services for Email.
4+
5+
## Getting started
6+
7+
### Prerequisites
8+
9+
- [Azure subscription][azure_sub]
10+
- [Communication Service Resource][communication_resource_docs]
11+
- [Email Communication Resource][email_resource_docs] with an active [Domain][domain_overview]
12+
- [Java Development Kit (JDK)](https://docs.microsoft.com/java/azure/jdk/?view=azure-java-stable) version 8 or above
13+
- [Apache Maven](https://maven.apache.org/download.cgi)
14+
15+
To create these resource, 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].
16+
17+
### Include the package
18+
#### Include the BOM file
19+
20+
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.
21+
To learn more about the BOM, see the [AZURE SDK BOM README](https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/boms/azure-sdk-bom/README.md).
22+
23+
```xml
24+
<dependencyManagement>
25+
<dependencies>
26+
<dependency>
27+
<groupId>com.azure</groupId>
28+
<artifactId>azure-sdk-bom</artifactId>
29+
<version>{bom_version_to_target}</version>
30+
<type>pom</type>
31+
<scope>import</scope>
32+
</dependency>
33+
</dependencies>
34+
</dependencyManagement>
35+
```
36+
37+
and then include the direct dependency in the dependencies section without the version tag.
38+
39+
```xml
40+
<dependencies>
41+
<dependency>
42+
<groupId>com.azure</groupId>
43+
<artifactId>azure-communication-email</artifactId>
44+
</dependency>
45+
</dependencies>
46+
```
47+
48+
#### Include direct dependency
49+
If you want to take dependency on a particular version of the library that is not present in the BOM,
50+
add the direct dependency to your project as follows.
51+
52+
[//]: # ({x-version-update-start;com.azure:azure-communication-email;current})
53+
```xml
54+
<dependency>
55+
<groupId>com.azure</groupId>
56+
<artifactId>azure-communication-email</artifactId>
57+
<version>1.0.0-beta.1</version>
58+
</dependency>
59+
```
60+
## Key concepts
61+
> More details coming soon.
62+
63+
## Examples
64+
65+
`EmailClient` provides the functionality to send email messages .
66+
67+
### Client Creation and Authentication
68+
69+
Email clients can be created and authenticated using the connection string acquired from an Azure Communication Resource in the [Azure Portal][azure_portal].
70+
71+
```java readme-sample-createEmailClientWithConnectionString
72+
String connectionString = "https://<resource-name>.communication.azure.com/;<access-key>";
73+
74+
EmailClient emailClient = new EmailClientBuilder()
75+
.connectionString(connectionString)
76+
.buildClient();
77+
```
78+
79+
Email clients can also be created and authenticated using the endpoint and Azure Key Credential acquired from an Azure Communication Resource in the [Azure Portal][azure_portal].
80+
81+
```java readme-sample-createEmailClientUsingAzureKeyCredential
82+
String endpoint = "https://<resource-name>.communication.azure.com";
83+
AzureKeyCredential azureKeyCredential = new AzureKeyCredential("<access-key>");
84+
85+
EmailClient emailClient = new EmailClientBuilder()
86+
.endpoint(endpoint)
87+
.credential(azureKeyCredential)
88+
.buildClient();
89+
```
90+
91+
92+
### Send an Email Message
93+
94+
To send an email message, call the `send` function from the `EmailClient`.
95+
96+
```java readme-sample-sendEmailToSingleRecipient
97+
EmailAddress emailAddress = new EmailAddress("<recipient-email-address>");
98+
99+
ArrayList<EmailAddress> addressList = new ArrayList<>();
100+
addressList.add(emailAddress);
101+
102+
EmailRecipients emailRecipients = new EmailRecipients(addressList);
103+
104+
EmailContent content = new EmailContent("test subject")
105+
.setPlainText("test message");
106+
107+
EmailMessage emailMessage = new EmailMessage("<sender-email-address>", content)
108+
.setRecipients(emailRecipients);
109+
110+
SendEmailResult response = emailClient.send(emailMessage);
111+
System.out.println("Message Id: " + response.getMessageId());
112+
```
113+
114+
### Send an Email Message to Multiple Recipients
115+
116+
To send an email message to multiple recipients, add a object for each recipient type and an object for each recipient.
117+
118+
```java readme-sample-sendEmailToMultipleRecipients
119+
EmailAddress emailAddress = new EmailAddress("<recipient-email-address>");
120+
EmailAddress emailAddress2 = new EmailAddress("<recipient-2-email-address>");
121+
122+
ArrayList<EmailAddress> toAddressList = new ArrayList<>();
123+
toAddressList.add(emailAddress);
124+
toAddressList.add(emailAddress2);
125+
126+
ArrayList<EmailAddress> ccAddressList = new ArrayList<>();
127+
ccAddressList.add(emailAddress);
128+
129+
ArrayList<EmailAddress> bccAddressList = new ArrayList<>();
130+
bccAddressList.add(emailAddress);
131+
132+
EmailRecipients emailRecipients = new EmailRecipients(toAddressList)
133+
.setCc(ccAddressList)
134+
.setBcc(bccAddressList);
135+
136+
EmailContent content = new EmailContent("test subject")
137+
.setPlainText("test message");
138+
139+
EmailMessage emailMessage = new EmailMessage("<sender-email-address>", content)
140+
.setRecipients(emailRecipients);
141+
142+
SendEmailResult response = emailClient.send(emailMessage);
143+
System.out.println("Message Id: " + response.getMessageId());
144+
```
145+
146+
### Send Email with Attachments
147+
148+
Azure Communication Services support sending email with attachments.
149+
150+
```java readme-sample-sendEmailWithAttachment
151+
File file = new File("C:/attachment.txt");
152+
153+
byte[] fileContent = null;
154+
try {
155+
fileContent = Files.readAllBytes(file.toPath());
156+
} catch (Exception e) {
157+
System.out.println(e);
158+
}
159+
160+
String b64file = Base64.getEncoder().encodeToString(fileContent);
161+
162+
EmailAddress emailAddress = new EmailAddress("<recipient-email-address>");
163+
164+
ArrayList<EmailAddress> addressList = new ArrayList<>();
165+
addressList.add(emailAddress);
166+
167+
EmailRecipients emailRecipients = new EmailRecipients(addressList);
168+
169+
EmailContent content = new EmailContent("test subject")
170+
.setPlainText("test message");
171+
172+
EmailAttachment attachment = new EmailAttachment("attachment.txt", EmailAttachmentType.TXT, b64file);
173+
174+
ArrayList<EmailAttachment> attachmentList = new ArrayList<>();
175+
attachmentList.add(attachment);
176+
177+
EmailMessage emailMessage = new EmailMessage("<sender-email-address>", content)
178+
.setRecipients(emailRecipients)
179+
.setAttachments(attachmentList);
180+
181+
SendEmailResult response = emailClient.send(emailMessage);
182+
System.out.println("Message Id: " + response.getMessageId());
183+
```
184+
185+
### Get Email Message Status
186+
187+
The result from the `send` call contains a `messageId` which can be used to query the status of the email.
188+
189+
```java readme-sample-getMessageStatus
190+
SendStatusResult response = emailClient.getSendStatus("<sent-message-id>");
191+
System.out.println("Status: " + response.getStatus());
192+
```
193+
194+
## Troubleshooting
195+
> More details coming soon,
196+
197+
## Next steps
198+
199+
- [Read more about Email in Azure Communication Services][nextsteps]
200+
201+
## Contributing
202+
203+
This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit [cla.microsoft.com][cla].
204+
205+
This project has adopted the [Microsoft Open Source Code of Conduct][coc]. For more information see the [Code of Conduct FAQ][coc_faq] or contact [opencode@microsoft.com][coc_contact] with any additional questions or comments.
206+
207+
<!-- LINKS -->
208+
209+
[azure_sub]: https://azure.microsoft.com/free/dotnet/
210+
[azure_portal]: https://portal.azure.com
211+
[cla]: https://cla.microsoft.com
212+
[coc]: https://opensource.microsoft.com/codeofconduct/
213+
[coc_faq]: https://opensource.microsoft.com/codeofconduct/faq/
214+
[coc_contact]: mailto:opencode@microsoft.com
215+
[communication_resource_docs]: https://docs.microsoft.com/azure/communication-services/quickstarts/create-communication-resource?tabs=windows&pivots=platform-azp
216+
[email_resource_docs]: https://aka.ms/acsemail/createemailresource
217+
[communication_resource_create_portal]: https://docs.microsoft.com/azure/communication-services/quickstarts/create-communication-resource?tabs=windows&pivots=platform-azp
218+
[communication_resource_create_power_shell]: https://docs.microsoft.com/powershell/module/az.communication/new-azcommunicationservice
219+
[communication_resource_create_net]: https://docs.microsoft.com/azure/communication-services/quickstarts/create-communication-resource?tabs=windows&pivots=platform-net
220+
[package]: https://www.nuget.org/packages/Azure.Communication.Common/
221+
[product_docs]: https://aka.ms/acsemail/overview
222+
[nextsteps]: https://aka.ms/acsemail/overview
223+
[nuget]: https://www.nuget.org/
224+
[source]: https://github.com/Azure/azure-sdk-for-net/tree/main/sdk/communication
225+
[domain_overview]: https://aka.ms/acsemail/domainsoverview
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# NOTE: Please refer to https://aka.ms/azsdk/engsys/ci-yaml before editing this file.
2+
3+
trigger:
4+
branches:
5+
include:
6+
- main
7+
- hotfix/*
8+
- release/*
9+
paths:
10+
include:
11+
- sdk/communication/azure-communication-email/
12+
exclude:
13+
- sdk/communication/azure-communication-email/pom.xml
14+
15+
pr:
16+
branches:
17+
include:
18+
- main
19+
- feature/*
20+
- hotfix/*
21+
- release/*
22+
paths:
23+
include:
24+
- sdk/communication/azure-communication-email/
25+
exclude:
26+
- sdk/communication/azure-communication-email/pom.xml
27+
28+
extends:
29+
template: ../../../eng/pipelines/templates/stages/archetype-sdk-client.yml
30+
parameters:
31+
ServiceDirectory: communication
32+
EnableBatchRelease: true
33+
Artifacts:
34+
- name: azure-communication-email
35+
groupId: com.azure
36+
safeName: azurecommunicationemail

0 commit comments

Comments
 (0)