Gmail trigger UiPath process | Configuration | Filters | IMAP | SMPT | UiPath Email Automation
0:00 Intro
1:00 Gmail configuration inside settings
2:50 Read Emails and Send Emails
10:30 Filters for emails
17:40 Trigger for Orchestrator
23:30 Google script add data on Orchestrator Queue and start UiPath process
Code:
function myFunction() {
var threadList = Gmail.Users.Threads.list('me', {
q: 'is:unread label:inbox'
});
if (threadList.threads && threadList.threads.length > 0) {
threadList.threads.forEach(function(thread)
{
var id2 = thread.id;
var tdata = Gmail.Users.Threads.get(userId='me', id=id2);
var msg = tdata.messages[0];
var subject = '';
var date = '';
var from = '';
var payload = msg.payload.headers;
payload.forEach(function(heads)
{
if (heads.name=='Subject') subject = heads.value;//Logger.log('Header Subject: %s', heads.value);
else if (heads.name=='Date') date = heads.value;//Logger.log('Header Date: '+heads.value);
else if (heads.name=='From')
{
This file has been truncated. show original
RPA_Canada
(RPA_Canada)
November 20, 2022, 7:00pm
2
Gmail trigger UiPath
Menu Resources is not available on https://script.google how i can find it?
I want to be fair with you I use this only when I create the movie. Please tell me the exact second of the movie where you have issues because I really don’t know.
Thanks,
Cristian
RPA_Canada
(RPA_Canada)
November 21, 2022, 3:06pm
4
Hi @Cristian_Negulescu ,
Thank you for creating such amazing videos
I found the error: The issue was that the gmail library was not added.
On the new Apps Script Interface this is the new path to do it
RPA_Canada
(RPA_Canada)
November 21, 2022, 3:08pm
5
Is there any way to get a file attached from the email using Apps Script?
Thanks for your detailed reply.
I will study to see how you can do this.
jauharul
(Jauharul Arifin)
November 21, 2022, 3:44pm
8
Thanks for sharing the wonderful tutorial. is it still working in 2022 since Gmail already update its security?
thank you
1 Like
So a way to do this is to have the file somewhere on WEB with a link on google drive and you will pass the link as a parameter of the process here:
‘InputArguments’:‘{"param1":"YOUR LINK","param2":"Video Live 21:21"}’
and in UiPath Studio you do the download for the file.
1 Like
RPA_Canada
(RPA_Canada)
November 21, 2022, 11:48pm
10
Could we get the attached file from the email that is triggering the process?
To download the file you need to use the object: GmailAttachment from this documentation
But like I said on the orchestrator you need a link, not a file.
Thanks,
Cristian
1 Like
RPA_Canada
(RPA_Canada)
November 22, 2022, 12:31pm
12
Thank you for the article.
I found the way how to create a file and send it to the email using google script as a link here
I’m looking how to get the link from the attached file on the email to send it on orchestrator
Thank you for your help.
RPA_Canada
(RPA_Canada)
November 22, 2022, 4:18pm
13
function searchInbox(){
const results = GmailApp.search(‘has:attachment’,0,5);
Logger.log(results);
let counter = 0;
results.forEach((thread)=>{
Logger.log(thread);
const messages = thread.getMessages();
messages.forEach((message)=>{
const attachments = message.getAttachments();
const subjectEmail = message.getSubject();
Logger.log(‘***’+ subjectEmail);
Logger.log(attachments);
attachments.forEach((data)=>{
Logger.log(data.getName());
Logger.log(data.getContentType());
if(data.getContentType() == ‘text/csv’){
const csv = data.getAs(‘text/csv’);
counter++;
const newFile = DriveApp.createFile(csv);
newFile.setName(‘NEW csv ‘+counter+’.csv’);
var resourceKey = newFile.getDownloadUrl();
Logger.log(resourceKey);
Logger.log(newFile.getId());
}
})
})
})
}