Unable to send embedded image in outlook

Hi All, I’m trying to send image in email body and for that I have tried to embed the image in html. It is working fine in my outlook account but if I try the same code in other outlook, it is not working and I’m getting Outlook Times out error. Any idea why it could be?

Hi @anjana1

Is it that you are using in another system outlook? or same system different outlook account?

Also please share the screenshot to understand the issue

Thanks,
Srini

yes I have different BOT laptop and i have different outlook account

error

imgpath = “C:\5de180f954fec4d3a4bdfad2a1485457.jpg”
byteArray = System.Io.File.ReadAllBytes(imgPath)
base64String = Convert.ToBase64String(byteArray)
html = “<img src=”“data:image/jpg;base64,base64StringVariable”“>”
html = html.Replace(“base64StringVariable”, base64String)
mailbody = “

Hello,

This is an email from abc

Regards,
abc
EmbeddedImage


mailbody = mailBody.Replace(“EmbeddedImage”,html)

Atlast
outlook activity

Your code is correct , but there’s a small issue in the way you’re replacing the base64StringVariable placeholder in the HTML. Here’s the corrected code:

imgPath = "C:\5de180f954fec4d3a4bdfad2a1485457.jpg"
byteArray = System.IO.File.ReadAllBytes(imgPath)
base64String = Convert.ToBase64String(byteArray)
html = "<img src=""data:image/jpg;base64," & base64String & """>"
mailBody = "Hello,

This is an email from abc

Regards,
abc
" & html

' Now, you can use the "mailBody" variable in your Outlook activity to send the email.

This code will correctly embed the image as a base64 encoded image in the email’s HTML body, and you can use the mailBody variable in your Outlook activity to send the email. Make sure to replace the Outlook activity comment with the actual activity that sends the email using Outlook.

@anjana1

Hi Praveen,

Thanks a lot for the reply. Still it is not working in my BOT laptop.

Not sure what is the issue. I have used the code which you have sent and this code works in my laptop and my outlook account.

This is the below exception Im getting it.

23.4.5+Branch.support-v23.4.Sha.8424249464a6161e3f015a227611467e546fbdb0

Source: Send Outlook Mail Message

Message: The operation has timed out.

Exception Type: System.TimeoutException

System.TimeoutException: The operation has timed out. at UiPath.Mail.Activities.Extensions.TaskExtensions.TimeoutAfter(Task task, Int32 timeoutMs)
at UiPath.Mail.Activities.SendMailActivity.ExecuteAsync(AsyncCodeActivityContext context, CancellationToken cancellationToken)
at UiPath.Shared.Activities.AsyncTaskCodeActivityImplementation.EndExecute(AsyncCodeActivityContext context, IAsyncResult result)
at UiPath.Shared.Activities.AsyncTaskCodeActivity.EndExecute(AsyncCodeActivityContext context, IAsyncResult result)
at UiPath.Shared.Activities.ContinuableAsyncCodeActivity.EndExecute(AsyncCodeActivityContext context, IAsyncResult result)
at UiPath.Mail.Activities.BaseMailContinuableAsyncActivity.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)

If the code is working on your laptop and with your Outlook account but not on your BOT laptop, there might be a few factors to consider:

1.Permission and Configuration on BOT Laptop: Ensure that your BOT laptop has the necessary permissions and configurations to access and send emails via Outlook. Check if there are any security policies or restrictions that may be causing issues.

2.Outlook Version: Verify that both laptops are using the same version of Outlook or are compatible with the method you are using for sending emails. Different Outlook versions may have variations in behavior and capabilities.

3.Firewall: firewalls may block or restrict certain actions, such as sending emails from applications. Check if any security software is blocking the email sending process.

4.Bot Environment: Ensure that the UiPath runtime environment on your BOT laptop is set up correctly, with the required dependencies installed and configured.

@anjana1

I can see that the BOT is able to send & receive emails using outlook. However if I change the email body as Embedded content, BOT is unable to send.

Hi @anjana1

Try with Create HTML Content activity in that you can give the image path

image

Can you check the content

imgPath = "C:\5de180f954fec4d3a4bdfad2a1485457.jpg"
byteArray = System.IO.File.ReadAllBytes(imgPath)
base64String = Convert.ToBase64String(byteArray)
html = "<img src=""data:image/jpg;base64," & base64String & """>"

mailBody = "Hello, <br><br>" & _
           "This is an email from abc <br><br>" & _
           "Regards, <br>" & _
           "abc <br><br>" & _
           html  ' Include the embedded image in the email body

' You can now use mailBody as the HTML body of your email

' Use the Outlook activity to send the email

@anjana1

Hi all, i have tried everything but still i’m facing the same issue. So i have asked my IT team to reinstall the outlook fully. I hope this will help. Thanks everyone

yeah sure and also check this point

Permission and Configuration on BOT Laptop: Ensure that your BOT laptop has the necessary permissions and configurations to access and send emails via Outlook. Check if there are any security policies or restrictions that may be causing issues

@anjana1

Hello Praveen,

Yes BOT is able to send normal email without Base64 string logic. But if I add this logic, BOT is facing timed out issue. I have reinstalled microsoft 365 too but still same issue.

I haven’t find any solution for this however UiPath suggested to paste the image in word and attach the word in email body and that works. So closing the case.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.