-1

I'm trying to develop a snippet in C # code that enables the "voting option" function of Outlook.

This code will be used by a platform called Blue Prism.

The "vote" function of Outlook is in the Microsoft.Office.Interop.Outlook namespace, so I need to import it using C#, but I dont have enough knowledge to develop this.

I tried to do something like this but it is giving an error. Here is the code:

public class program {

[DllImport(@"C:\Program Files\Blue Prism Limited\Blue Prism Automate\Microsoft.Office.Interop.Outlook.dll", EntryPoint = "VotingOptions")]
public static extern string Outlook(uint type);

static void Main()
{
    // Create the Outlook application.
    Outlook.Application  oApp = new Outlook.Application();
oApp.VotingOption = "Yes; No";
}

}

So, can someone help me?

Marek Stejskal
  • 2,698
  • 1
  • 20
  • 30
  • 2
    `[DllImport]` is for P/Invoke. You're looking for COM interop. Add a reference. – SLaks Jul 15 '18 at 02:58
  • Get hold of Adam Nathan's book .NET & COM. It's gotten a little simpler since that book was published, but it's still the right instruction manual for understanding both COM Interop and P/Invoke – Flydog57 Jul 15 '18 at 04:07
  • I added this reference :System.Runtime.InteropServices But the compiler appears: Compiler error at line 11:Email_POP3.SMTP.program.Outlook() is a 'method' but is used like a 'type' – Lucas Hoberty Jul 15 '18 at 13:17
  • That error message is pretty clear. Try reading it and thinking about what it means. – David Heffernan Jul 16 '18 at 07:35

3 Answers3

0

The VotingOptions property belongs to the MailItem class , not Outlook Application. Voting options on messages are used to give message recipients a list of choices and to track their responses. To create voting options programmatically, set a string that is a semicolon-delimited list of values for the VotingOptions property of a MailItem object. The values for the VotingOptions property will appear under the Vote command in the Respond group in the ribbon of the received message.

 private void OrderPizza()
 {
    Outlook.MailItem mail = (Outlook.MailItem)Application.CreateItem(
       Outlook.OlItemType.olMailItem);
    mail.VotingOptions = “Cheese; Mushroom; Sausage; Combo; Veg Combo;”
    mail.Subject = “Pizza Order”;
    mail.Display(false);
 }

Also you may find the C# app automates Outlook (CSAutomateOutlook) sample project helpful, it shows how to automate Outlook in C#.

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
  • Hi Eugene, Yes, the "Vote" option belongs to the MailItem, inside of Microsoft.Office.Interop.Outlook.dll, alright? I need to import this DLL on the application Blue Prism, because this DLL arent inside the NET framework... – Lucas Hoberty Jul 15 '18 at 22:20
0

Com objects aren't accessed through DLLImport. They're accessed using references. From the sample Eugene linked:

Create a Console application and reference the Outlook Primary Interop Assembly (PIA). To reference the Outlook PIA, right-click the project file and click the "Add Reference..." button. In the Add Reference dialog, navigate to the .NET tab, find Microsoft.Office.Interop.Outlook 12.0.0.0 and click OK.

Now you'll have access to the Microsoft.Office.Interop.Outlook object.

sgriffin
  • 337
  • 1
  • 9
0

If you are using Blue Prism then rather than having to specify DLL references you may also chose to go the GetObject or CreateObject way, you will be able to interact with Outlook just like Blue Prism does with Excel. The drawback of this approach is that you have to use VB.NET (unless I am mistaken) and that you will not be able to use text representation of enum values (so for OlItemType you will not be able to use olMailItem but only its numeric value, which is 0).

Please note that Blue Prism has released a new version recently (6.3) and with it a new VBO for interaction with Outlook. It's nothing revolutionary, but it may provide some insight.

Marek Stejskal
  • 2,698
  • 1
  • 20
  • 30
  • I haven't had any luck using this new VBO. I always get an error at the code stage `Get Items` where the error says something about `item` not having a `CC` property (among other invalid properties). Since all the 'Get Received Items' use this code stage at some point, I haven't been able to use it at all. On top of it, the documentation says the property is valid, so... I wouldn't recommend using this VBO just yet. – Jerry Sep 21 '18 at 07:47