I have a requirement that as soon as I receive an email containing “Outlook Forms”, I have to read and extract the values from the fields of “Outlook Forms”.
In the below example, I have to extract the values for below fields from the email ‘Outlook forms’: “Full Name”, “Company”, “Job Title”, “File as”, “Business Phone numbers”, “Business Addresses” .
Could you please provide detailed steps how to do it ?
Good Evening. Thanks for the clarifications. Could you please provide the detailed steps on how to automatically execute the “Outlook Macros” for each of the emails received with “Outlook forms”. Is it using “Email activity” in UiPath?
How to integrate the extracted data from “Outlook Macros” and UiPath?
Could you please provide the detailed steps on how to proceed with it ?
Ideally instead of crwating macro ..as outlook supports vbscript..go with creating a vbscript which loops through each email form and reads the data..then write that data to text or excel file in vbscript itself..
If you want to trigger vbscript fromuipath you can ..or the same .code can be executed inside invoke code directly
For detailed code use chatgpt ..and you should be able to get the complete code
A sample from gpt is here which can be used inside invoke code..invoke code does not support using and all class and all are also not needed..just the mail code should be enough..try to add references in importa in UiPath
using System;
using System.Runtime.InteropServices;
using Outlook = Microsoft.Office.Interop.Outlook;
using Excel = Microsoft.Office.Interop.Excel;
class Program
{
static void Main()
{
try
{
// Start Outlook
Outlook.Application outlookApp = new Outlook.Application();
Outlook.NameSpace outlookNamespace = outlookApp.GetNamespace("MAPI");
outlookNamespace.Logon("", "", Missing.Value, Missing.Value);
Outlook.MAPIFolder inbox = outlookNamespace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
Outlook.Items items = inbox.Items;
// Start Excel
Excel.Application excelApp = new Excel.Application();
excelApp.Visible = false;
Excel.Workbook workbook = excelApp.Workbooks.Add();
Excel.Worksheet worksheet = (Excel.Worksheet)workbook.Sheets[1];
// Headers
worksheet.Cells[1, 1] = "Subject";
worksheet.Cells[1, 2] = "Sender";
worksheet.Cells[1, 3] = "Received Time";
worksheet.Cells[1, 4] = "Body";
int row = 2;
foreach (object item in items)
{
if (item is Outlook.MailItem mail)
{
worksheet.Cells[row, 1] = mail.Subject;
worksheet.Cells[row, 2] = mail.SenderName;
worksheet.Cells[row, 3] = mail.ReceivedTime.ToString();
worksheet.Cells[row, 4] = mail.Body;
row++;
}
}
// Save Excel file
string filePath = @"C:\Temp\OutlookEmails.xlsx";
workbook.SaveAs(filePath);
workbook.Close();
excelApp.Quit();
// Cleanup
Marshal.ReleaseComObject(worksheet);
Marshal.ReleaseComObject(workbook);
Marshal.ReleaseComObject(excelApp);
Marshal.ReleaseComObject(items);
Marshal.ReleaseComObject(inbox);
Marshal.ReleaseComObject(outlookNamespace);
Marshal.ReleaseComObject(outlookApp);
Console.WriteLine("Emails exported to Excel successfully.");
}
catch (Exception ex)
{
Console.WriteLine("Error: " + ex.Message);
}
}
}
Good Evening. Thank You very much for the detailed solution. This is very helpful. Will try it out and will get back to you if I have any further questions.