Attended - Display a drafted email

Hello,

Just looking to draft an email from template, add attachments and display to user

I used “Send Outlook Mail Message” activity … body from template as well as adding attachments was easy

however, after message is saved in drafts folder (used “is draft” option) and not displayed for user

I tried searching, but seems as most automations are for unattended processes and without using “invoke code” this doesn’t appear to be a feature of any of the activities

so question, is there a way to display drafted email I just created and have customer add an additional details before sending (without using unofficial libraries) ?

Hi @Zoran1983

In UiPath, the standard activities for sending emails are primarily designed for unattended automation processes and often don’t provide a direct method for displaying a drafted email to the user with the ability to add additional details before sending

you can follow this steps

  1. Use Outlook Interaction: Instead of using the “Send Outlook Mail Message” activity, which is designed for automated sending, you can use Outlook interaction activities to create and display the email draft to the user.
    2.Create Email Draft: Use Outlook interaction activities to create a new email draft, set the subject, recipient, body, and attachments as needed. You can use the “Outlook” activities package in UiPath, which provides a range of activities for interacting with Outlook.
  2. Display the Draft: After creating the draft, use an activity to display it in the user’s Outlook email client. This can be achieved using the “Send Outlook Mail Message” activity if your use case allows for this interaction with the user. Set the “IsDraft” option to true.
    4.User Interaction: The user will be able to view the drafted email in their Outlook client, add additional details, make edits, and send the email manually.

Hi @Zoran1983

In UiPath, you can create a draft email from a template, add attachments, and then display it to the user for further editing before sending it. You don’t necessarily need to use unofficial libraries or invoke code activities for this task. You can achieve this using the built-in “Send Outlook Mail Message” activity along with a few additional steps. Here’s a step-by-step guide:

  1. Send Outlook Mail Message (Compose the email and set IsDraft = True)
  2. Get Outlook Mail Messages (Retrieve the draft email)
  3. Display email to the user for editing (e.g., using an Input Dialog)
  4. User makes changes if necessary
  5. Send Outlook Mail Message (Send the updated email)

@Zoran1983

ideally you should be able to see it…can you check if there are multiple accounts may be the draft is saved in different account

or try to use get outlook mail messages on drafts folder and check if you are able to get the draft email…

Or alternately you can sue a UiPath form to diplay the body and user edits it in form and you can save it back and then send automatically

cheers

I can not find “outlook interaction” activities, can you point me to this package?

@vinitha_yachamaneni

Display email to the user for editing (e.g., using an Input Dialog)
User makes changes if necessary
Send Outlook Mail Message (Send the updated email)

not sure how I feel about this … this just confuses user, they use outlook every day so email sitting waiting to be sent is nothing new… bunch of prompts asking questions … don’t really find that useful

@Anil_G

Or alternately you can sue a UiPath form to diplay the body and user edits it in form and you can save it back and then send automatically

again, it goes back to user experience… They use outlook every day, some form will just confuse them

UiPath Dev Team
quick google search and Powershell can do this in 7 lines of code

$ol = New-Object -comObject Outlook.Application
$mail = $ol.CreateItem(0)
$mail.Subject = "<subject>"
$mail.Body = "<body>"
$mail.save()
$inspector = $mail.GetInspector
$inspector.Display()

.Display() is really what’s missing in “Send Outlook Mail Message” activity

it’s crazy that I have to go through this much trouble just to display a message from draft

1 Like

Have you tried using UI automation to go into Outlook, find the email, and double-click it?

With attended, that would be very risky, I think I’ll go with the code route

not much to this really

Dim mail As Microsoft.Office.Interop.Outlook.MailItem
code for attachments, subject, etc

than to dislay

mail.Display

just mad at UiPath Dev team really… this is the first time that I’m doing attended
I was 100% sure this is some checkmark on some outlook activity that I am missing

Let me know if you actually get that to work. It throws an exception for me. I don’t think you can use code within an Invoke Code to get the email to open from Outlook.

something like this should do

Dim outlook As Microsoft.Office.Interop.Outlook.Application = New Microsoft.Office.Interop.Outlook.Application()
Dim ns As Microsoft.Office.Interop.Outlook.NameSpace = outlook.GetNamespace("MAPI")
Dim mailItem As Microsoft.Office.Interop.Outlook.MailItem = DirectCast(outlook.CreateItem(OlItemType.olMailItem), Microsoft.Office.Interop.Outlook.MailItem)


mailItem.Subject = "Test"


mailItem.Recipients.Add("test@test.com")
mailItem.Recipients.ResolveAll()


mailItem.Display(mailItem)
mailItem.HTMLBody = "test"


Marshal.ReleaseComObject(mailItem)
Marshal.ReleaseComObject(ns)
Marshal.ReleaseComObject(outlook)
GC.Collect()
GC.WaitForPendingFinalizers()

@uipath can we have enhancement to one of the Outlook packages

if “is draft” is selected add “is visible” or something

1 Like

Did you get this to work for you?

yea, with powershell

function Out-Default {}
$randomstr = -join ((65..90) + (97..122) | Get-Random -Count 8 | % {[char]$_})
$outlook = New-Object -comObject Outlook.Application 
$message = $outlook.CreateItem(0) 
$message.Subject = "Subject" 
$message.SentOnBehalfOfName = "email@email.com" 
$message.HTMLBody = "HTML Body"

$path    = "c:\temp\$randomstr"
$lastest = Get-ChildItem -Path $path 
foreach ($file in $lastest)
{
    $message.Attachments.Add($file.FullName)
}

$message.Display()
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($outlook) | Out-Default