Rename pdf file while downloading as attachments from Outlook


#1

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.


#2

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

SaveAttachment.xaml (9.1 KB)


#3

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?


#4

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("."))


#5

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.


#6

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


#7

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


#8

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.


#9

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))))


#10

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.


#11

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.


#12

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


#13

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