Hello Forum,
I would really appreciated if you could advice me on how:
store in a variable the name of one attachement email that was received in my outlook inbox.
The idea is : i have several emails with attachments. So, i want to extract attachments names in a variable ( because my workflow will save the file in a folder path) and then il will use this variable to be able to save again the attachment with the same name BUT with a diferent extension. That’s the reason i need to store the name in a variable …
any suggestion on how to do it will be much appreciated.
Thanks
You can use For Each activity for the email to run the loop
Now you can choose a string variable and give as
mailMessage.Attachments.Select(function(x) x.Name).toArray()
Use “Get Outlook Mail Messages” activity onto your UiPath workflow.
Configure the properties of the “Get Outlook Mail Messages” activity, such as specifying the folder (e.g., Inbox) and output variable to store the retrieved emails.
Use a “For Each” loop activity to iterate through each email in the mailMessages.
Within the loop, drag and drop the “Save Attachments” activity.
Configure the properties of the “Save Attachments” activity, such as specifying the email (e.g., item), the folder path to save the attachment, and the output variable to store the saved attachment (let’s call it attachmentPath).
After the “Save Attachments” activity, use an “Assign” activity to store the attachment name in a variable. For example, you can use the following expression: attachmentName = Path.GetFileName(attachmentPath).
You can then use the attachmentName variable to save the attachment with a different extension or perform other operations as needed
.
I hope it helps.
Hello @fernando_zuluaga
Thanks for helping.
I tried the third example but i have still problem to make it work
you will see in picture below my workflow, where i have already (it is not shown in the picture) filter email from outlook then:
step 1 : i use a Switch activity to filter by attachement name , just if the include some string patterns)
step2: just a message to control for my tests
step 3: in this activity i just apply for marking as read message
step 4 : just to eliminate color categories in a email
step 5: my main problem : i have problem to save the name of the attachement in a variable…would you help on that…
Hi @Anil_G and thanks for helping,
I am using a Switch scenario to catch an email individually instead of using a list variable (and the attachment target ) to save it. you could find the concept of my workflow here.
I have previously filtered the email by : unread and red category (it is not shown in the picture) then I use a Switch activity to verify string subject matches, then once an email respect that string pattern in subject, i use Get outloot mail message to mark as unread. then set outlook mail categories to erase color categories .
Finally (and heres is my problem) i want to store the name of the attachment in this email into a variable . just to be able to use this name after…
Thanks to all of you guys!
Finally, i could store the name in a variable using:
CType(mail.Attachments.FirstOrDefault, Attachment).Name
I tried all the other suggestion but i couldn’t make it work for some reason.
Thank you very much for helping…
Richch