这是我的方案:我必须阅读来自Exchange 2010 sp2帐户的电子邮件.我必须使用Exchange Web服务,POP3和IMAP被阻止.我必须在人们只能通过Intranet中的Web浏览器访问其帐户的环境中测试我的应用程序.我无法直接将此应用程序调试到此Intranet.我有这个代码片段来访问帐户:
private void Dowork()
{
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
string dominio = "domain";
string usuario = "user";
string password = "password";
service.Credentials = new NetworkCredential(usuario, password, dominio);
string url = usuario + "@" + dominio + ".com";
service.AutodiscoverUrl(url, RedirectionUrlValidationCallback);
//service.AutodiscoverUrl(url);
FindItemsResults<Item> findResults = service.FindItems(
WellKnownFolderName.Inbox,
new ItemView(10));
string content = string.Empty;
foreach (Item item in findResults.Items)
{
EmailMessage email = EmailMessage.Bind(service, item.Id);
email.Load();
content += item.Subject + "\n";
content += email.From.Address + "\n";
content += email.Body …Run Code Online (Sandbox Code Playgroud) 该EWS托管API具有的功能,用于检索和管理屈指可数的电子邮件对话(又名 电子邮件线程).不幸的是,其中很大一部分只适用于新版本的Exchange(2013等)
Outlook确实实现了针对旧版 Exchange的电子邮件线程.也许它通过自己管理线程来实现这一点(Outlook是桌面应用程序,电子邮件在本地计算机上复制,因此可以通过Conversation Topic等轻松分组).
现在,如何在Web应用程序中支持电子邮件线程?通常在Exchange客户端中支持此功能的操作是什么?通过支持我的意思是:
EWS Managed Api等问题:
我现在使用的(作为解决方法):
我正在编写一个监视特定交换邮箱的简单控制台应用程序,当收到符合特定条件的电子邮件时,应用程序将下载XML文件附件并存档电子邮件.
我已经连接到EWS OK,并且已经能够遍历任何电子邮件,但是我在创建一个可以用来访问附件的EmailMessage对象时遇到了困难.
在下面的示例代码中,该EmailMessage message = EmailMessage.Bind(...)行执行时没有错误,但不返回有效消息,因此当我访问和属性或方法时,我收到一个错误:'对象引用未设置为对象的实例'.
我是C#的新手,更不用说EWS,所以我很难知道从哪里开始......
代码片段:
public static void FindItems()
{
try
{
ItemView view = new ItemView(10);
view.OrderBy.Add(ItemSchema.DateTimeReceived, SortDirection.Ascending);
view.PropertySet = new PropertySet(
BasePropertySet.IdOnly,
ItemSchema.Subject,
ItemSchema.DateTimeReceived);
findResults = service.FindItems(
WellKnownFolderName.Inbox,
new SearchFilter.SearchFilterCollection(
LogicalOperator.Or,
new SearchFilter.ContainsSubstring(ItemSchema.Subject, "Sales Enquiry")),
view);
log2.LogInfo("Total number of items found: " + findResults.TotalCount.ToString());
foreach (Item item in findResults)
{
log2.LogInfo(item.Id);
EmailMessage message = EmailMessage.Bind(service, item.Id, new PropertySet(BasePropertySet.IdOnly, ItemSchema.Attachments));
Console.WriteLine(message.Subject.ToString());
if (message.HasAttachments && message.Attachments[0] is FileAttachment)
{
FileAttachment fileAttachment = message.Attachments[0] as …Run Code Online (Sandbox Code Playgroud) 我正在编写一个Java应用程序来使用Exchange Web服务下载电子邮件.我正在使用Microsoft的ewsjava API来执行此操作.
我可以获取电子邮件标题.但是,我无法使用此API下载电子邮件附件.以下是代码段.
FolderId folderId = new FolderId(WellKnownFolderName.Inbox, "mailbox@example.com");
findResults = service.findItems(folderId, view);
for(Item item : findResults.getItems()) {
if (item.getHasAttachments()) {
AttachmentCollection attachmentsCol = item.getAttachments();
System.out.println(attachmentsCol.getCount()); // This is printing zero all the time. My message has one attachment.
for (int i = 0; i < attachmentsCol.getCount(); i++) {
FileAttachment attachment = (FileAttachment)attachmentsCol.getPropertyAtIndex(i);
String name = attachment.getFileName();
int size = attachment.getContent().length;
}
}
}
Run Code Online (Sandbox Code Playgroud)
item.getHasAttachments()是返回true,但是attachmentsCol.getCount()是0.
我正在使用EWS (Exchange Web Services)它Exchange 2010来在我们的组织内部生成和发送电子邮件.我们目前有一个邮箱/用户,我们所有的应用程序都通过它们发送app.
生成电子邮件没有问题,但是当发送测试邮件时,无论代码中设置了什么显示名称,它都会在收件人的邮箱中以默认帐户名进行交换.
示例代码:
EmailMessage message = new EmailMessage(ExchangeManager.CreateConnection());
// set from address as generic application account
message.From = new EmailAddress("app@company.com");
// set custom display name for sender email
message.From.Name = "Test Display Name";
// set send recipient as myself for testing
message.ToRecipients.Add(new EmailAddress("myaccount@company.com"));
ExchangeManager.SendExchangeMessage(message);
Run Code Online (Sandbox Code Playgroud)
收到消息,但它显示为app帐户的默认名称,而不是上面代码中使用的"测试显示名称".请参阅下面的Outlook收件箱截图:

这种方法在使用Exchange 2003 STMP服务时工作正常 - 我们可以根据需要格式化地址,例如"Intranet生成的邮件"或"其他一些应用程序"等.现在使用Exchange 2010和EWS它似乎没有允许我们使用此选项来使用自定义显示名称.
我还通过调试验证在发送消息之前已成功设置显示名称.
有没有人成功使用EWS/Exchange 2010的自定义显示名称?
我正在尝试创建一个ASP.NET(.NET 3.5)网站,通过Exchange Web服务连接到我们的Exchange 2010服务器,当我定义用户名,密码和域进行身份验证时,我能够连接到EWS,但我希望,如果可能,不在我的代码中包含登录详细信息.
在IIS中,我已在站点的web.config中为站点启用了集成Windows身份验证<authentication mode="Windows"/>.
以下代码是我一直在使用的代码:
svc.UseDefaultCredentials = True
svc.Credentials = New WebCredentials()
svc.Url = New Uri(svcURL)
Run Code Online (Sandbox Code Playgroud)
使用上面的代码我收到的消息:
将请求作为没有邮箱的帐户发出时,必须为任何可识别的文件夹ID指定邮箱主SMTP地址.
当我尝试使用svc.Credentials = CredentialCache.DefaultNetworkCredentials(代替svc.Credentials = New WebCredentials())时,我收到错误消息:
无法将类型为"System.Net.SystemNetworkCredential"的对象强制转换为"Microsoft.Exchange.WebServices.Data.ExchangeCredentials".
如上所述,唯一有效的方法是通过硬编码用户登录详细信息来定义要通过身份验证的用户凭据,我宁愿不这样做: svc.Credentials = New WebCredentials("username","password","domain")
有没有人能够使用ASP.NET网站中当前登录用户的凭据对EWS进行身份验证?
TL;博士
设置CustomProperties为具有与会者的约会时,只有组织者的约会才能获得CustomProperties.属性不会传播到其他与会者的约会.
更长的版本
当我们与多个与会者创建约会然后以每个与会者身份登录时,我们注意到每个与会者ItemId都不同.因此,会议中的每个与会者似乎都会获得自己的约会副本.(真的希望有人确认这是真的).
但是,从我们的加载项设置自定义属性(使用Outlook JavaScript API)时,只有组织者的约会才能获得自定义属性,因为当我们以任何其他与会者身份登录时,我们无法看到自定义属性.
我们的代码中的代码片段是相关的:
Office.initialize = function (reason) {
$(document).ready(function () {
Office.context.mailbox.item.loadCustomPropertiesAsync (onCustomPropertiesLoaded);
});
};
function onCustomPropertiesLoaded(asyncResults) {
_customProps = asyncResults.value;
}
//Set custom properties
_customProps.set("myProp", "true");
_customProps.saveAsync(customPropertiesOnSaved);
Run Code Online (Sandbox Code Playgroud)
有没有办法让每个约会副本都有自定义属性?
ms-office office-addins exchangewebservices outlook-addin office-js
我在python中使用exchangelib时遇到问题.我试试这个示例代码:
from exchangelib import DELEGATE, Account, Credentials
creds = Credentials(
username='xxxx\\username',
password="mypassword"
)
account = Account(
primary_smtp_address='surname.name@xxxx.fr',
credentials=creds,
autodiscover=True,
access_type=DELEGATE
)
# Print first 10 inbox messages in reverse order
for item in account.inbox.all().order_by('-datetime_received')[:10]:
print(item.subject, item.body, item.attachments)
Run Code Online (Sandbox Code Playgroud)
我尝试了不同的用户名但没有任何作用,我总是有相同的错误消息:
AutoDiscoverFailed: All steps in the autodiscover protocol failed
顺便说一句,以防万一它可以提供帮助,我试图使用为C#编码的Exchange Web服务,它可以完美地使用这些信用卡,我可以发送邮件:
static void Main(string[] args)
{
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
// The last parameter is the domain name
service.Credentials = new WebCredentials("username", "password", "xxxx.lan");
service.AutodiscoverUrl("surname.name@xxxx.fr", RedirectionUrlValidationCallback);
EmailMessage email = new EmailMessage(service);
email.ToRecipients.Add("surname.name@xxxx.fr"); …Run Code Online (Sandbox Code Playgroud) python exchange-server exchangewebservices office365 exchangelib
我在 Azure VM 上有一个 Exchange Online 环境和服务/daemin(无交互用户)应用程序。服务使用 EWS 托管 API 来处理任何租户用户邮箱中的电子邮件。现在 EWS 客户端使用基本身份验证,据 Microsoft 称,EWS 将不支持该身份验证来访问 Exchange Online。
因此,我需要找到一种方法来获取服务/守护程序应用程序的有效访问令牌以与 EWS 托管 API 一起使用。
以下文章展示了将 OAuth 2.0 与 EWS 托管 API 结合使用的示例。此示例有效,但它使用了不适合服务/守护程序应用程序场景的交互式方法来获得同意(出现登录表单,允许用户验证自己并授予应用程序请求的权限),因为没有交互式用户。
对于服务/守护程序应用程序,我需要使用client credential身份验证流程。
使用https://aad.portal.azure.com门户上的管理员帐户,我向 Azure Active Directory 注册了应用程序。为已注册的应用程序添加了客户端机密。
上述文章使用https://outlook.office.com/EWS.AccessAsUser.All的scope。但是我没有在门户网站上找到这样一个 URL 的许可。我发现只有在以下权限Office 365 Exchange Online> Application permissions> Mail:
https://outlook.office365.com/Mail.Read 允许应用在没有登录用户的情况下阅读所有邮箱中的邮件https://outlook.office365.com/Mail.ReadWrite 允许应用在没有登录用户的情况下创建、读取、更新和删除所有邮箱中的邮件。 我添加了它们并为所有用户授予管理员同意。
出于测试目的和简单起见,我没有使用任何身份验证库(ADAL、MSAL 等)。我使用 Postman 获取访问令牌,然后token …
希望是一个非常简单的。我将一个应用程序.net-core从.net使用EWS. 除了进行大量交互异步之外,所有似乎都可以正常工作而无需任何更改。除了从电子邮件下载附件。在调试和使用对象检查器时,FileAttachment对象存在并且对象属性/大小看起来正是我所期望的。的FileAttachment。Load(string outputPath) 创建一个文件,但是,该文件的内容大小为 0KB。所以外壳已经创建,但没有数据流入其中。可能我错过了一些明显的东西,但明显的东西正在逃避我。尝试使用流和输出路径方法,结果相同。该功能在.net框架版本中仍然可以正常工作。任何想法非常感谢?
foreach (EmailMessage email in orderedList)
{
EmailMessage message = await EmailMessage.Bind(_service, email.Id, new PropertySet(BasePropertySet.FirstClassProperties, EmailMessageSchema.Attachments));
if (email.HasAttachments)
{
foreach (Attachment attachment in message.Attachments)
{
bool getFile = false;
if (attachment is FileAttachment)
{
FileAttachment fileAttachment = attachment as FileAttachment;
if (!string.IsNullOrEmpty(filename) && fileAttachment.Name.StartsWith(filename))
{
getFile = true;
}
else if (string.IsNullOrEmpty(filename))
{
getFile = true;
}
if (getFile)
{
//var response …Run Code Online (Sandbox Code Playgroud) c# ×4
asp.net ×2
email ×2
office365 ×2
attachment ×1
ewsjavaapi ×1
exchangelib ×1
java ×1
ms-office ×1
oauth-2.0 ×1
office-js ×1
python ×1
web-services ×1