Outlook search 2

i have a requirement

i have few fields in excel whose data i need to search in office 365
for example if cell A2 contains company name , i need to search company name in office 365 . the data can either be in mail attachment or in the body of the mail and need to download it .

how do i do that ?

Hi @poojaskyrathore

Office 365 is the website right?


  1. Read Excel Data:
  • Use ‘Excel Application Scope’ to read the company names from Excel into a DataTable.
  1. Get Outlook Mail Messages:
  • Use ‘Get Outlook Mail Messages’ to retrieve emails from your Office 365 mailbox.
  1. Iterate Through Emails:
  • Use ‘For Each’ to loop through each email obtained in the previous step.
  1. Search for Company Name:
  • Inside the loop, check if the company name from Excel is present in the email’s subject, body, or attachments.
  1. Download Attachments:
  • If the company name is found, use ‘Save Attachments’ to download them to a specified folder.
  1. Logging and Reporting:
  • Log relevant information using ‘Log Message’ and consider reporting the downloaded files for record-keeping.

Here’s a simplified pseudocode:

plaintextCopy code

Excel Application Scope
  Read Range (A2 company names into DataTable)

Get Outlook Mail Messages
  For Each mail in mailMessages
    If mail.Subject.Contains(companyName) Or mail.Body.Contains(companyName) Or AttachmentContainsCompanyName(mail.Attachments)
      Save Attachments
      Log Message ("Downloaded attachment from email: " + mail.Subject)
    End If
  End For Each

Replace companyName with the actual company name, and create a custom function (AttachmentContainsCompanyName) to check if any attachment contains the company name.

Ensure you handle authentication and security considerations appropriately.

i have given get outlook mail message an output variable and then for other activity
for each Currentitem i have given in option as variable of get outlook mail message

in body i need to give if activity right ? and the condition i m not getting there

Hi @poojaskyrathore

Use this in if condition

Currentitem.Subject.Contains(row("CompanyName").ToString) Or Currentitem.Body.Contains(row("CompanyName").ToString)

Hi @poojaskyrathore

Read Range
For Each row in dtCompanies
    Get Outlook Mail Messages (Filter: "Subject = '" + row("CompanyName").ToString + "'")
    For Each Currentitem in retrievedEmails
        If Currentitem.Subject.Contains(row("CompanyName").ToString) Or Currentitem.Body.Contains(row("CompanyName").ToString) Then
            Save Attachments
        End If

i m not getting that drill down of subject.contains automatically in the condition

can we connect over call for this issue ? this is very critical and i need to finish off within today … if you feel right can you call me on 8248882693

1 Like



Delete the activities drag and drop again. Give a try

Could you share your workflow, or send me the screenshot where you are not getting subject. @poojaskyrathore

i m using if activity for giving conditions

Inside for each activity you have to insert the If condition then you can get the subject when you hit on Ctrl+Space. @poojaskyrathore

Use if inside the for each as shown in above

Can you show the datatype of output variable

its system.collection.generic.list<system.net.mail.mailmessage>

Check the below workflow -

→ I used Get outlook mail message activity to retrieve the mails from the outlook and store in a Variable called Mailmessages it is List<mailmessage> datatype.
→ The output of Get outlook mail message activity give the input to the for each in List of items block.
→ Insert If activity inside the For each then try to give the Condition as below


Note - When you hit on Ctrl+Space to get the subject, sometimes it will not work in that time just type the condition what you want.

Hope you understand!! @poojaskyrathore

Can you try by typing currentitem. And then ctrl+spacekey and send a screenshot

For testing i have given read cell activity and varaible for it .

if i give that variable name instead of company name will that work ?mail.Subject.Contains(companyName) Or mail.Body.Contains(companyName) Or AttachmentContainsCompanyName(mail.Attachments)