如何使用Microsoft.Exchange.WebServices?
我尝试使用:Microsoft.Exchange.WebServices.dll 来使用 Outlook。但连接返回错误
错误返回行:service.AutodiscoverUrl("[电子邮件受保护] ");
无法找到自动发现服务。我的代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Mail;
using System.Net;
using Microsoft.Exchange.WebServices.Data;
using Microsoft.Exchange.WebServices.Autodiscover;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
namespace test
{
class Program
{
static void Main(string[] args)
{
try
{
// Connect to Exchange Web Services as user1 at contoso.com.
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
service.Credentials = new WebCredentials("[email protected]", "mypassword", "xxxx.com");
service.TraceEnabled = true;
service.AutodiscoverUrl("[email protected]");
// Create the e-mail message, set its properties, and send it to [email protected], saving a copy to the Sent Items folder.
EmailMessage message = new EmailMessage(service);
message.Subject = "Interesting";
message.Body = "The proposition has been considered.";
message.ToRecipients.Add("[email protected]");
message.SendAndSaveCopy();
// Write confirmation message to console window.
Console.WriteLine("Message sent!");
Console.ReadLine();
}
catch (Exception ex)
{
Console.WriteLine("Error: " + ex.Message);
Console.ReadLine();
}
}
}
}
i try to use : Microsoft.Exchange.WebServices.dll to use outlook. but connection return error
Error return line:service.AutodiscoverUrl("[email protected]");
The Autodiscover service could not be located. my codes:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Mail;
using System.Net;
using Microsoft.Exchange.WebServices.Data;
using Microsoft.Exchange.WebServices.Autodiscover;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
namespace test
{
class Program
{
static void Main(string[] args)
{
try
{
// Connect to Exchange Web Services as user1 at contoso.com.
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
service.Credentials = new WebCredentials("[email protected]", "mypassword", "xxxx.com");
service.TraceEnabled = true;
service.AutodiscoverUrl("[email protected]");
// Create the e-mail message, set its properties, and send it to [email protected], saving a copy to the Sent Items folder.
EmailMessage message = new EmailMessage(service);
message.Subject = "Interesting";
message.Body = "The proposition has been considered.";
message.ToRecipients.Add("[email protected]");
message.SendAndSaveCopy();
// Write confirmation message to console window.
Console.WriteLine("Message sent!");
Console.ReadLine();
}
catch (Exception ex)
{
Console.WriteLine("Error: " + ex.Message);
Console.ReadLine();
}
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我知道这是一个老问题,但最近一直在努力解决这个问题以及类似的错误(包括 ISA 服务器)。已修复:
使用显式 URL 时不需要,但使用自动发现时需要
I know this is an old question, but recently wrestled with this and similar looking error (including ISA server). It was fixed with:
This was not required when working with an explicit URL, but was when using AutoDiscover
这是一个常见问题,当交易所的自动发现服务关闭时,会遇到自动发现服务错误
解决方案是提供交换位置的实际 URL,而不是自动发现它。
这解决了我同样的问题。
This is a common problem , Autodiscover service error is encountered when this autodiscover service by exchange is down
Resolution is to provide actual URL for exchange location , rather than autodiscovering it.
This solved my same issue.
这是一篇旧文章,但也许有人会需要它。
不要使用自动发现,它非常慢。
如何查找您的 Exchange 网址:
哦,要使用您添加的额外代码行的网址:
this is an old post but maybe someone will need it.
do not use auto discover, it is rly slow.
how to find your exchange url:
oh and to use the url you trop that extra line of code:
该代码表明您有一个 Exchange 2007 服务器...它是否已正确配置以使用自动发现功能?确认您可以 ping autodiscover.XXXX.com 并在网络浏览器中查看 https://autodiscover.XXXX.com 。
或者,您可能需要使用内部域名进行自动发现和登录。例如,在我的办公室,外部电子邮件地址位于
CompanyX.com
之类的域中,但内部 Active Directory 域类似于CompanyX.local
,而我们没有自动发现在开放的 Internet 上,因此我的 EWS 需要找到Autodiscover.CompanyX.local
。The code suggest that you have an Exchange 2007 server... Is it properly configured for using the Autodiscover features? Confirm that you can ping autodiscover.XXXX.com and view https://autodiscover.XXXX.com in a web browser.
Alternately, you may need to use your internal domain name for autodiscovery and login. For example, in my office the external email addresses are on a domain like
CompanyX.com
, but the internal Active Directory domain is likeCompanyX.local
, and we do not have autodiscover on the open Internet, so my EWS needs to locateAutodiscover.CompanyX.local
.尝试这些概念:
try these concept: