简体   繁体   中英

Microsoft.Exchange.WebServices.Data.ServiceResponseException: Connection did not succeed. Try again later

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(IEnumerable 1 items, FolderId parentFolderId, Nullable 1 messageDisposition, Nullable 1 sendInvitationsMode, ServiceErrorHandling errorHandling) at Microsoft.Exchange.WebServices.Data.Item.InternalCreate(FolderId parentFolderId, Nullable 1 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

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());

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM