Open Outlook email template via Blueprism?

jassi_123

Member
Hello Team,

I have a Outlook email template which I use to send email to multiple receipients.

Can someone please tell me how to open outlook email template via Blueprism?
 

Laura Pilar

New Member
Hello Team,

I have a Outlook email template which I use to send email to multiple receipients.

Can someone please tell me how to open outlook email template via Blueprism?


Hello,

I am using c# code for send and read emails. I am working with Interop.Outlook and it work fine, but you need to configure an Outlook account.
 

Laura Pilar

New Member
can you show me how you have configured C# code for sending and reading emails.
Of course :)

ReadMailsFromOutlook:

first of all, I count the number of mails with the next C# code:

Microsoft.Office.Interop.Outlook.Application app = new Microsoft.Office.Interop.Outlook.Application();
Microsoft.Office.Interop.Outlook._MailItem mailItem = (Microsoft.Office.Interop.Outlook._MailItem)app.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
Microsoft.Office.Interop.Outlook.NameSpace nameSpace = app.GetNamespace("MAPI");
Microsoft.Office.Interop.Outlook.MAPIFolder inboxFolder = nameSpace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);
inboxFolder = nameSpace.Folders[account].Folders[bandeja];
//Hay que contar los elementos que hay para poder leerlos con un for
numMails = inboxFolder.Items.Count;

Then, I can go to Outlook and loop all emaill:

Microsoft.Office.Interop.Outlook.Application app = new Microsoft.Office.Interop.Outlook.Application();
error = "1";
Microsoft.Office.Interop.Outlook._MailItem mailItem = (Microsoft.Office.Interop.Outlook._MailItem)app.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
error = "2";
Microsoft.Office.Interop.Outlook.NameSpace nameSpace = app.GetNamespace("MAPI");
error = "3";
Microsoft.Office.Interop.Outlook.MAPIFolder inboxFolder = nameSpace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);
error = "4";
inboxFolder = nameSpace.Folders[account].Folders[bandeja];

body = "null";
subject = "null";
sender = "null";
senderAddress = "null";
if ((Microsoft.Office.Interop.Outlook.MailItem)inboxFolder.Items is Microsoft.Office.Interop.Outlook.MailItem && (Microsoft.Office.Interop.Outlook.MailItem)inboxFolder.Items!= null){
//error = "dentro del if";
body = ((Microsoft.Office.Interop.Outlook.MailItem)inboxFolder.Items).Body;
//error = "pasa body";
subject = ((Microsoft.Office.Interop.Outlook.MailItem)inboxFolder.Items).Subject;
//error = "pasa subject";
sender = ((Microsoft.Office.Interop.Outlook.MailItem)inboxFolder.Items).SenderName;
//error = "pasa sender";
senderAddress = ((Microsoft.Office.Interop.Outlook.MailItem)inboxFolder.Items).SenderEmailAddress;
//error = "pasa emailAddress";
//date = ((Microsoft.Office.Interop.Outlook.MailItem)inboxFolder.Items).CreationTime;
//attachment = ((Microsoft.Office.Interop.Outlook.MailItem)inboxFolder.Items).Attachments;
error = "mail";
}

else {
i = i + 1;
body = "null";
subject = "null";
sender = "null";
senderAddress = "null";
error = "no es igual";
//date = ((Microsoft.Office.Interop.Outlook.MailItem)inboxFolder.Items).CreationTime;
}
//}


This code returns a collection with all mails. I have a rule in my Outlook to move all the mails like meetings and other "extrange" mails.

SendMailsFromOutlook:

Microsoft.Office.Interop.Outlook.Application app = new Microsoft.Office.Interop.Outlook.Application();
Microsoft.Office.Interop.Outlook._MailItem mailItem = (Microsoft.Office.Interop.Outlook._MailItem)app.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
//mailItem.Sender = "";
mailItem.Subject = Subject;
mailItem.To = To;
mailItem.Body = Body;
mailItem.Recipients.Add(Cc);
mailItem.Attachments.Add(Path, OlAttachmentType.olByValue, Type.Missing, Type.Missing);
mailItem.Importance = Microsoft.Office.Interop.Outlook.OlImportance.olImportanceLow;
mailItem.Display(false);
//return mailItem;
mailItem.Send();


I control the Cc and the attachment with the next diagram:

1527493867072.png
 
Last edited:

jreddy

New Member
Hi guys,

i have recently implemented a similar C# code to retrieve Emails from Outlook. Here's my code:

Code:
Microsoft.Office.Interop.Outlook.Application olApp = new Microsoft.Office.Interop.Outlook.Application();
Microsoft.Office.Interop.Outlook.NameSpace olNS = olApp.GetNamespace("MAPI");
Microsoft.Office.Interop.Outlook.MAPIFolder inbox = olNS.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);

emails = new DataTable();

emails.Columns.Add("Sender", typeof(string));
emails.Columns.Add("Subject", typeof(string));
emails.Columns.Add("Body", typeof(string));
emails.Columns.Add("Date", typeof(string));

foreach (Microsoft.Office.Interop.Outlook.MailItem item in inbox.Items)
    emails.Rows.Add(new object[] {    item.SenderName,
                                    item.Subject,
                                    item.HTMLBody,
                                    item.SentOn.ToLongDateString()+" "+item.SentOn.ToLongTimeString()
                                    });

But I can't run because I get an interface error:
COM-Object of type System._ComObject cannot be converted to the interface-type Microsoft.Office.Interop.Outlook.MailItem. This can't be done because the query to COM-Component for the interface with ID {00063034-0000-0000-C000-000000000046} can't be executed because of the following problem: Interface is not supported (Exception HRESULT 0x80004002 (E_NOINTERFACE))

I have attached screenshots with error message and my imports. What am I doing wrong?
 

Attachments

  • BP Interface Error.png
    12.4 KB · Views: 55
  • Initialise Stage Imports.png
    16.7 KB · Views: 40

Laura Pilar

New Member
I think that the error is that you are trying to retrieve all the items of your mailbox, but there are several kinds of item (mails, meetings...) and when it find a item that it is not a mail, it returns the error. If you need all the emails, you could filter by the MailItem.GetType() or you can create an Outlook rule to remove "uncommon" emails to the current folder.

Laura.
 

jreddy

New Member
Hi Laura,

sorry for late reply, but your hint indded helped me out. After some googling I modified the code in the following way, adding check whether the object is really a MailItem:

Code:
Microsoft.Office.Interop.Outlook.Application olApp = new Microsoft.Office.Interop.Outlook.Application();
Microsoft.Office.Interop.Outlook.NameSpace olNS = olApp.GetNamespace("MAPI");
Microsoft.Office.Interop.Outlook.MAPIFolder inbox = olNS.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);

//olNS.SendAndReceive(true);

emails = new DataTable();

emails.Columns.Add("Sender", typeof(string));
emails.Columns.Add("Subject", typeof(string));
emails.Columns.Add("Body", typeof(string));
emails.Columns.Add("Date", typeof(string));

foreach (object item in inbox.Items)
{
    if (item is Microsoft.Office.Interop.Outlook.MailItem)
    {
        Microsoft.Office.Interop.Outlook.MailItem mailItem = (Microsoft.Office.Interop.Outlook.MailItem)item;
        emails.Rows.Add(new object[] {mailItem.SenderName, mailItem.Subject, mailItem.Body, mailItem.SentOn.ToLongDateString()+" "+mailItem.SentOn.ToLongTimeString()});
    }
}

Hope this will be useful for somebody in future as well :)
 
