RENAME WITH GMAIL ID

Greetings of the day…
i had given a task where i should download the attachment from the gmail and rename that attachment with senders mail id/username and date. They had said me that i should get the mail id and date in separate variable
eg: use A variable to get the mail id and B variable to get date. C variable is defined where C=A concatenate B. now this C will be renaming the file.
This is the task i am given but to get the mail id/username i had assigned a variable as name and gave mail.sender.displayname and made to display the content in name. But while i am running i am getting error.
rename2

can any one help me how to resolve this or is there any other way to get the username and date in a variable to achieve this task.

Thanks
Soumiya

1 Like

Did u try using write line to write each variable and see which one occur error?

@soumi_soumiya

Try this:

mail.From.Tostring

And also could you please tell me the steps you followed.

Thanks for your reply …Where should i use this syntax

1 Like

thanks for your reply…
where should i use this case activity

Thanks
Soumiya

@soumi_soumiya

  1. After reading mails from Gmail and it will give you output as List of MailMessages right and say mail

  2. Then use For Each loop Activity and pass that list of mail Messages to this to itreate one by one mail.

ForEach item in mail
use Write Line or Message box Activity and print item.From.Tostring

1 Like

Hi @soumi_soumiya
you have to follow the following Steps.

  • Read Mails Using get Imap Mail Messages Activity
    -Then use For each to Iterate the Mails select the For each argument as Mail.Mail messages
    -Get the Mail Id using The Item.from.Address It will give you the senders mail Id
  • Get the date in Another variable using Item.Headers(“Date”)
    -save The Attachment Using save Attachment activity
    -Then To rename the files Use Move file Activity provide the source path as Old Path And destination Path As your NewFolderPath+Your Both Variables
1 Like

Thank you…
it works it retrieves the user name and mail id of the user .

1 Like

Thanks for your reply
it works but i have a doubt regarding whether this renames each attachment that is downloaded else it only rename the overall folder.

@soumi_soumiya
Since we are using the For each It will Iterate one by one

  • It will Save the files as per the Attachment name You just have to provide the path
  • so your File will be saved Like This FolderPathYouProvided+AttachmentName
  • You can get attachment Name using CType(item.Attachments.FirstOrDefault, Attachment).Name
  • In the Move File activity You have to Provide source Path as above path
  • In the destination path You have To provide NewFolderPathYou+YourVariables
  • And this will work for every file because we are using Move file Activity in the for Each.

Thanks & Regards

1 Like

Thanks for your reply

     I had done as what you said but i am still facing certain issues that i have attached can you guide me where i have went wrong. 

destination%20path%20for%20rename filerename%20error from%20path%20to%20rename

Thanks
Soumiya

You are getting this error Because we can not provide Characters in The file Path Like *,&<( so Correct It.

Thanks for your reply…
I am able to get but dont know how to change in the stored variable

You Can Use the Replace Activity Just Replace That Characters With “”(Null).

what do you mean by Ctype

@soumi_soumiya It Is an Function for Converting to an expression to a specified data type for more Information refer The Link CType Function - Visual Basic | Microsoft Learn

where should i give this condition

Create A string Variable in a for each in the Assign Activity Give above to that variable.

1 Like

Thanks for your guidance…
attachement%20name%20that%20exsist date mail%20id

I had done with CType syntax now i should replace the attachment name with mail id and date. So i have 3 variable named as name which stores the username and mail id, other is the dmy which stores the date,time and the last in rename variable which stores the name of the attachment that is found in the mail. So now my issue is that i cannot concatenate the username and dmy because it has some special characters. How to over come this. As you said to use replace activity but i dont know how to scrap only the mail id/user name and only the date leaving the special char. i am attaching the mail id and dmy format that i get. Help me out to rectify it.

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