第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在 Exchange C# 上檢測發(fā)送電子郵件失敗

如何在 Exchange C# 上檢測發(fā)送電子郵件失敗

C#
富國滬深 2021-12-25 18:43:40
我試圖檢測我的應(yīng)用程序發(fā)送的電子郵件是否發(fā)送失敗。這意味著我不是要驗證電子郵件,而實際上只是驗證它是否到達了目標(biāo)郵箱。這是我正在使用的 .Net Framework 應(yīng)用程序代碼:    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;    }   例如:如果我將其發(fā)送到有效的電子郵件,一切都很好。這里的目標(biāo)是檢測故障,以便我們可以聯(lián)系業(yè)務(wù)并檢查為什么我們存儲了錯誤的電子郵件地址。
查看完整描述

2 回答

?
慕容3067478

TA貢獻1773條經(jīng)驗 獲得超3個贊

如果您存檔的電子郵件地址無效,則 SendAndSaveCopy() 應(yīng)該拋出一個異常說明。你可以實現(xiàn)一個 try/catch 語句來檢測任何失敗,并將失敗發(fā)送到一個記錄器,它會給你一個文本列表來處理:


public void Send(EmailRequest emailRequest)

{

    try

    {

        // 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);

    }

    catch (Exception x)

    {

        logger.LogError(x.Message);


    }

}

您可以在此處找到其他示例。


查看完整回答
反對 回復(fù) 2021-12-25
?
慕的地6264312

TA貢獻1817條經(jīng)驗 獲得超6個贊

我試圖檢測我的應(yīng)用程序發(fā)送的電子郵件是否發(fā)送失敗。這意味著我不是要驗證電子郵件,而實際上只是驗證它是否到達了目標(biāo)郵箱。

一旦您將消息交給 Exchange,它甚至可能不會立即發(fā)出。一旦 Exchange 嘗試發(fā)送它,它可能會發(fā)現(xiàn)遠程服務(wù)器不可用并稍后重試。

最終,Exchange 要么讓遠程服務(wù)器接受消息,要么放棄。

如果遠程服務(wù)器接受該消息,并且您在消息中配置了該標(biāo)志,則您可以獲得發(fā)送回執(zhí)。然而這并不能意味著該郵件確實送達收件人或收件人閱讀; 這僅意味著 Exchange 能夠?qū)⑵涮峁┙o目標(biāo)服務(wù)器。

許多服務(wù)器只是簡單地接受和丟棄發(fā)送給不存在的用戶的郵件。其他人將它們?nèi)拥饺帧袄]件”文件夾中。

如果您在郵件中設(shè)置了正確的“回復(fù)”地址,并且在 Exchange 管理員設(shè)置的超時時間內(nèi)無法將郵件傳送到遠程服務(wù)器,您將收到來自 Exchange 的電子郵件。這通常是幾天。

但是,即使您設(shè)置了“已讀回執(zhí)”標(biāo)志,收件人也完全有可能閱讀郵件而不發(fā)送郵件。遵守是自愿的。

真正非常簡短的回答是“您可以檢測到即時故障,但實際上無法確定消息是否已被讀取或傳送”,并且無論如何都不會在您的代碼中發(fā)生。

如果有幫助,有一些錯誤可以立即檢測到,這些錯誤會顯示在您的 try/catch 塊中,但這些是例外而不是規(guī)則。


查看完整回答
反對 回復(fù) 2021-12-25
  • 2 回答
  • 0 關(guān)注
  • 203 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號