1

I basically want to create emails which shall be displayed in the Outlook Inbox using C# Outlook VSTO AddIn. I have installed the test dlls for Outlook Redemption in my C# Outlook VSTO Addin. For testing purposes I created a Ribbon Bar with a button. When the button is clicked the following event is triggered:

private void CreateMailItemWithRedemption()
{
    //FYI: outlookApp is set in Ribbon load event
    //Outlook.Application outlookApp = Globals.ThisAddIn.Application as Microsoft.Office.Interop.Outlook.Application;
    var outlookNameSpace = outlookApp.GetNamespace("MAPI");
    RDOSession session = new RDOSession();
    session.MAPIOBJECT = outlookNameSpace.MAPIOBJECT;
    RDOFolder folder = session.GetDefaultFolder(rdoDefaultFolders.olFolderInbox);
    RDOMail msg = folder.Items.Add("IPM.Note");
    msg.Sent = true;
    DateTime dt = new DateTime(2021, 8, 29, 5, 10, 20, DateTimeKind.Utc);
    msg.ReceivedTime = dt;
    msg.Subject = "Mail created with Redemption";
    msg.To = “******@outlook.com”;
    msg.Sender = GetAddressEntry("[TestFirstName] [TestLastName]");
    msg.Save();
}

It basically works – but for the time being I am stuck with setting the Sender for the new RDOMail which I understand needs to be an RDOAddressEntry.

The GetAddressEntry method looks as follows (with firstname string + lastname string of an existing contact as parameter, like “John Do”):

private RDOAddressEntry GetAddressEntry(string _name)
{
    RDOSession session = new RDOSession();
    session.MAPIOBJECT = outlookApp.Session.MAPIOBJECT;
    RDOAddressList contacts = session.AddressBook.GAL;
    RDOAddressEntry contact = contacts.ResolveName(_name);
    MessageBox.Show(contact.ToString());
    return contact;
}

At contacts.ResolveName an exception is thrown. Do you have an idea what I am doing wrong? Any hints are welcomed. Many thanks in advance Alexander

Alexander
  • 23
  • 3
  • Does the name actually exist in GAL? Or is it a one-off SMTP address? – Dmitry Streblechenko Aug 29 '21 at 17:57
  • Do you get the same results with the `CreateRecipient` method? – Eugene Astafiev Aug 29 '21 at 18:02
  • Thanks for your replies - it is a one-off SMTP address; I have changed the line "**RDOAddressList** contacts = session.AddressBook.GAL;" in GetAddressEntry method to "**RDOAddressBook** contacts = session.AddressBook;" and now it works (despite the fact that in the InBox the sender is not displayed, but when I create a copy of the mail the name/email gets displyed as well). I will also test the CreateRecipient proposal. – Alexander Aug 30 '21 at 15:31

0 Answers0