コード例 #1
0
        public void GetSendEmailStatus()
        {
            EmailClient client = CreateEmailClient();

            // Create the email content
            var emailContent = new EmailContent("This is the subject");

            emailContent.PlainText = "This is the body";

            // Create the recipient list
            var emailRecipients = new EmailRecipients(
                new List <EmailAddress>
            {
                new EmailAddress(
                    //@@ email: "<recipient email address>"
                    //@@ displayName: "<recipient displayname>"
                    /*@@*/ email: TestEnvironment.ToEmailAddress,
                    /*@@*/ displayName: "Customer Name")
            });

            // Create the EmailMessage
            var emailMessage = new EmailMessage(
                //@@ sender: "<Send email address>" // The email address of the domain registered with the Communication Services resource
                /*@@*/ sender: TestEnvironment.AzureManagedFromEmailAddress,
                emailContent,
                emailRecipients);

            #region Snippet:Azure_Communication_Email_GetSendStatus
            SendEmailResult sendResult = client.Send(emailMessage);

            SendStatusResult status = client.GetSendStatus(sendResult.MessageId);
            #endregion Snippet:Azure_Communication_Email_GetSendStatus

            Assert.False(string.IsNullOrEmpty(sendResult.MessageId));
        }
コード例 #2
0
        public async Task GetSendStatusAsync()
        {
            EmailClient emailClient = CreateEmailClient();

            SendEmailResult response = await SendEmailAsync(emailClient);

            Assert.IsNotNull(response);
            Assert.IsFalse(string.IsNullOrWhiteSpace(response.MessageId));
            Console.WriteLine($"MessageId={response.MessageId}");

            SendStatusResult messageStatusResponse = await emailClient.GetSendStatusAsync(response.MessageId);

            Assert.IsNotNull(messageStatusResponse);
            Console.WriteLine(messageStatusResponse.Status);
        }
コード例 #3
0
        public async Task <ResponseWithHeaders <SendStatusResult, EmailGetSendStatusHeaders> > GetSendStatusAsync(string messageId, CancellationToken cancellationToken = default)
        {
            if (messageId == null)
            {
                throw new ArgumentNullException(nameof(messageId));
            }

            using var message = CreateGetSendStatusRequest(messageId);
            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);

            var headers = new EmailGetSendStatusHeaders(message.Response);

            switch (message.Response.Status)
            {
            case 200:
            {
                SendStatusResult value = default;
                using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false);

                value = SendStatusResult.DeserializeSendStatusResult(document.RootElement);
                return(ResponseWithHeaders.FromValue(value, headers, message.Response));
            }