【问题标题】:Mails Sent Via Outlook Redemption Stuck in Outlook Outbox通过 Outlook 兑换发送的邮件卡在 Outlook 发件箱中
【发布时间】:2017-01-16 21:29:18
【问题描述】:

此问题发生在我们的一位客户身上,我无法使用相同版本的 Outlook 进行复制。我和我的客户正在使用安装了 Outlook 2016 的 Office 365。当他通过 Outlook Redemption(用于 Outlook 集成的第三方程序)在我们的程序中发送电子邮件时,邮件卡在他的发件箱中。

如果他双击消息(因此它会在 Outlook 中弹出),他可以点击发送按钮,它会成功发送。如果他们使用旧版本的 Outlook (2010),这不是问题。我当时将它们升级到了最新版本的 Outlook Redmeption(2016 年 5 月 7 日发布),尽管看起来它们几天前刚刚发布了新版本。我会尽快尝试,但更改日志没有提到邮件卡在发件箱中。

我还注意到,他发件箱中的电子邮件似乎带有“草稿”符号,而在我的发件箱中,它们带有“发送”符号。这似乎很重要,但我不确定我能做些什么。

此外,点击发送/接收所有文件夹也无济于事。

我的代码如下。感谢您的帮助。

        public static bool SendMessage(Recipients recipients, string[] addressListReplyTo, string subject, string body, string[] attachments, bool requestReadReceipt, Log log, bool isHtmlBody = false)
    {
        RDOSession session = null;
        RDOMail mail;
        RDOFolder folder;
        bool result = true;

        session = GetSessionAndLogon(log);
        if (session == null)
            return false;

        folder = session.GetDefaultFolder(rdoDefaultFolders.olFolderOutbox);
        mail = folder.Items.Add();
        if (isHtmlBody)
            mail.HTMLBody = body;
        else
            mail.Body = body;
        mail.Subject = subject;
        mail.ReadReceiptRequested = requestReadReceipt;
        foreach (string attachment in attachments)
        {
            if (attachment != "")
                mail.Attachments.Add(attachment);
        }
        foreach (string address in addressListReplyTo)
        {
            if (address != "")
                mail.ReplyRecipients.Add(address);
        }
        foreach (string address in recipients.To)
        {
            if (address != "")
                mail.Recipients.Add(address).Type = 1;
        }
        foreach (string address in recipients.Cc)
        {
            if (address != "")
                mail.Recipients.Add(address).Type = 2;
        }
        foreach (string address in recipients.Bcc)
        {
            if (address != "")
                mail.Recipients.Add(address).Type = 3;
        }

        foreach (RDORecipient recipient in mail.Recipients)
        {
            if (!OutlookMailEngine64.existsName(recipient.Name, session, log == null ? null : log))
                result = false;
        }
        if (result)
        {
            try
            {
                mail.Send();
                result = true;
            }
            catch (System.Runtime.InteropServices.COMException ex)
            {
                string message = "Error while sending email: " + ex.Message;
                if (log != null)
                    log.Message(message);
                if (OutlookMailEngine64.DiagnosticMode)
                    MessageBox.Show(message);
                throw new EmailLibraryException(EmailLibraryException.ErrorType.InvalidRecipient, "One or more recipients are invalid (use OutlookMailEngine64.ValidateAddresses first)", ex);
            }
        }
        if (session.LoggedOn)
            session.Logoff();

        return result;
    }

