问题描述
我可以很好地连接到Exchange Server,并且可以收到所有未读邮件,但是新邮件不想发送
I'm connecting fine to the Exchange Server and I'm getting all the unread mails but a new message doesn't want to send
消息代码
var newHTML = html.HTMLCode.Replace("{House}", house.Number)
.Replace("{Token}", token.Number)
.Replace("{contactPerson}",
string.Format("<a href=mailto:{0}>{1}</a>",
contactPerson, contactPerson));
LogError.WriteToFile("Has House and token");
//Send mail with token to user
EmailMessage message = new EmailMessage(emailService);
message.ToRecipients.Add(email.From.Address);
message.Subject = string.Format("Electricity token for: {0}", house.Number);
message.Body = new MessageBody(html.HTMLCode);
LogError.WriteToFile("Trying to send");
message.Send();
我尝试解决此问题,因此在日志文件中显示正在尝试发送",但发生错误,显示为请求中必须包含EmailAddress或ItemId."
I have a try catch around this so in the log file I get "Trying to send" but then a error occurs that reads as"EmailAddress or ItemId must be included in the request."
从所看到的示例中,我构造消息的方式似乎足够,但显然不是
From examples seen, the way I construct my message seems sufficient but clearly isn't
推荐答案
这是我收到所有未读电子邮件的方式
This is how I got all my unread emails
SearchFilter sf = new SearchFilter.SearchFilterCollection(LogicalOperator.And, new SearchFilter.IsEqualTo(EmailMessageSchema.IsRead, false));
ItemView view = new ItemView(int.MaxValue);
FindItemsResults<Item> findResults = emailService.FindItems(WellKnownFolderName.Inbox, sf, view);
foreach (EmailMessage email in findResults)
{}
请注意,我将它们作为"EmailMessage"获得
Note that I got them as a "EmailMessage"
但是由于无法获得发件人的电子邮件地址,所以这就是它不想发送的原因.然后我找到了这篇文章: FindItem仅返回任何可流属性的前512个字节
But were never able to get the senders email address so that's why it didn't want to send.and then I found this article: FindItem returns only the first 512 bytes of any streamable property
因此,我去了接收这样的特定电子邮件.请注意,我现在从findResults获取项目",并使用该项目"执行以下操作.
So then I went to go get that specific email like this. Note that I now get the "Item" from the findResults and with that "Item" I do the following.
SearchFilter sf = new SearchFilter.SearchFilterCollection(LogicalOperator.And, new SearchFilter.IsEqualTo(EmailMessageSchema.IsRead, false));
ItemView view = new ItemView(int.MaxValue);
FindItemsResults<Item> findResults = emailService.FindItems(WellKnownFolderName.Inbox, sf, view);
foreach (Item item in findResults)
{
//Get the email message
EmailMessage email = EmailMessage.Bind(emailService, item.Id,
new PropertySet(BasePropertySet.FirstClassProperties, ItemSchema.Attachments));
if (email != null)
{}
}
现在我终于可以发送电子邮件了
Now I could finally send emails
这篇关于尝试发送邮件时出错.不使用EWS发送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!