问题描述
我有一封相当简单的电子邮件,需要使用Exchange服务器发送.这在本地有效,但是在发布到服务器时失败.这是我的代码,它建立了到交换服务器的链接:
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服务=新的ExchangeService(ExchangeVersion.Exchange2010_SP2);service.UseDefaultCredentials = true;service.AutodiscoverUrl(Config.GetGroupMailbox(),RedirectionUrlValidationCallback);
var service = new ExchangeService(ExchangeVersion.Exchange2010_SP2);service.UseDefaultCredentials = true;service.AutodiscoverUrl(Config.GetGroupMailbox(),RedirectionUrlValidationCallback);
设置完字段后,我只是简单地调用.Send().
After setting the fields I am simply calling .Send() with no success.
这是堆栈跟踪:
Microsoft.Exchange.WebServices.Data.ServiceResponseException:没有邮箱的用户无法使用SendOnly.使用SendAndSaveCopy并在邮箱中指定文件夹ID,以从没有邮箱的帐户发送项目. 在Microsoft.Exchange.WebServices.Data.ServiceResponse.InternalThrowIfNecessary() 在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) 在Microsoft.Exchange.WebServices.Data.EmailMessage.InternalSend(FolderId parentFolderId,MessageDisposition messageDisposition) 在CCSSWorkflow.Models.EmailService.Send(EmailObject EmailObject,EmailSent EmailSentObject)
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, Nullable
1 messageDisposition, Nullable1 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)
感谢帮助/指导,
山姆
推荐答案
我找到了问题并解决了.问题出在与正在连接或尝试连接的用户有关.
I found the issue and resolved. The issue was with the user that was connecting, or attempting to connect.
我已将服务设置为使用默认设置:service.UseDefaultCredentials = true;意味着它将在用户运行进程时尝试连接.
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());
这篇关于Microsoft.Exchange.WebServices.Data.ServiceResponseException:连接失败.稍后再试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!