【问题讨论】:

    标签: c# outlook office365 outlook-redemption outlook-2016


    【解决方案1】:

    请记住,消息提交是异步的,除非您使用在线 Exchange 存储(其中存储和传输提供程序紧密耦合),否则它不会自动触发。

    您可以通过在 Outlook 对象模型中调用 Namespace.SendAndReceive 来强制发送/接收。

    【讨论】:

    • 发件箱文件夹中是否打开了预览窗格? Outlook 是否以斜体显示消息?
    • 邮件不是斜体的,这意味着 Outlook 不会尝试发送它们。如果您在创建和提交邮件时正在查看发件箱,它们是否会以斜体显示?
    • 你的 GetSessionAndLogon 方法的实现是什么?
    • 您能否创建 Outlook.Application 对象的实例并将 RDOSession.MAPIOBJECT 属性设置为 Application.Session.MAPIOBJECT 以确保两者共享相同的 MAPI 会话,而不是使用 RDOSession.Logon?
    • 只有在针对 Google Apps 商店运行时才会出现这种情况吗?还是 Exchange (Office 365) 邮箱?
    【解决方案2】:

    Dmitry 通过电子邮件与我合作。我的解决方案是将 RDO 换成 SafeMailItem 对象。这是我的方法的更新版本,因此您可以看到更改:

    private static bool SendSafeMessage(Recipients recipients, string[] addressListReplyTo, string subject, string body, string[] attachments, bool requestReadReceipt, Log log, bool isHtmlBody = false)
        {
            //This method was added because sometimes messages were getting stuck in the Outlook Outbox and this seems to solve that
            bool result = true;
    
            Microsoft.Office.Interop.Outlook.Application application = new Microsoft.Office.Interop.Outlook.Application();
            Microsoft.Office.Interop.Outlook.NameSpace namespaceMAPI = application.GetNamespace("MAPI");
            namespaceMAPI.Logon();
            RDOSession session = null;
            session = GetSessionAndLogon(log); //TODO: I'm creating a 2nd session here which is wasteful
    
            SafeMailItem safeMail = Redemption.RedemptionLoader.new_SafeMailItem();
            Microsoft.Office.Interop.Outlook.MailItem outlookMailItem = (Microsoft.Office.Interop.Outlook.MailItem)application.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
            safeMail.Item = outlookMailItem;
    
            if (isHtmlBody)
                outlookMailItem.HTMLBody = body;
            else
                safeMail.Body = body;
            outlookMailItem.Subject = subject;
            outlookMailItem.ReadReceiptRequested = requestReadReceipt;
            foreach (string attachment in attachments)
            {
                if (attachment != "")
                    safeMail.Attachments.Add(attachment);
            }
            foreach (string address in addressListReplyTo)
            {
                if (address != "")
                    safeMail.ReplyRecipients.Add(address);
            }
            foreach (string address in recipients.To)
            {
                if (address != "")
                    safeMail.Recipients.Add(address).Type = 1;
            }
            foreach (string address in recipients.Cc)
            {
                if (address != "")
                    safeMail.Recipients.Add(address).Type = 2;
            }
            foreach (string address in recipients.Bcc)
            {
                if (address != "")
                    safeMail.Recipients.Add(address).Type = 3;
            }
    
            foreach (Microsoft.Office.Interop.Outlook.Recipient recipient in outlookMailItem.Recipients)
            {
                if (!OutlookMailEngine64.existsName(recipient.Name, session, log == null ? null : log))
                    result = false;
            }
            if (result)
            {
                try
                {
                    safeMail.Send();
                    result = true;
                }
                catch (System.Runtime.InteropServices.COMException ex)
                {
                    string message = "Error while sending email: " + ex.Message;
                    if (log != null)
                        log.Message(message);
                    if (OutlookMailEngine64.DiagnosticMode)
                        MessageBox.Show(message);
                    throw new EmailLibraryException(EmailLibraryException.ErrorType.InvalidRecipient, "One or more recipients are invalid (use OutlookMailEngine64.ValidateAddresses first)", ex);
                }
            }
    
            if (session.LoggedOn)
                session.Logoff();
    
            namespaceMAPI.Logoff();
    
            return result;
        }
    

    【讨论】:

      猜你喜欢
      • 2017-12-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-14
      • 2012-03-03
      • 1970-01-01
      相关资源
      最近更新 更多