HugoHiasl
HugoHiasl

Reputation: 324

recipient is not resolved issue in EWS

I am sending emails via exchange web services (EWS C#), modern authentication and Exchange Online.

This works fine for all email addresses tested except one. This one email address is the main SMTP address of a user in our organization.

When I try to send the email it results in an error "Microsoft.Exchange.WebServices.Data.ServiceResponseException: At least one recipient is not valid., Recipient '[email protected] ' is not resolved. All recipients must be resolved before a message can be submitted."

The mail then resides in the draft folder of the sending mailbox.

If I view it there with Outlook then it shows 2-3 seconds the entered SMTP email address of the user and then it switches to this underlined resolved name view in Outlook.

Is there a way in EWS to trigger this resolve process manually? Or do I need a setting on the server?

Or am I missing something?

Thanks.

This is my code:

            log.Debug("create email object");
            EmailMessage message = new EmailMessage(service);
            // Set properties on the email message.
            message.Subject = subject;
            message.Body = body;
            message.From = from;

            foreach (string emailReplyTo in replyTo)
            {
                message.ReplyTo.Add(emailReplyTo);
            }

            foreach (string emailTo in recipients)
            {
                message.ToRecipients.Add(emailTo);
            }

            if (cc != null)
            {
                foreach (string emailTo in cc)
                {
                    message.CcRecipients.Add(emailTo);
                }
            }

            if (bcc != null)
            {
                foreach (string emailTo in bcc)
                {
                    message.BccRecipients.Add(emailTo);
                }
            }

            

            if (attachmentData != null && !String.IsNullOrWhiteSpace(attachmentFileName))
            {
                log.Debug("Add attachment");
                message.Attachments.AddFileAttachment(attachmentFileName, attachmentData);
            }

            log.Debug("Send and save copy of email");
            message.SendAndSaveCopy();

            log.Debug("Successfully sent email");
            return true;

Upvotes: 0

Views: 2519

Answers (1)

HugoHiasl
HugoHiasl

Reputation: 324

Funny thing. The issue was that the email address had a trailing blank.

The Exchange server is still able to resolve when viewing it in Outlook (it just takes some seconds) but in the code it creates the issue.

Upvotes: 2

Related Questions