Mail differentiation

Hello,

I have 5 different type of email which can be differentiate through naming convention of the attachment present
Which is the best way to get the mail type as each of them have different functionality to be done according to the name present in attachment

@shilpashree.mohanty

Get Outlook Mail Messages
Output: mailMessages (List<MailMessage>)
For Each email In mailMessages
If email.Attachments.Count > 0
For Each attachment In email.Attachments
If attachment.Name.Contains("Type1")
    Perform Action for Type1
Else If attachment.Name.Contains("Type2")
    Perform Action for Type2
Else If attachment.Name.Contains("Type3")
    Perform Action for Type3
Else If attachment.Name.Contains("Type4")
    Perform Action for Type4
Else If attachment.Name.Contains("Type5")
    Perform Action for Type5

Use Normal for each Loop only.
I hope this will help you

@shilpashree.mohanty

–>Retrieve Emails through GetOutlook or Get Imap Mail Messages
–>Loop through For Each Statement
–>Inside use Switch statement with expression attachment.name

Hi @shilpashree.mohanty

Use switch after getting all mails inside the for each

Hope it helps!!

@shilpashree.mohanty,

Follow this approach.

  1. Iterate through emails using For Each Email Activity
  2. Get the Attachments names and add to a List or array
  3. Check the naming conventions
  4. Categorize the email and add further logic scenario based using Switch activity.

Thanks,
Ashok :slight_smile:

Can we use 4-5 else if?

@shilpashree.mohanty

You can use switch also for this.

but in switch i cant use attachment.name

@shilpashree.mohanty

attachmentType = If(attachment.Name.Contains("Type1"), 1, 
                    If(attachment.Name.Contains("Type2"), 2, 
                    If(attachment.Name.Contains("Type3"), 3, 
                    If(attachment.Name.Contains("Type4"), 4, 
                    If(attachment.Name.Contains("Type5"), 5, 0)))))

 Switch
          Expression: attachmentType
          Cases:
            1:
              // Perform action for Type1
            2:
              // Perform action for Type2
            3:
              // Perform action for Type3
            4:
              // Perform action for Type4
            5:
              // Perform action for Type5
          Default:
            // Default action if no match

You can try this approach
attachmentType is of type Int

Use the Get Outlook Mail Messages activity.
Use a For Each activity to iterate through the list of emails.
Inside the loop, use an If activity to check if the email has attachments.

If email.Attachments.Count > 0 Then
’ Process attachments
End If

  • Use another For Each activity to loop through each attachment of the email.
  • Extract the name of each attachment using the Name property of the attachment.

For Each attachment In email.Attachments
Dim attachmentName As String = attachment.Name
Next

Use an If or Switch activity to determine the type of email based on the attachment name.

If attachmentName.Contains(“Type1”) Then
’ Handle Type 1 email
ElseIf attachmentName.Contains(“Type2”) Then
’ Handle Type 2 email
ElseIf attachmentName.Contains(“Type3”) Then
’ Handle Type 3 email
ElseIf attachmentName.Contains(“Type4”) Then
’ Handle Type 4 email
ElseIf attachmentName.Contains(“Type5”) Then
’ Handle Type 5 email
End If

Based on the type determined, invoke different workflows or activities specific to each type of email.