Actions when email received

email
activities

#1

Is it possible to check the email and initiate actions when email received?

For example, if a user has sends an email with the header like ‘ACTION: start downloading report’. Can a UiPath identify that an email has been received with this header and from this start an automated process?

Otherwise, it is possible to monitor a folder instead and when a text file (for example) is saved there to initiate an automated process?

Is there code examples for either?

Thanks


#2

Hi @selrac,

You can monitor events using the activity named Monitor Events. This activity has a trigger section in which you can drop the File change trigger to observe changes on files and folders.

In order to execute actions when receiving mail you’ll have to get the mails from your Outlook account for example and parse the subject of each mail to do a related action.

Hope it helps.

Regards,

Masire


#3

Thanks Masire. I’m going to try to see if I can put it goguether


#4

I have been playing with Outlook macros. I’m not great at VBA, but I managed to muddle through. I’m sure it’s worth having a look.


#5

Yes it is. Email is a great queuing system.

Just read the email folder in a loop having MarkAsRead and OnlyUnreadMessages checked.
You can use Top = 1 if you want to retrieve them one by one.

See bellow:

"


#6

hi badita… in this desicion box, whats the condition have to give? and have to assign the variable for this?


#7

hi can you share the screenshot of how to find the attachments in email automation.

Thank You


#8

mailMsgs.Count > 0

You should go through the data types and email video tutorials.


#9

sure thanks for sending the training materials.


#10

Dadita, on the flowchart you posted I see the ‘Wait 2 mins’ step. What activity is it ‘Wait attribute’ activity?


#11

hi @selrac

It is not wait attribute Activity, It’s a “Delay Activity”. He just changed the Displayname property to above text and Duration Property.

Regards…!!
Aksh


#12

I know this is slightly … counter-intuitive … to be writing this here … but I have been playing around with Outlook Macros … I feel they are a little over-looked.

The mailbox automation that I wrote used both UiPath and outlook macros.

Have a play … they are not that difficult.


#13

Can you please share the xaml and macros if possible? Thanks


#14

Private Sub Application_Startup()
Dim olApp As Outlook.Application
Dim objNS As Outlook.NameSpace
Dim olFolder As Outlook.MAPIFolder
Dim olASDAFolder As Outlook.MAPIFolder
Dim msg As Outlook.MailItem

Set olApp = Outlook.Application
Set objNS = olApp.GetNamespace(“MAPI”)
Set olFolder = objNS.GetDefaultFolder(olFolderInbox)
'Set olASDAFolder = olFolder.Folders(“ASDAsickness”)

'default local Inbox
’Set Items = objNS.GetDefaultFolder(olFolderInbox).Items
Set olASDAFolder = objNS.Folders(“Mailbox - Hugh Abbott”).Folders(“sickness”)
Set Items = olASDAFolder.Items

End Sub

Private Sub Items_ItemAdd(ByVal item As Object)

Dim strFileName As String
Dim i As Integer
Dim secStamp As Integer
Dim minStamp As Integer
Dim hrStamp As Integer
secStamp = Second(Now)
minStamp = Minute(Now)
hrStamp = Hour(Now)

'i = i + 1
’strFileName = "C:\Users\Hugh Abbott\Documents\UiPath\ASDAsickness01\mails\email.txt"
strFileName = “C:\Users\Hugh Abbott\Documents\UiPath\ASDAsickness01\mails\email” & secStamp & minStamp & hrStamp & “.txt”

On Error GoTo ErrorHandler

If TypeName(item) = “MailItem” Then
Set msg = item
’ ******************

'MsgBox "This is fun" & secStamp
'MsgBox "This is fun" & i

'MsgBox msg.Body
msg.SaveAs strFileName, olTXT

' ******************

End If
ProgramExit:
Exit Sub
ErrorHandler:
MsgBox Err.Number & " - " & Err.Description
Resume ProgramExit
End Sub


#15

I did this some time ago … just as a test. The basic idea is to write a text file every time an email reaches a certain folder … I’m not sure it even works :slight_smile: ? But the most important thing is for you to see that it is good old VB. so give it a go :slight_smile: !


#16

Hey! here is an example. in this example, if the mail contains attachment then they are saved in a particular folder otherwise bot replies to the sender saying you have forgotten to attach files in the sent mail.


#17

I did something similar and it works fairly well. The codes saves the contents of the email into a text file.

 Dim objItem As Object
 Dim myFolder As Folder
 If Not TypeName(myItem) = "Nothing" Then
    If LCase(myMail.Subject) = "SubjectKeyword" Then
        strname = myMail.Subject
        strdate = Format(myMail.ReceivedTime, "yymmddhhmmss")
        myMail.SaveAs "C:\EmailFiles\" & strdate & ".txt", olTXT
    End If
 End If

End Sub

I have then a process that picks up new files in the folder, reads the contents and acts upon the information received

There is a problem thought that the text is wrapped, so I had to find a way to merge the text


#18

thanks Selrac …that’s exactly what I was doing … I bet your code works better than mine :slight_smile: !

great share - thanks


#19

Does it maintain the formatting done inside the mail body?


#20

The formatting is lost in my case. Only the text is copied. This works for me as I need to capture the request type and the setting from the users that I use then for the robot in Uipath.

Maybe it is possible to capture the formatting if the email is saved in HTML instead of olTXT. I didn’t test it.