How to throw an exception and send email as alert


#1

Hello

I want to know how to send an email as notification/alerts in UiPath after successful Job or Exceptions?

thanks in advance
Ayyoub


#2
  1. Once your seq is completed you can add the send mail activity. That way once its successfully completed it will send the mail.
  2. In case of error/exception, when u use try-catch block, use a throw activity and then in catch you can use the send mail activity.

A good sample is the REFramework, which uses state machines and has all this logic.


#3

Hi Nadim

1- the send email activity I have to set it? I mean there is no activity related to Alerts or something like that?
2- You mean in Catch I will have a sequence (1-throw 2-send email)?

thanks in advance


#4

Hi,

1- the send email activity I have to set it? I mean there is no activity related to Alerts or something like that?

There are different types of email activities are already available in the UiPath. As per Your requirement you have to use it. For example

if you are planning to send an email from outlook you have to use send outlook mail message activity.

If you are planning to send an email from gmail or yahoo or any other, you have to use SMTP mail message activity.

Note: Also You can send email in outlook via SMTP as well but you need to have the server and port id but if you use the outlook then there is no need of server and port id.The only thing is outlook should be opened during this case.

For more info refer the below link:

2- You mean in Catch I will have a sequence (1-throw 2-send email)?

Yes , He is just giving an example to you. If anything fails in try then it will come to the catch block. Make a code in try block that creates an exception so that it will go to catch block and use send mail activity in catch block.


#5

Hi

Let’s say that the Try Block failed, and in Catch I have the following Sequence:
1- Throw Exception for example new BusinessRuleException(“please review this process”)
2- send email (with outlook activity)

My questions are:
1- will the email activity be executed even when it is after (Throw Exception)?
2- How can I write in the email the thrown exception message?

thanks in advance


#6

@nadim.warsi
@sravan_kumar1
Could you please tell me, where I can use send email activity if I’m using the REFramework?
in my case: I can’t retry the items, doest it mean that I have always throw exceptions of type (BusinesRuleException) in my “Process” block.
and this Exception will be catched in the Catch block of the Process
and after this catch I should add the send email right?


#7

Let me help you with more understanding of the REFamework or how state machines work.
You catch and exception, great, but below that you need to let the state know wht is the next transition that need to happen.

Like if BusinessRule Exception isNot Nothing, transition to this state machine ->a
or if Exception, isNot Nothing, transition to another state machine -> b
if success, transition to success state machine -> c

image

There you can keep the machine same or different, depends on your requirement and also pass arguments.
These arguments can be same or different.

Like in all 3 states i call sendEmail machine, and in my process.xaml i and setting a out_argument to the value i want to send in the email body.
a. BusinessRule - i use the exception message/or my custom message
b. Success - i use a custom message.

So in the SendEmail, i get one in_argument and i send the email, so in case of error or success sendMail works.

Helpful?


#8

@nadim.warsi
Thank you so much for your time and help.
You mean here I can place the send email workflow which takes in-Argument?

I wanted to know something regarding the catch Exceptions,
How the robot will know the type of exceptions? ir order to assign the Exception to (Business) or (SystemError)?
because in my case, the Robot shouldn’t retry the item, if it fails I want it to send email and mark the Item as failed. Should I alway throw BusinessExceptions in this case?


#9

you can add the send mail message activity inside the catch block itself.

If you add send mail message activity inside the businesses exception, then email will trigger if there is any business rule exception occurs.

If you add send mail message activity inside the exception, then email will trigger if there is any exception occurs.

Based on the type of exception message ,all the activities inside that exception will execute.(You can execute multiple activities inside every exception.)

thanks


#10

i want to log the exception occured in sql database.How can it be done?

regards