Save email attachment per excel rules

Email rules_du.xlsx (11.8 KB)
Hi,
I have a task to save outlook email attachment according to my pre-set email rules in attached excel file.
The purpose is to
1.Read all unread emails in outlook.
2.Save attachment from row “Sender” unread emails which contains row “Key word” to path in row “Folder”.

Appreciate for a workflow for guidance, I’ve tried many times but not succeed.

Sender Key word Folder
zhang@dhn.com Shipment Notification C:\Users\z00371vw\Desktop\WK0401\RDA\DOC\DHL
liu@abb.com Cutoms issue C:\Users\z00371vw\Desktop\WK0401\RDA\DOC\Liu Xiao Qin
Xiang@tdk.com Today’s arrangement C:\Users\z00371vw\Desktop\WK0401\RDA\DOC\TDK
kui@seec.com Task to do C:\Users\z00371vw\Desktop\WK0401\RDA\DOC\Du Kui

Hi,

I have made a quick sequence to do what you want. I haven’t tested it but feel free to upgrade de solution to fit your needs.

  1. Read range your excel Rules Table into a DataTable (let’s called it “DT_RulesTable”)
  2. Read the unread mails into a List<System.Net.MailMessages> (via Get Outlook Mail Message for exemple) (Let’s called it “Lst_OutlookUnreadMessages”)
  3. Add a “For Each” with
    “TypeArgument” : System.Net.MailMessages
    “Values” : Lst_OutlookUnreadMessages
  4. change the For Each “item” to “mail”
  5. In the Body Add an “Assign” activity
  6. Create a “RuleRow as System.Data.DataRow” and put it in the left box of the assign activity
  7. Insert this LINQ request into the right box of the assign activity :

DT_RulesTable.AsEnumerable.FirstOrDefault(function(row) mail.Sender.Address = row(0).ToString AndAlso mail.Subject.Contains(row(1).ToString))

Your can change the condition for the “subject” to fit your needs (exemple: “StartWith” instead of “Contains”)

  1. Add a “If” activity with this condition :
    RuleRow IsNot Nothing
  2. Create a TargetFolderPath As string variable
  3. In the “True” part of the if add an assign activity with : TargetFolderPath = RuleRow(2).ToString

You now need to add the activities to get the attachement(s) and save it/them to the “TargetFolderPath”

Regards,
Boaepa

Dear,
Thanks for your reply.
I think the key part of this project is below part.
DT_RulesTable.AsEnumerable.FirstOrDefault(function(row) mail.Sender.Address = row(0).ToString AndAlso mail.Subject.Contains(row(1).ToString))
I compiled a similar words as your method but it doesn’t work.
I’ve successfully processed with each condition, but can not run with this multiple 2 conditions.
mail.From.Address.Contains(row(“Sender”).ToString) andalso mail.Subject.Contains(row(“keyword”)).ToString

System back with a compile error:
Overload resolution failed because no accessible “contains” can be called with these arguments: Public Function Contains…
Extension method…from ‘Object to Char’"

Dear all,
Case fixed.
Share my final workflow summary.
Read range of emailrules excel(output to a datatable MailrulesDT)
Get out look message(output to a list mailmessage variable Message)
For each mail in Message
For each Row in MailrulesDT
If Condition mail.From.Address.Contains(row.Item(“Sender”).ToString) And mail.Subject.Contains(row.Item(“keyword”).ToString)
Then
Save attachments
Mail
row(“Folder”).ToString

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.