none
mailItem.Recipients returning empty until mail is saved RRS feed

  • Question

  • Sorry for another question on a Sunday.

    I have noticed that mailItem.Recipients is returning empty until I save the mail first (mailItem.Save). 

    Darryl

    Sunday, December 13, 2015 4:01 PM

All replies

  • Darryl, try tab then back tab.

    SendKeys.SendWait("{TAB}")

    SendKeys.SendWait("+{TAB}")

    John


    John C Svercek

    Sunday, December 13, 2015 4:18 PM
  • No luck, still seems to think it's empty.

    The problem with mailItem.Save is it creates a copy of the email in the drafts folder which doesn't go away.

    Sunday, December 13, 2015 4:27 PM
  • OOM doesn't reflect changes made through UI until the item is saved. You need to call the Save method sometimes to be able to see changes. What code do you use now?
    Sunday, December 13, 2015 4:54 PM
  • Hmmm, works for me. The mail item has to be visible and the active window. What version of Outlook are you using?

    I think Redemption lets you see recipients without having to do a Save.


    John C Svercek

    Sunday, December 13, 2015 5:18 PM
  • John what property are you using to run that?
    Sunday, December 13, 2015 5:22 PM
  • John,

    Redemption will not help in that case.

    Sunday, December 13, 2015 5:43 PM
  • Darryl,

    What code do you have now? Where do you run it?

    Sunday, December 13, 2015 5:44 PM
  • Hi Eugene,

    I have a ribbon button that sends the mail, here is how it looks.

    public void button1_Click(Office.IRibbonControl control)
            {

    var mailItem = Globals.ThisAddIn.Application.ActiveInspector().CurrentItem as MailItem;
                if (mailItem == null)
                    return;

                    

                int count = mailItem.Recipients.Count;
                string sender;
                try
                {
                    sender = mailItem.SendUsingAccount.SmtpAddress;

                }
                catch
                {
                    sender = string.Empty;
                }

    }

    At the moment, unless I put a mailItem.Save there. I cannot get a recipient count?

    Sunday, December 13, 2015 5:46 PM
  • Right, you need to save the item manually or programmatically to get visible all changes. You can switch to another fields in the inspector window or call the Save method for that. I don't see any code which calls the Send method however.

    Do you have any code in the ItemSend event handler?

    Sunday, December 13, 2015 5:58 PM
  • I did have

    mailItem.Save 

    But removed it because everytime I sent the message, it would still keep a copy in drafts even though the mail had gone. That's the end goal. I don't want the mail to stay in drafts after it's been sent. Hence why I don't want to use mailitem.Save.

    mailItem.Send(); is at the bottom but I removed some code on here

    I don't have any code in ItemSend now.

    Sunday, December 13, 2015 6:01 PM
  • TAB works for Outlook 2007 thru 2016.


    John C Svercek

    Sunday, December 13, 2015 6:05 PM
  • Hi John,

    I get this error if using that and trying to debug.

    Sunday, December 13, 2015 6:22 PM

  • public void button1_Click(Office.IRibbonControl control)
            {

    var mailItem = Globals.ThisAddIn.Application.ActiveInspector().CurrentItem as MailItem;

    I get my mail item differently.

    Dim MyMailItem As Outlook.MailItem = Nothing

    ~~~

                    'we are in the mail so add the logo and info to body
                    MyMailItem = CType(m_oApp.ActiveInspector.CurrentItem, Outlook.MailItem)


    John C Svercek

    Sunday, December 13, 2015 6:23 PM
  • Hi John,

    I get this error if using that and trying to debug.

    Ignore it, it is only displayed when running from the IDE.

    John C Svercek

    Sunday, December 13, 2015 6:40 PM
  • Hello Darryl,

    Do you have an IMAP account configured in Outlook? What Outlook version are you talking about?


    Sunday, December 13, 2015 7:57 PM
  • John - That still does not help sadly....I still get an empty for recipients.

    I am sending from an Outlook account. It does not recognize any recipients unless I save first.

    I don't want to save the mail first or it leaves behind a draft.

    Sunday, December 13, 2015 10:20 PM
  • Hi Darryl,

    >> At the moment, unless I put a mailItem.Save there. I cannot get a recipient count?

    I made a test with your code with the steps below, but I failed to reproduce your issue. I could get the recipient count.

    1. Create a new email
    2. Add recipients to the To field manually
    3. Click the button and I could see the Recipients.Count

           private void button2_Click(object sender, RibbonControlEventArgs e)
            {
                var mailItem = Globals.ThisAddIn.Application.ActiveInspector().CurrentItem as MailItem;
                if (mailItem == null)
                    return;
    
                int count = mailItem.Recipients.Count;
                MessageBox.Show(count.ToString());
                string sender1="";
                try
                {
                    sender1 = mailItem.SendUsingAccount.SmtpAddress;
    
                }
                catch
                {
                    sender1 = string.Empty;
                }
            }

    I made a test under Outlook 2013. Could you share us your outlook version and details steps to reproduce your issue?

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.



    Tuesday, December 15, 2015 6:18 AM