You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There are a few different options available for authenticating an email client:
106
+
There are a few different options available for authenticating an email client.
108
107
109
108
#### [Connection String](#tab/connection-string)
110
109
111
110
To authenticate a client, you instantiate an `EmailClient` with your connection string. Learn how to [manage your resource's connection string](../../create-communication-resource.md#store-your-connection-string). You can also initialize the client with any custom HTTP client that implements the `com.azure.core.http.HttpClient` interface.
112
111
113
-
To instantiate a client, add the following code to the `main` method:
112
+
To instantiate a synchronous client, add the following code to the `main` method:
114
113
115
114
```java
116
115
// You can get your connection string from your resource in the Azure portal.
@@ -121,6 +120,17 @@ EmailClient emailClient = new EmailClientBuilder()
121
120
.buildClient();
122
121
```
123
122
123
+
To instantiate an asynchronous client, add the following code to the `main` method:
124
+
125
+
```java
126
+
// You can get your connection string from your resource in the Azure portal.
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](https://portal.azure.com/).
144
167
168
+
To instantiate a synchronous client, add the following code to the `main` method:
@@ -159,24 +195,37 @@ For simplicity, this quickstart uses connection strings, but in production envir
159
195
160
196
## Basic email sending
161
197
162
-
To send an email message, call the `beginSend` function from the `EmailClient`. This method returns a poller, which can be used to check on the status of the operation and retrieve the result once it's finished. Note that the initial request to send an email will not be sent until either the `poll` method is called or we wait for completion of the poller.
198
+
An email messagecan be crafted using the `EmailMessage` object in the SDK.
.setSubject("Welcome to Azure Communication Services Email")
169
205
.setBodyPlainText("This email message is sent from Azure Communication Services Email using the Java SDK.");
206
+
```
207
+
208
+
Make these replacements in the code:
209
+
- Replace `<[email protected]>` with the email address you would like to send a message to.
210
+
- Replace `<[email protected]>` with the MailFrom address of your verified domain.
211
+
212
+
To send the email message, call the `beginSend` function from the `EmailClient`.
213
+
214
+
## [Sync Client](#tab/sync-client)
170
215
216
+
Calling `beginSend` on the sync client returns a `SyncPoller` object, which can be used to check on the status of the operation and retrieve the result once it's finished. Note that the initial request to send an email will be sent as soon as the `beginSend` method is called. Sending an email is a long running operation, so calling `getFinalResult` on the poller returned by `beginSend` could potentially block the application for a long time. The recommended method is to do manual polling at an interval that's appropriate for your application needs as demonstrated in the sample below.
- Replace `<[email protected]>` with the email address you would like to send a message to.
214
-
- Replace `<[email protected]>` with the MailFrom address of your verified domain.
262
+
Calling `beginSend` on the async client returns a `PollerFlux` object to which you can subscribe. You will want to set up the subscriber in a seperate process to take advantage of the asynchronous functionality. Note that the initial request to send an email will not be sent until a subscriber is set up.
263
+
264
+
```java
265
+
// The initial request is sent out as soon as we subscribe the to PollerFlux object
266
+
emailClient.beginSend(emailMessage).subscribe(
267
+
response -> {
268
+
if (response.getStatus() ==LongRunningOperationStatus.SUCCESSFULLY_COMPLETED) {
269
+
System.out.printf("Successfully sent the email (operation id: %s)", response.getValue().getId());
0 commit comments