Outlook voting buttons

I saw the thread on adding voting buttons with the Invoke Code activity. I followed the steps in that post and have the following code written. I am getting a lot of complier errors. Can someone please help me make this work?

image

here is the link to the post I am referring to. I followed the steps written here.

hey

first of all we need to add the Microsoft.Office.Interop.Outlook depence:

next, in the invoke code activity change the language to C#:
image

next, change the New method to new method (lower case because we working on c#)

image

here is the code:

Microsoft.Office.Interop.Outlook.MailItem mailItem;

Microsoft.Office.Interop.Outlook.Application outlookApp = new Microsoft.Office.Interop.Outlook.ApplicationClass();

mailItem = (Microsoft.Office.Interop.Outlook.MailItem)outlookApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);

mailItem.Subject = "This Is the subject";
mailItem.To = "mail to send";
mailItem.Body = "This Is the message";
mailItem.VotingOptions = "Test1;Test2";

mailItem.Send();

hope it helps regards!

1 Like

Will this work if outlook is not installed on the machine the bot is running from?

it will not work without the Outlook installed.

regards!

Hi, how about with excel file attachment, how to add an attachment using invoke code?

Hi @Mariel_Pertos

First we need to add an argument in the invoke code activity, lets call it path

Provide direction as In and provide the full path of the document in the value

Then just add the line in the above code and pass the local argument we’ve created with the path

Microsoft.Office.Interop.Outlook.MailItem mailItem;
Microsoft.Office.Interop.Outlook.Application outlookApp = new Microsoft.Office.Interop.Outlook.ApplicationClass();
mailItem = (Microsoft.Office.Interop.Outlook.MailItem)outlookApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
mailItem.Subject = "This Is the subject";
mailItem.To = "EmailToSend@email.com";
mailItem.Body = "This Is the message";
mailItem.VotingOptions = "Test1;Test2";

// Add attachment
mailItem.Attachments.Add(path);

mailItem.Send();

Let me know if any questions or troubles

Regards!

Thanks. Is there any option to draft the email and not send it right away?

Hi @Mariel_Pertos

Just change mailItem.Send to mailItem.Save()


Microsoft.Office.Interop.Outlook.MailItem mailItem;
Microsoft.Office.Interop.Outlook.Application outlookApp = new Microsoft.Office.Interop.Outlook.ApplicationClass();
mailItem = (Microsoft.Office.Interop.Outlook.MailItem)outlookApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
mailItem.Subject = "This Is the subject";
mailItem.To = "EmailToSend@email.com";
mailItem.Body = "This Is the message";
mailItem.VotingOptions = "Test1;Test2";

// Add attachment
mailItem.Attachments.Add(path);

// Save the email as a draft
mailItem.Save();

Regards

Thank you. It works. how about using other account to send the mail

Hi @Mariel_Pertos

First keep in mind that you will need to be logged in outlook then we can just specify the account

Microsoft.Office.Interop.Outlook.Application outlookApp = new Microsoft.Office.Interop.Outlook.Application();
Microsoft.Office.Interop.Outlook.MailItem mailItem = outlookApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem) as Microsoft.Office.Interop.Outlook.MailItem;

mailItem.Subject = "This Is the subject";
mailItem.To = "recipient@example.com";
mailItem.Body = "This Is the message";
mailItem.VotingOptions = "Test1;Test2";

// Add attachment
mailItem.Attachments.Add(path);

// Specify the sender's email address
Microsoft.Office.Interop.Outlook.Account account = outlookApp.Session.Accounts["sender@example.com"];
mailItem.SendUsingAccount = account;

// Send the email
mailItem.Send();

Replace the account for the one that you have logged

Regards!

Hi @fernando_zuluaga

I would like to ask you how to save the outlook mail vote result in an Excel file using UiPath. Is it possible?

Thanks!