Hello everyone !
please i want to add in blue prism action that may help me to check my outlook inbox every 1 hour (1h) to see if the mail has been receieved or not , but currently i work with code stage (C#) so i can get attachement and body mail , any solution for this problem, and can i complete my code to add this check ??? thank you for you help !
 

Attachments

  • Outlook.txt
    2.9 KB · Views: 47
/*
This Business Object makes use of the Microsoft.Office.Interop.Outlook assembly,
it's referenced in the code options tab of the BO properties, as an external reference
*/
string txtBody = "";
DataTable edbFnames = new DataTable();
edbFnames.Columns.Add(new DataColumn("File Name", typeof(String)));
int index = 1;
DateTime edate = DateTime.Now.Date;
if( ddate != DateTime.MinValue)
edate = ddate;
Microsoft.Office.Interop.Outlook.Application Application = new Microsoft.Office.Interop.Outlook.Application();
Folder root = Application.Session.DefaultStore.GetRootFolder() as Folder; //Gets the root folder
Folders childFolders = root.Folders; //Gets the child folders of the root folder

if (childFolders.Count > 0)
{
foreach (Folder childFolder in childFolders) //Iterates through ROOT's child folders
{
if (childFolder.FolderPath.Contains(inboxF)) //Finds the Inbox folder
{

var fi = childFolder.Items;
if (fi != null)
{
foreach (Object item in fi) //Iterates through Inbox's objects
{
try
{
MailItem mi = (MailItem)item; //Cast Objects to Mails
if(mi.Subject.Contains(SMC) && mi.CreationTime.Date.ToString().Contains(edate.ToString())) //Look for the mail that regards all the conditions
if(mi.Attachments.Count > 0) //Check if the mail has attachments
for (int i = 1; i <= mi.Attachments.Count; i++) //Iterates throught attachments
{
if(mi.Attachments.FileName.Contains("pdf")) //Looks only for the excel file
{
mi.Attachments.SaveAsFile(dPath + mi.Attachments.FileName); //Save the pdf attachment in a given path
txtBody = mi.Body;
edbFnames.Rows.Add(dPath + mi.Attachments.FileName); //Store the excel file name in a DataTable(Collection)
index++;
}
else if(mi.Attachments.FileName.Contains("docx"))
{
mi.Attachments.SaveAsFile(dPath + mi.Attachments.FileName); //Save the docx attachment in a given path
txtBody = mi.Body;
edbFnames.Rows.Add(dPath + mi.Attachments.FileName); //Store the excel file name in a DataTable(Collection)
index++;
}
else if(mi.Attachments.FileName.Contains("xlsx"))
{
mi.Attachments.SaveAsFile(dPath + mi.Attachments.FileName); //Save the docx attachment in a given path
txtBody = mi.Body;
edbFnames.Rows.Add(dPath + mi.Attachments.FileName); //Store the excel file name in a DataTable(Collection)
index++;
}
}
}
catch{}
}
}
}
}
}
EDB = edbFnames;
bod = txtBody;
 

Laura Pilar

New Member
Hello everyone !
please i want to add in blue prism action that may help me to check my outlook inbox every 1 hour (1h) to see if the mail has been receieved or not , but currently i work with code stage (C#) so i can get attachement and body mail , any solution for this problem, and can i complete my code to add this check ??? thank you for you help !

Maybe you need to use this:
Items.Restrict("[Unread]=true");
In your case, Items = mi
Regards!
 
Hello All,

I am having a requirement related to Outlook email file (.eml) format.

I am downloading outlook email (.eml) extension file from my application and stored in local drive (C:\).
I need to extract all attachments in that outlook email (.eml) file and store it in local drive (C:\).

Thanks in advance.
 

Attachments

  • Email Attachments1.png
    47.9 KB · Views: 35
  • Email Attachments3.png
    17.6 KB · Views: 31

Sachin_Kharmale

Active Member
Hi VenkataKrishna ,

You can use following Code to Read .msg File Details :
View attachment 1559288617430.png
fig 1- New action to get mail details add code stage in blue prism Object Studio
View attachment 1559288730503.png
fig 2- code stage it will read msg file details

Use Following Code to Read Details of Outlook Message File

Try
Dim App As New Outlook.Application()
Dim item As Outlook.MailItem = App.CreateItemFromTemplate(Msg_File_Path, Type.Missing)
'Console.WriteLine("Mail Item Created ")
ToMail =item.To
CC=item.CC
Subject=item.Subject
Recived_Time=item.ReceivedTime
Attachment_Count=item.Attachments.Count.ToString
Success=true
catch ex As Exception
Message=ex.Message
Success=false
End Try


Best,
Sachin
 
Try
Dim App As New Outlook.Application()
Dim item As Outlook.MailItem = App.CreateItemFromTemplate(Msg_File_Path, Type.Missing)
'Console.WriteLine("Mail Item Created ")
ToMail =item.To
CC=item.CC
Subject=item.Subject
Recived_Time=item.ReceivedTime
Attachment_Count=item.Attachments.Count.ToString
Success=true
catch ex As Exception
Message=ex.Message
Success=false
End Try
Hi sachin facing "Outlook.Application is defined" can you please help me out in this?
 

kattapug

New Member
Hi Sachin,

I would appreciate it if you could help me out. I have followed the above instruction to creat the VBO. I have validated and no error is thrown up. When creating the VBO it has all the fields as in View attachment 1559288730503.png as above,

When creat a process flow with an Action object and select the Outlook Object - Manual VBO in Business Object field and from Action drop-down I select Get Message Details as defined in the VBO, all the Inputs and Outputs are blank.

Please could suggest any solutions. See attached. View attachment 1572304550237.png
 
Top