Couldn't send email via Send Exchange Message with attachment

I have encountered an error while sending an email via Send Exchange Mail Message.
This is the details of the error:

Message: The request failed. The operation has timed out

Exception Type: Microsoft.Exchange.WebServices.Data.ServiceRequestException

and this is the stack trace:

RemoteException wrapping Microsoft.Exchange.WebServices.Data.ServiceRequestException: The request failed. The operation has timed out  ---> RemoteException wrapping System.Net.WebException: The operation has timed out 
   at System.Net.HttpWebRequest.GetResponse()
   at Microsoft.Exchange.WebServices.Data.EwsHttpWebRequest.Microsoft.Exchange.WebServices.Data.IEwsHttpWebRequest.GetResponse() in \\REDMOND\EXCHANGE\BUILD\E15\15.00.0913.015\SOURCES\sources\dev\EwsManagedApi\src\EwsManagedApi\Core\EwsHttpWebRequest.cs:line 113
   at Microsoft.Exchange.WebServices.Data.ServiceRequestBase.GetEwsHttpWebResponse(IEwsHttpWebRequest request) in \\REDMOND\EXCHANGE\BUILD\E15\15.00.0913.015\SOURCES\sources\dev\EwsManagedApi\src\EwsManagedApi\Core\Requests\ServiceRequestBase.cs:line 821
	--- End of inner exception stack trace ---
   at Microsoft.Exchange.WebServices.Data.ServiceRequestBase.GetEwsHttpWebResponse(IEwsHttpWebRequest request) in \\REDMOND\EXCHANGE\BUILD\E15\15.00.0913.015\SOURCES\sources\dev\EwsManagedApi\src\EwsManagedApi\Core\Requests\ServiceRequestBase.cs:line 831
   at Microsoft.Exchange.WebServices.Data.ServiceRequestBase.ValidateAndEmitRequest(IEwsHttpWebRequest& request) in \\REDMOND\EXCHANGE\BUILD\E15\15.00.0913.015\SOURCES\sources\dev\EwsManagedApi\src\EwsManagedApi\Core\Requests\ServiceRequestBase.cs:line 724
   at Microsoft.Exchange.WebServices.Data.MultiResponseServiceRequest`1.Execute() in \\REDMOND\EXCHANGE\BUILD\E15\15.00.0913.015\SOURCES\sources\dev\EwsManagedApi\src\EwsManagedApi\Core\Requests\MultiResponseServiceRequest.cs:line 157
   at Microsoft.Exchange.WebServices.Data.ExchangeService.InternalCreateItems(IEnumerable`1 items, FolderId parentFolderId, Nullable`1 messageDisposition, Nullable`1 sendInvitationsMode, ServiceErrorHandling errorHandling) in \\REDMOND\EXCHANGE\BUILD\E15\15.00.0913.015\SOURCES\sources\dev\EwsManagedApi\src\EwsManagedApi\Core\ExchangeService.cs:line 401
   at Microsoft.Exchange.WebServices.Data.Item.InternalCreate(FolderId parentFolderId, Nullable`1 messageDisposition, Nullable`1 sendInvitationsMode) in \\REDMOND\EXCHANGE\BUILD\E15\15.00.0913.015\SOURCES\sources\dev\EwsManagedApi\src\EwsManagedApi\Core\ServiceObjects\Items\Item.cs:line 198
   at Microsoft.Exchange.WebServices.Data.EmailMessage.InternalSend(FolderId parentFolderId, MessageDisposition messageDisposition) in \\REDMOND\EXCHANGE\BUILD\E15\15.00.0913.015\SOURCES\sources\dev\EwsManagedApi\src\EwsManagedApi\Core\ServiceObjects\Items\EmailMessage.cs:line 110
   at UiPath.Mail.Exchange.EwsClient.ExchangeMailService.SendMail(ExchangeService service, MailMessage mailMessage, Receiver receiver, String name, String from, String user, List`1 attachments, Boolean SaveCopy, Boolean IsDraft, Boolean IsBodyHtml)
   at UiPath.Mail.Exchange.Activities.SendExchangeMail.<>c__DisplayClass59_0.<<GetAsyncWork>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
   at UiPath.Mail.Exchange.Activities.SendExchangeMail.<GetAsyncWork>d__59.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at UiPath.Mail.Exchange.Activities.ExchangeActivity`1.<ExecuteAsync>d__49.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at UiPath.Shared.Activities.AsyncTaskCodeActivityImplementation.EndExecute(AsyncCodeActivityContext context, IAsyncResult result)
   at UiPath.Shared.Activities.AsyncTaskCodeActivity.EndExecute(AsyncCodeActivityContext context, IAsyncResult result)
   at System.Activities.AsyncCodeActivity.System.Activities.IAsyncCodeActivity.FinishExecution(AsyncCodeActivityContext context, IAsyncResult result)
   at System.Activities.AsyncCodeActivity.CompleteAsyncCodeActivityData.CompleteAsyncCodeActivityWorkItem.Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at UiPath.Executor.BaseRunner.EndExecute(IAsyncResult result)
   at UiPath.Executor.InProcessRunner.EndExecute(IAsyncResult result)
   at UiPath.Core.Activities.ExecutorInvokeActivity.EndExecute(AsyncCodeActivityContext context, IAsyncResult result)
   at System.Activities.AsyncCodeActivity.System.Activities.IAsyncCodeActivity.FinishExecution(AsyncCodeActivityContext context, IAsyncResult result)
   at System.Activities.AsyncCodeActivity.CompleteAsyncCodeActivityData.CompleteAsyncCodeActivityWorkItem.Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)

I have managed to isolate the problem it seems to be occuring whenever I include an attachment.
I tried to send three emails via the said activity:

  1. With an attachment, where the attachment was included by way of mentioning the full path to the file in the Arguments in the
  2. With an attachment, where the attachment is mentioned in the Properties panel in the AttachmentsCollection field :slight_smile:

    The ExceptionsFileDirectory variable of String array typewas defined earlier in an Assign activity.
  3. Without an attachment. Other fields in the Properties panel(with the exception of the AttachmentCollection) were left the same as they were for cases 1) and 2).

I am only able to send the email successfully without the Attachment. But I need to send it with the attachment. When I do send together with the attachment I get the Exception :
Message: The request failed. The operation has timed out

Exception Type: Microsoft.Exchange.WebServices.Data.ServiceRequestException

The size of each of the attachments were around 816kb and there were 3 of them.
Kindly assist me. Thank you.

Hi @RobinsonFrancis ! :smile:
Could you check in your event viewer if there is any strange logs ? Just before looking at the logs, run the bot so it’s easier for you to track the data :wink:

I am sorry, I don’t how to do the steps you have just suggested. How do we use the “event viewer”?

Silly question: But have you tried to increase the timeout, for example TimeoutMS = 120000 ?

Hi @RobinsonFrancis !

To open an event viewer, click on your windows icon, and write eventvwr.msc


Then click on the windows application that I highlighted in red :wink:

With this, you will be able to see all the logs at your operating system level. Sometimes it shows us interesting logs (like security or network logs that do not appear in the software used - like UiPath).

Here is the way to navigate and understand the logs of the event viewer. You should focus on events that happen just before, during and after you run your bot so you see if something is blocking your mail with attachments ^^

I just think of something else, maybe you could try to see if your antivirus or firewall blocked the uipath smtp request. To verify it, you can stop temporiraly the antivirus and the firewall, and run your bot. If there is no error thrown, then it might be a problem of AV or firewall :wink: