Microsoft.Exchange.WebServices.Data.ServiceRespons

2019-07-16 13:20发布

问题:

I have a fairly simple email that I need to send using Exchange server. This works locally, but fails when I publish to the server. Here is my code establishing the link to the exchange server:

var service = new ExchangeService(ExchangeVersion.Exchange2010_SP2); service.UseDefaultCredentials = true; service.AutodiscoverUrl(Config.GetGroupMailbox(),RedirectionUrlValidationCallback);

After setting the fields I am simply calling .Send() with no success.

Here is the stack trace:

Microsoft.Exchange.WebServices.Data.ServiceResponseException: SendOnly cannot be used by a user without a mailbox. Use SendAndSaveCopy and specify a folder ID in a mailbox to send an item from an account that doesn't have a mailbox. at Microsoft.Exchange.WebServices.Data.ServiceResponse.InternalThrowIfNecessary() at Microsoft.Exchange.WebServices.Data.ExchangeService.InternalCreateItems(IEnumerable1 items, FolderId parentFolderId, Nullable1 messageDisposition, Nullable1 sendInvitationsMode, ServiceErrorHandling errorHandling) at Microsoft.Exchange.WebServices.Data.Item.InternalCreate(FolderId parentFolderId, Nullable1 messageDisposition, Nullable`1 sendInvitationsMode) at Microsoft.Exchange.WebServices.Data.EmailMessage.InternalSend(FolderId parentFolderId, MessageDisposition messageDisposition) at CCSSWorkflow.Models.EmailService.Send(EmailObject EmailObject, EmailSent EmailSentObject)

Thanks for the help/direction,

Sam

回答1:

I found the issue and resolved. The issue was with the user that was connecting, or attempting to connect.

I had set the service to use default setting: service.UseDefaultCredentials = true; meaning that it would try to connect as the user running the process.

When I replaced that with actual user id and password everything worked:

service.UseDefaultCredentials = false;
service.Credentials = new WebCredentials(Config.GetEmailConnectionUserID(),
                                         Config.GetEmailConnectionPassword());