Rename pdf file while downloading as attachments from Outlook

Hi,
I tried searching for my issue in forum but couldn’t find the right solution, apologies for reposting if already discussed.

I have attachments in Outlook(X,Y,Z…) while downloading and before saving it using save attachment i want to rename it uniquely as X_01,Y_02,Z_03 and save in a folder.

Why i want to rename it is because few of my inbox mails are having attachments with same name but content is different and the bot is skipping the files with duplicate name and is not saving it, hence i wanted to save the attachments with unique auto incrementing values.
Any other suggestion would be highly appreciated.

Thanks in advance.

Not sure if solution was shared before, but this is one way.

SaveAttachment.xaml (9.1 KB)

3 Likes

Hey! Excellent!!!. Thanks for the immediate response and yes that works but was just wondering is there a way to extract the original attachment name and then add (MMDDYYHHMMSS) as suffix?

May be something like this, i know its lengthy. Its just splitting the name by last “.” in your file name. If you know you will have only one “.”, it will be much easier.

att.name = att.Name.Substring(0,att.Name.LastIndexOf("."))+now.ToString("MMddyyhhmmss")+att.Name.Substring(att.Name.LastIndexOf("."),att.Name.Length-att.Name.LastIndexOf("."))

Hey Thanks, that works but after downloading few attachments it throws error, i think i can fix that, my another concern is that i want to extract attachments only from particular email with certain subject lines and certain email addresses and mark those mails as read and move to another mail box.
For instance i want to download attachments from email having subject OR CONTAINING ‘xyz’,‘123’,‘SOMETHING’ sender’s address as ‘@xyz.com’,‘*@123.com’…and so on.
I am trying using like operator but it doesn’t seem to work.

Can’t guarantee, but try this filter

"@SQL= urn:schemas:httpmail:subject like ‘%SOMETHING%’ AND urn:schemas:httpmail:hasattachment=true AND “+Chr(34)+“http://schemas.microsoft.com/mapi/proptag/0x007D001E”+Chr(34)+ " like ‘%@domain.com%’”

Thanks,

Vinay

Or something like this in your for each :

emails.Where(Function(s) s.Attachments.Count>0 AND s.Subject.ToLower.Contains(“something”) AND s.Sender.Address.ToLower.Contains(“domain.com”))

Thanks,

Vinay

Hi,
This works fine for single type of subject line and single sender’s email address but doesn’t work when i am entering multiple subject lines/receiver’s addresses for pattern matching.

mail.Subject Like (“Something,123,xyz") Or mail.From.Address.Contains("@services.com;@ountres.com;@xon”) AND mail.Attachments.Any

I even tried using OR after every subject pattern/Sender’s address and also used mail.subject.contains.

mails.Where(Function(s) s.Attachments.Any AND ({ “abc”, “xyc”,
“Something” }.Any(Function(x) s.Subject.ToLower.Contains(x)) OR { “abc.com”, “xyz.com","@123.com”}.Any(Function(x) s.Sender.Address.ToLower.Contains(x))))

Hey thanks for your reply, really appreciate your effort but unfortunately it’s not working for me, i even tried using “”@SQL=" + “”“” + “urn:schemas:httpmail:subject” + “”“” + " like ‘%Uber%’" in my filters but it throws error.

I simply want to extract attachments from multiple sender addresses along with that i also want to extract attachments from mail having certain subject lines.
I am using get outlook mail messages.

I have given all options I can think of. If you want to filter on outlook level, then it’s going to be tough for you as the filters may not work as expected or you might be implementing in wrong way.

OR

Get all your emails and filter in your foreach loop as shown below :

mails.Where(Function(s) s.Attachments.Any AND ({ “abc”, “xyc”,

“Something” }.Any(Function(x) s.Subject.ToLower.Contains(x)) OR { “abc.com”, “xyz.com”,“@123.com”}.Any(Function(x) s.Sender.Address.ToLower.Contains(x))))

You can create the array’s dynamically

sub (string array) = ({ “abc”, “xyc”,“Something” }

dom (string array) = { “abc.com”, “xyz.com”,“@123.com”}

mails.Where(Function(s) s.Attachments.Any AND (sub.Any(Function(x) s.Subject.ToLower.Contains(x)) OR dom.Any(Function(x) s.Sender.Address.ToLower.Contains(x))))

If it doesn’t help , someone should be be able to help.

Hi , I get the below exception every time when i’m running the workflow.
Anyways, i really appreciate you spending time for me, thanks again

This has filter and no filter solutions. For filter to implement mulitple search patterns implemented @ClaytonM idea (i don’t think he remembers). See if any of the solution works for you.

emailfilter.xaml (9.6 KB)

I got above error when I used array variables, i will check why until then you can hard code the search patterns.

image

1 Like

Hai i have a doubt regarding the attachment of file can we rename the downloaded attachment with the senders mail id or username in gmail using uipath

@soumi_soumiya

If you want to rename with sender or receiver username
First read your mail with your get mail activities(either “get outlook mail” or "get IMAP mail messages) the output of these activities is list

Take for each loop configure the type argument as system.net.mailmessage

Now inside for each loop in file activities

You can use item.sender.DisplayName.tostring

Thanks,
Aman sheik

thanks for your help…!!!

ReadGmailMail.xaml (8.3 KB)
This is my file that i had developed for downloading the attachment from gmail. now i need to rename the downloaded attachment with user name. as you said where should i put for each activity to get the name .

thanks
soumiya.s

as you said i have added but i get object reference error i have attached my error. rename1 rename2

@soumi_soumiya I tried this one but iam getting as folder name (inside that folder name it is saving that attachment)
Example: if my sender name is Aman, it’s creating Aman as a folder inside that its saving the attachment. If this is Fyn for you , you can do like this

First , for each loop configure type argument as (system.net.mailmessage)

Inside for each loop take save attachment activity, in mail message place in attachment place you can give as “yourfolderpath”+item.sender.user.displayname

Or else if you want to save the attachment with the sender name only then after downloading you can get recent file from a folder (with code) then you can use move file activity then you can change the name accordingly ( these steps all in inside the for each loop)

Hope this helps

Thanks
Aman sheik

1 Like

@soumi_soumiya

Can you show the variable type of name

Thanks,
Aman

rename3

i need to know whether its possible to store the senders name in a variable as i did