cancel
Showing results for 
Search instead for 
Did you mean: 

SAP Intelligent RPA Automation Mail Outlook

Hi guys,

i have problem when tried save file (.xlsx) attachment in folder path.

I saw the documentation before, this : https://contextor.eu/dokuwiki2/doku.php?id=lib:office:outlook#attachmentsave_oindex_path_object

that is my code,

any help?

Regards,

Accepted Solutions (1)

Accepted Solutions (1)

xbealan
Explorer
0 Kudos

Hello everyone,

I have a problem on save mail attachment part. I checked your solutions above. But I couldn't solve my problem.

- Filenames.push? I don't know this functionality, is it mandatory to use in this code scope?

- Can' I use attachmentSave function like

ctx.outlook.mail.attachmentSave(i,"C:\\Users\\---\\Desktop\\FromEmail\\Attachmentname.xlsx",1);

- Is there a correct example?

Thank you all.

yilmazozkn
Participant
0 Kudos

Hi Bengu, you should use object parameter after path,

Here my example;

	var res = ctx.outlook.mail.getFilteredTable();
	ctx.log("Mail length: " + res.length,e.logIconType.Info);
	for(var i = 0 ;i < res.length;i++){
		ctx.outlook.mail.retrieveMail({EntryID : res[i]['EntryID'], StoreID : res[i]['StoreID']});
	}
	ctx.log("Mail getCollectionLength: " + ctx.outlook.mail.getCollectionLength(),e.logIconType.Info);
	for (var i = 0;i< ctx.outlook.mail.getCollectionLength();i++){
		ctx.log("Mail i:" + i,e.logIconType.Info);
		ctx.log("Mail from :" + ctx.outlook.mail.getSenderAddress(i));
		ctx.log("Mail Subject :" + ctx.outlook.mail.getSubject((i)));
		ctx.log("Mail Body :" + ctx.outlook.mail.getBody((i)));
		ctx.log("Mail Attachments :" + ctx.outlook.mail.getAttachmentsCount((i)));
		
		
		for (var j=0;j<ctx.outlook.mail.getAttachmentsCount((i));j++){ 
				ctx.outlook.mail.attachmentSave(i,
"C:\\Users\\...\\RPA\\" + ctx.outlook.mail.getAttachmentsName(i)[j],
{Index : ++j} ); }
}
dianamatache
Explorer
0 Kudos

Hi Bengu,

Here is what I used to recursively save attachments from certain emails. I saved my attachments in the log file of the project. I hope it helps

for(i=0; i<mails.length; i++) {
    ctx.outlook.mail.retrieveMail({EntryID : mails[i]['EntryID'], StoreID : mails[i]['StoreID']});
  }

//Display some info about each email.
  ctx.log("---------------------------------------------------------");
  for(i=0; i<ctx.outlook.mail.getCollectionLength(); i++) {
    ctx.log("Mail no: " + i);       
    ctx.log("From: " + mails[i]['Sender']);       
    ctx.log("Subject: " + ctx.outlook.mail.getSubject(i));           
ctx.log("---------------------------------------------------------"); 
//Here we start the procedure of downloading the attachments in the email (if they exist).

//Get the number of attachments for each email.
noAttachments = ctx.outlook.mail.getAttachmentsCount(i);
//Get the name of the attachments.
attachments = ctx.outlook.mail.getAttachmentsName(i);
//Download the attachments if they exist.
if (noAttachments > 0) {
//Save each attachment separately.
for(j=0; j<noAttachments; j++){
filename = attachments[j];
path = ctx.options.path.log + "\\" + filename; 
ctx.outlook.mail.attachmentSave( i, path, { AttachmentName: filename } );
ctx.log('File downloaded: '+filename);
}
}
}
0 Kudos

Hi, sorry for the wait, what is your version of Desktop Studio ?

Answers (7)

Answers (7)

peterengel
Advisor
Advisor

Hi,

       var object = [];
       object["Index"] = 1;
			 fileNames.push(filePath+"\\"+ctx.outlook.mail.getAttachmentsName(i)[0]);
       ctx.outlook.mail.attachmentSave(i, filePath+"\\"+ctx.outlook.mail.getAttachmentsName(i)[0] ,object);

Documentation:

Br,

Peter

peterengel
Advisor
Advisor

Hi Edgar,

what I see in the error message is "AttachmentName". Please check your code if you use "AttachmentName". If yes insert an 's' after Attachment.

Here an example:

 fileNames.push(filePath+"\\"+ctx.outlook.mail.getAttachmentsName(i)[0]);
       ctx.outlook.mail.attachmentSave(i, filePath+"\\"+ctx.outlook.mail.getAttachmentsName(i)[0] ,object);
			 ctx.outlook.mail.setUnRead(i);

Br,

Peter

0 Kudos

No, another mail server

0 Kudos

Hi,

thanks Peter!

I saw my error , other question!

I can modified other mail server for the automatization?

thanks

Regards

peterengel
Advisor
Advisor
0 Kudos

You think about e.g. gmail? Not in this way. You have to use open api or screen capture.

0 Kudos

Hi Peter,

when send in the function: ctx.outlook.mail.attachmentSave()

third parameter send object, i tried send object of actually data how mark the documentation

my code is this (line 77):

¿what is the object to send in the function?

Regards

0 Kudos

Hi Peter,

Yes, i has check out library of Outlook

any help ?

Regards

peterengel
Advisor
Advisor
0 Kudos

Hi Edgar,

did you activate the outlook library in your project?

Br,

Peter