Attachments - Read Email

Hi Everyone, i would like to know how to download files in especific by using the option Read email attachments , in my case i would like to now how to download a “xml” file using attachments

2 Likes

Hi!

To download Email attachments you can use the “Read emails” activity, making sure to check the “Download attachments” option that’s inside the “Attachments” section.

Once you’ve checked that box, other options will appear, including “Save duplicate with new name” (leave it checked if you want duplicate files to be saved with different names), and “Directory path template”, which you can use to set the folder where the attachments will be saved.

In the “Directory path template” field, you can simply write a directory name (such as “attachments” in the image above) or you can use some keywords to customize that directory name with properties such as the sender’s name, the email’s date and time, etc. You can check these keywords in this Help Center article, in the “Attachments” section under “Directory path template”.

Once you’ve executed the workflow, the “email_messages” variable will contain something like this. Note the highlighted “attachments” key, which contains the path where the attachment was downloaded, and also the “hasAttachment” value, which is “true”.

And here we can see the file itself in its location after the workflow was executed:

Let me know if this helps you!

2 Likes

i al ready tried that but when i have a lot of emails with several files for each email, this function download all files that content each email and what is jut want is just in this case my “xml” file

1 Like

In that case, the best approach would be to first download all the attachments from all the emails, and then loop through all the emails, and inside that do another loop for all the attachments.

Then, inside that second loop, you can use the “File information” activity from the OS Automation > Files & Folders category to get each attachment’s extension. Then you can use an “If…then” activity to check if that extension is “.xml” or not.

Here’s an example:

Let me know if this helps!

2 Likes

i already triend copy the same workflow like this

and drop me this in the file_info variable
" {
“name”: “Factura de deudores_2602 Ccren.xml”,
“extension”: “.xml”,
“length”: 5157,
“creation_time”: “2023-01-09T14:22:36.132-06:00”,
“last_access_time”: “2023-01-09T14:22:37.272-06:00”,
“last_write_time”: “2023-01-09T14:22:36.132-06:00”,
“creation_time_ms”: 1673295756132.8286,
“last_access_time_ms”: 1673295757272.1335,
“last_write_time_ms”: 1673295756132.8286,
“mode”: 33206,
“owner_uid”: 0
}
"
but in the file folder still downloading all the files

what did i do wrong? in the "read email " funtion i path the folder manually likt "c:C:\Users\proyect

2 Likes

Right, this workflow downloads all the attachments and then you can perform different actions depending on whether or not the file is an “.xml” file or not.

If, for example, you want to only keep the “.xml” files, you could use the “Delete file” activity from OS Automation > Files & Folders in the “No” branch of the “If…then” condition. So if the file is NOT an XML file, then it’s deleted.

Hope this helps!

2 Likes

i see i not important if it download all the files i see, but it drop me the format or name “xml” file and that is what i need , tnx, another question, if i have 3 emails differents i mean :slight_smile: email1@emai.mx, email2@email.mx , email3@email.mx and so, all those email save it in a text format, using “read text file” and text found , is it possible to find all those emails that are written in the text format to find it inside the email?

for example the email email1@email.mx and email3@email.mx all ready exist inside my inbox outlook and then make another process

2 Likes

Hi Carlos, my apologies, I am having trouble understanding your question.

Could you please rephrase it further or provide a little more context?

Thank you!

2 Likes

sorry my mistake , mi situation is this, i have more that 2 emails with differents names in this case save it in a file text, maybe later in a database but in this case in a text file, using “read text file” function and "text found " function or i dont know what function use, becase i need to create a way to create a way to find the existing emails in the text file (or database) and verify that they also exist and are correct within my email inbox, suppose I have email1@email.com , email2@email .com, email3@email.com and so written in my text file, and I need the robot to verify within my emails received from my inbox that it understands or knows that they exist and processes them later

2 Likes

Hi Carlos, if I understood correctly, you want to have a list of email addresses on a text file like this, correct?

ans4img5

Then you would like a bot to read this text file, grab the email addresses, and for each one of them check if you have received an email message from them on your inbox?

If that is what you need, you can do the following: first, to read the text file, you can use the “Read text file” activity from the OS Automation > Files & Folders category, and then you can use the “split” method to get a list of the email addresses that you can loop through, like this:

Then, you can use “Read emails” to get all the email messages from the last week (for example), like this (I set “Emails limit” to 5 to only grab 5 messages, to save on time, but you can skip that):

And finally do a loop through the list of email addresses from the txt, and for each one, check if it’s found in the list of emails, with this loop-within-a-loop:

Would this help you do what you need?

1 Like

i tried but the workflow drop me this error

what did i do wrong?

1 Like

Don’t worry, it’s a simple error: you need to remove the “if” from the Condition, and just leave the rest.

1 Like

thanks it works, another question using “read emails” in the option “filter by content” can i use that to read the content for each email as well as download its corresponding files

1 Like

Glad that solution worked!

Regarding this latest question, the filters in the “Read emails” activity, including the “Filter by content” options, limit which email messages are read from the inbox and saved to the email_messages variable, which is a JSON object. Using “Filter by content”, you can filter messages based on their Subject, their Sender or their Body (the content of the message).

If you later want to use the Body of the messages, you can access it by using the “text” or “textPlain” keys of the JSON object. For more details on the “email_messages” variable, check this article on the Help Center.

For example, if you have 4 emails and you want to access the text second one, you would access it by typing either “email_messages[1].text” or “email_messages[1].textPlain” - the index is 1 because the first element is index 0. The difference between “text” and “textPlain” is that “text” includes the full HTML code of the messaage, parsed to a JavaScript string, while “textPlain” only includes the text itself of the message, and excludes things like formatting, images and hyperlinks.

Let me know if this helped you!

1 Like

sorry i couldnt found the way how to use “read emails” to find an specific email , example in my text file i have “email1@email.com” and others and with ur help with the loop u send me i could verify is exist the mail inside mi inbox, now i want just to find the specific email and then read the content of the email, so using “filter by content” could work? in the specific “subject contains” i could introduce the name of the person or name of the mail?

1 Like

Yes, exactly, you can use the variable that contains the email address in the “Subject contains” field (make sure to select the “Calculate a value” option).

If you do that, you will only be reading messages from that address. If the result is empty, that means there weren’t any messages from that person.

1 Like

so the structure it has to be a json format? inside in “calculate a value” in the “subject contains”

1 Like

If the value is inside a variable, you can just write the variable name when using the “Calculate a value” option.

1 Like