我试图检测我的应用程序发送的电子邮件是否发送失败。这意味着我不是要验证电子邮件,而实际上只是验证它是否到达了目标邮箱。
这是我正在使用的 .Net Framework 应用程序代码:
public void Send(EmailRequest emailRequest)
{
// Creates the message itselft
EmailMessage message = new EmailMessage(ServiceExchange);
message.Body = new MessageBody(emailRequest.Message);
message.Subject = emailRequest.Subject;
message.ToRecipients.Add(emailRequest.To);
// Create a custom extended property and add it to the message.
Guid myPropertySetId = Guid.NewGuid();
ExtendedPropertyDefinition myExtendedPropertyDefinition = new ExtendedPropertyDefinition(myPropertySetId, "MyExtendedPropertyName", MapiPropertyType.String);
message.SetExtendedProperty(myExtendedPropertyDefinition, "MyExtendedPropertyValue");
// Asynchronously, call
message.SendAndSaveCopy();
// Wait one second (while EWS sends and saves the message).
System.Threading.Thread.Sleep(1000);
// Now, find the saved copy of the message by using the custom extended property.
ItemView view = new ItemView(5);
SearchFilter searchFilter = new SearchFilter.IsEqualTo(myExtendedPropertyDefinition, "MyExtendedPropertyValue");
view.PropertySet = new PropertySet(BasePropertySet.IdOnly, ItemSchema.Subject, myExtendedPropertyDefinition);
FindItemsResults<Item> findResults = ServiceExchange.FindItems(WellKnownFolderName.SentItems, searchFilter, view);
if (findResults == null) throw new Exception("Could not find results - findResults is null");
if (findResults.Items == null) throw new Exception("Could not find results - findResults.Items is null");
if (findResults.Items.Count == 0) throw new Exception("Could not find results - findResults.Items is 0");
if (findResults.Items.Count > 1) throw new Exception("findResults items returned more than one result");
ItemId itemID = null;
}
例如:如果我将其发送到有效的电子邮件,一切都很好。这里的目标是检测故障,以便我们可以联系业务并检查为什么我们存储了错误的电子邮件地址。
慕容3067478
慕的地6264312
相关分类