【问题标题】:How to Process NDR emails from Exchange Server in C#?如何在 C# 中处理来自 Exchange Server 的 NDR 电子邮件?
【发布时间】:2019-11-20 17:17:01
【问题描述】:

目前,我的应用程序能够处理传入的电子邮件,如果它与代码中的给定标准不匹配,则会退回。但是,我想向 Process 添加另一种类型的电子邮件,即来自 Microsoft Exchange Server 的 NDR“未送达报告”。所以我的应用程序不会响应/退回 NDR 到交换服务器,这会导致我的邮箱和 Exchange 服务器之间出现循环。 以下方法在 Invalid 没有特定时触发

private static void ProcessInvidMsgWithoutNo(string sMsgFrom, string sFromEmail, EmailMsg sMsgReceived, EmailMessage message)
    {
        EmailMsg.MoveToInvalid(message);

        sMsgReceived.IsValid = false;
        SaveMsgReceived(sMsgReceived, 0, string.Empty);

        if (!sFromEmail.Equals(string.Empty))
        {
            ResponseForInvidMsg(sFromEmail);
        }
        else
        {
            curLog.WriteLog(string.Format(CultureInfo.CurrentCulture, MsgEMChecker27, sMsgFrom));
        }
    }

按照上述方法触发响应传入的无效消息。

private static void ResponseForInvidMsg(string sFromEmail)
    {
        string tErrSubjectMsg = String.Format(CultureInfo.CurrentCulture, "{0}\\Resource\\MsgErrorSubjectAck.html", Entity.GetSetting("DocRootDir"));

        StringBuilder htmlText = new StringBuilder();
        FileStream fsFile = new FileStream(tErrSubjectMsg, FileMode.Open);

        if (fsFile != null)
        {
            StreamReader reader = new StreamReader(fsFile, Encoding.Default);

            string text;
            do
            {
                text = reader.ReadLine();
                if ((text != null) && (text != ""))
                    htmlText.Append(text + "\n");
            } while (text != null);

            reader.Close();
            fsFile.Close();
            fsFile = null;
        }
        else
            htmlText.Append("hello");

        string tToCustomerSubject = ReplyForInvalid;
        string tMessage = htmlText.ToString();

        EmailMsg emTo = new EmailMsg(string.Empty, sFromEmail, tToCustomerSubject, tMessage);
        emTo.MsgType = EmailMsg.TypeSentCustomer;
        emTo.Send(false); //Not save but CC to generic email box
    }

请帮助我找到一种方法来阻止我的代码响应 Exchange Server NDR。谢谢

【问题讨论】:

    标签: c# asp.net .net exchange-server exchangewebservices


    【解决方案1】:

    开始的地方是检查消息的 ItemClass 参见 https://docs.microsoft.com/en-us/openspecs/exchange_server_protocols/ms-asemail/51d84da6-a2da-41e9-8ca7-eb6c4e72c28d 。 NDR、交付报告等应具有报告前缀,例如

    REPORT.IPM.NOTE.NDR Non-delivery report for a standard message.
    REPORT.IPM.NOTE.DR Delivery receipt for a standard message.
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-06-24
      • 1970-01-01
      • 1970-01-01
      • 2010-11-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多