0

This problem is happening for one of our customers and I have been unable to replicate on my side using the same version of Outlook. My customer and I are using Office 365 with Outlook 2016 installed. When he sends an email in our program via Outlook Redemption (a third party program used for Outlook integration), the mail gets stuck in his outbox.

If he double clicks the message (so it pops up in Outlook) he can hit the send button and it will sucessfuly send. If they use an old version of Outlook (2010) this is not a problem. I upgraded them to the the newest version of Outlook Redmeption at the time (released May 07, 2016), though it looks like they just came out with a new version a few days ago. I'll try that soon, but the changelog doesn't mention mail getting stuck in the Outbox.

I also noticed that the emails in his outbox have what appears to be the 'draft' symbol on them, while in my outbox they have a 'sending' symbol on them. This seems important, but I'm not sure what I can do about that.

Also, hitting Send/Receive All Folders does not help.

My code is below. Thank you for any assistance.

        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;
    }
bruestle2
  • 727
  • 1
  • 8
  • 22

2 Answers2

1

Keep in mind that message submission is asynchronous, and it will nto be automatically triggered unless you are using the online Exchange store (where store and transport provider are tightly coupled).

You can force send/receive by calling Namespace.SendAndReceive in the Outlook Object Model.

Dmitry Streblechenko
  • 62,942
  • 4
  • 53
  • 78
  • Thank you for your response. `Namespace.SendAndReceive` does the same thing as hitting Send And Receive All Folders manually in Outlook, correct? If so, that doesn't help. We clicked that button and the message still sits in the Outbox with the 'draft' icon rather than the 'sending' icon. The customer also tested with the newest version of Redemption (January 09, 2017), but that didn't help (I wasn't expecting it to, just wanted to update anyway). I would also be open to a direct communication with you if that would work better for you. Thank you for the assistance! – bruestle2 Jan 23 '17 at 15:57
  • 1
    Do you have the preview pane on in the Outbox folder? Does Outlook show the message italicized? – Dmitry Streblechenko Jan 23 '17 at 16:09
  • Here is a screenshot from the customer with a Send/Receive included to show they won't send. http://i.imgur.com/rWYQSh9.png Also, it turns out I was incorrect about one detail. They are using Google App Sync with Office 2016, not Office 365. – bruestle2 Jan 24 '17 at 19:33
  • 1
    The messages are not italicized, which means Outlook will not attempt to send them. If you are watching the Outbox as the messages are created an submitted, are they ever italicized? – Dmitry Streblechenko Jan 24 '17 at 20:04
  • Thank you, I did not know that. Spoke to the user over the phone and had him watch the outbox as the mail is going out. He says that the mail is not italicized ever. He then sent a mail directly through outlook and it was italicized and sent. – bruestle2 Jan 24 '17 at 21:20
  • 1
    What is your implementation of the GetSessionAndLogon method? – Dmitry Streblechenko Jan 24 '17 at 21:25
  • 1
    Instead of using RDOSession.Logon, can you create an instance of the Outlook.Application object and set the RDOSession.MAPIOBJECT property to Application.Session.MAPIOBJECT to make sure the two share the same MAPI session? – Dmitry Streblechenko Jan 25 '17 at 00:08
  • After changing my implementation of GetSessionAndLogon, I now cannot call RDOFolder.Items.Add() in order to add a mail to the Outbox, however the Outlook address book functions do work (pop up to screen, get entered value, etc). See screenshot with error: http://i.imgur.com/i4QNB4m.png. Here is the new implementation of GetSessionAndLogon with your suggested change: http://pastebin.com/MsRy8qUA – bruestle2 Jan 25 '17 at 21:30
  • 1
    Does this only happen when running against the Google Apps store? Or an Exchange (Office 365) mailbox as well? – Dmitry Streblechenko Jan 25 '17 at 22:55
  • I had that last problem on my own development machine. I'm using Office 365 with Outlook 2016. I haven't tried that with the customer and their setup since I need to make sure at least my setup works first. – bruestle2 Jan 25 '17 at 22:59
  • 1
    Is it a C2R or an MSI install of Outlook 2016? – Dmitry Streblechenko Jan 25 '17 at 23:11
  • It is Click 2 Run (I have the Office Updates section under File > Accounts). – bruestle2 Jan 26 '17 at 14:59
1

Dmitry worked with me via email. The solution for me was to swap out RDO for the SafeMailItem object. Here is the updated version of my method so you can see the changes:

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;
    }
Community
  • 1
  • 1
bruestle2
  • 727
  • 1
  • 8
  • 22