How can I save attachment directly out of email with a new name (e.g. date of email)?

Hello,

I want to save the attachment of emails in my computer folder with a new name (e.g. date of email).

I have already tried out the rename activity, but it did not work (for me).

How is the best way to do it?

Thanks!

Hi @aaydin ,

Rename file might work if you provide input as attachments(0).

Where attachments is the output of save attachment activity.

You can get mail received date using mailVariable.Date

Hi @aaydin

Give a try to this

mails(0).Attachments(0).Name=Datetime.Parse(mails(0).Headers("Date")).ToString("dd_MM_yyyy")+".xlsx"

Or

mails(0).Attachments(0).Name=mails(0).DateAsDateTime.ToString("dd_MM_yyyy")+".xlsx"

Hope this helps.

2 Likes

Where do I put this information?

@aaydin

Check this

Is “attachments(0)” a new variable?

Sorry I did not get your point :frowning:

Hi @aaydin ,

attachment is output of Save attachment activity.

image

Hi @aaydin ,

Method suggested by @Suraj_B_Shetty is more efficient than mine as you can change the name before saving the attachment. You can try that method.

@Harshith_Adyanthaya @Suraj_B_Shetty
My idea is to save the attachment of email in that format:

e.g. “134705_John Mayer”
“hhmmss_sendername”

I saved datetime and sendername in variables

DateTime.ParseExact(str_dateOfMail_2,“HH:mm:ss”,Globalization.CultureInfo.InvariantCulture).ToString(“HHmmss”)

str_SenderName = mail.From.DisplayName.ToString

When I try to put bot variables as new name in Rename activity it does not work.

What was the input you provided for rename activity?
It should be output of save attachment activity (0).

File:
attachments(0)

New Name:
str_dateOfMail_2+“_”+str_Name

Thank you!

Does it throw error?

Now it worked. thank you

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.