This section shows how to save email attachments to a specified folder.
In this example, only PDF files are saved.
Robin(for copy and paste)
It can be copied and pasted into Power Automate Desktop.
Email.RetrieveEmails.RetrieveAndSaveAttachments IMAPServer: $'''imap.samurai-emblem.com''' Port: 993 EnableSSL: True Username: $'''test''' Password: P'AQAAANCMnd8BFdERjHoAwE/Cl+sBAAAAJZgwg7pl5kWccmSOPA4zfwQAAAACAAAAAAAQZgAAAAEAACAAAACvaCrZQnoFFVa58uK5gHP9KAWG6s078wIgxY5hg+aCkQAAAAAOgAAAAAIAACAAAABOqXaRUSESn+2KKKIW8gNbVv6dRiuBzFEzs2CDoQ11ahAAAAC9ZWyczm9qlyKW6s22kPX8QAAAAOahoiaLhTUHor7T6eRopL7OwKISwglcxCqhGztYxKBg9z6ZZnmsdImI+GwdA2P5RoPxBCFIhs1z+GPU3BiLD9s=' AcceptUntrustedCertificates: False MailFolder: $'''INBOX''' MailsToRetrieve: Email.RetrieveMessagesMode.All MarkAsRead: True SaveAttachmentsInto: $'''C:\\Test''' RetrievedEmails=> RetrievedEmails LOOP FOREACH CurrentItem IN RetrievedEmails LOOP FOREACH CurrentItem2 IN CurrentItem.Attachments Text.ChangeCase Text: CurrentItem2.Extension NewCase: Text.CaseOption.LowerCase Result=> TextWithNewCase IF TextWithNewCase = $'''.pdf''' THEN Text.ConvertDateTimeToText.FromCustomDateTime DateTime: CurrentItem.Date CustomFormat: $'''yyyyMMddhhmmss''' Result=> FormattedDateTime Folder.Create FolderPath: $'''C:\\Test\\MailSave''' FolderName: FormattedDateTime Folder=> NewFolder ON ERROR END File.Copy Files: CurrentItem2 Destination: $'''C:\\Test\\MailSave\\%FormattedDateTime%''' IfFileExists: File.IfExists.DoNothing CopiedFiles=> CopiedFiles END END END Folder.Empty Folder: $'''C:\\Test\\MailSave'''
The first step is to put "Retrieve email messages" in place.
If the incoming e-mail is an e-mail address registered in Outlook,
Since it is unlikely that all emails will be targeted, you can specify the extraction conditions here.
However, there is no date in the mail filter.
If you want to use the date as an extraction condition, you will need to use a combination of "this method" and this method.
Also, if you want to handle attachments as in this case, you need to specify the "Save attachments" parameter and the "Save attachments into" parameter.
If you simply want to save an attachment, this is all you need to do.
Note that the destination for attachments specified in the first action is a temporary destination.
Prepare a separate final folder.
Then put "For each" in place and specify %RetrievedEmails% as the "Value to iterate" parameter.
Attachments are list variables because there may be more than one.
Therefore, in order to handle one file at a time, it is necessary to repeat the process "For each".
"For each" is put in place, and %CurrentItem.Attachments% is specified in the "Value to iterate" parameter.
This example uses the file extension to determine the file extension, but other file properties such as the file name (.Name) and file size (.Size) can also be used for conditional branching.
Next, put "Change text case" in place to make the extension consistent with lowercase letters.
|Text to convert||%CurrentItem2.Extension%|
|Convert to||Lower case|
Next, put "If" in place.
If you want to make more than one extension a condition, do the following.
|First operand||%TextWithNewCase = '.pdf' OR TextWithNewCase = '.txt'%|
Next, create the name of the folder to be saved with "Convert datetime to text".
|Datetime to convert||%CurrentMail.Date%|
|Format to use||Custom|
Next, put "Create folder" in place.
|Datetime to convert||Any destination folder.|
(different from the first attachment destination)
|Format to use||%FormattedDateTime%|
To allow for duplicates (multiple attachments in one email), ignore the error.
Next, put in place a "Copy file(s) Action".
Finally, put "Empty folder" in place to delete all attachments remaining in the original folder.
This will delete all files that do not match the criteria, leaving only those that do.
For those who want to learn Power Automate Desktop effectively
The information on this site is now available in an easy-to-read e-book format.
Or Kindle Unlimited (unlimited reading).
You willl discover how to about basic operations.
By the end of this book, you will be equipped with the knowledge you need to use Power Automate Desktop to streamline your workflow.