Send Outlook email, one account but additional mailboxes


#1

Hello everyone, it’s my first post so I hope I won’t mess it up
I’m trying to send an email from Outlook with a non default account, I thought I found a solution there : Send Outlook email from a non-default account
but it turns out there is only one account on my Outlook and the “account” I want to send the emails from is in fact an “additional mailbox”. When I try to send the email with the email address of this “additional mailbox” as Account in the “Send Outlook mail message” activity, it returns me the error saying that this account does not exists. I know I can send emails from this “additional mailbox” as I did it both manually and using VBA (with the email address directly in the “.SentOnBehalfOfName” property of the email object. My question is : did anybody encounter this situation and found ways to solve it ? I’d rather not execute a macro to send the email as everything (recipient, subject, content of email, attachment etc) is already in my workflow…


Import ms outlook object library in invoke code
#2

Hi @neo_phil,
I tried the same thing in my system and it worked well,
I have two accounts which are added to my outlook, 1 is default and other is not.
I tried invoking “Send Outlook Mail Message” activity with my non-default outlook account and it worked .

So please check if the outlook account is setup in the outlook client.

Thanks,


#3

Hi @anjalimishra,

Thank you for your answer,
When you say you “” tried invoking “Send Outlook Mail Message” activity with my non-default outlook “” you mean you used the email address of the non default account as the “Account” parameter of the activity ? Or did you use something else (name of the account or so), I’m only asking because I already tried with the name and the address of the additional account and it failed in the same way (Account not found).

Also I have to precise that when I go in Outlook into > File > Account settings > Account settings
I only see my default account, but In the Mail panel of Outlook I can see both my own account and the other account and I can send email from both accounts…

Thanks,


#4

“” tried invoking “Send Outlook Mail Message” activity with my non-default outlook “” you mean you used the email address of the non default account as the “Account” parameter of the activity – Yes

I tried sending an email from the second account which is not default (highlighted in RED)


#5

I see,

Like said I only have one account in the settings :


But I still can see my default account and the “additional inbox” in my Outlook mail pane, I can see all the emails that goes in and I can send emails from it.
I’m affraid there is no way to do what I want without adding the second mailbox as a second account (which I’m not allowed to do for security reasons)…

The part that bugs me is that I can send an email from it using VBA so there is a way to retrieve it but this may have not yet been integrated in UiPath.

Thanks


#6

Hey… did you get a solution to this? If not will it be possible for you to share the macro(VBA) for sending email?


#7

Hey ! I ended up making it with an Excel and VBA, I put my input data (TO, CC, BCC, email account, Subject, content of the email and full path to the file I want to attach) in a DT, save it in my Excel and execute the macro from UiPath


#8

now if I could figure out how to upload the excel here…


#9

There is an ‘upload’ button. Could you please follow that and send?


#10

Thanks, but turns out you can’t upload excel files with VBA (xlsm extension) only without code (xlsx), I’ll upload the excel without the code so you can understand where I take my data from and here is the code :

Option Explicit

Sub send_email()

'XXXXXXXXXXXXXXXXXXXX - Workbook - XXXXXXXXXXXXXXXXXXXX             XXXXXXXXXXXXXXXXXXXXX - Usage - XXXXXXXXXXXXXXXXXXXXXXX
Dim wb_proj As Workbook
'------------------------------------------------------             -------------------------------------------------------

'XXXXXXXXXXXXXXXXXXX - Worksheet - XXXXXXXXXXXXXXXXXXXX             XXXXXXXXXXXXXXXXXXXXX - Usage - XXXXXXXXXXXXXXXXXXXXXXX
'------------------------------------------------------             -------------------------------------------------------

'XXXXXXXXXXXXXXXXXXXXXX - Byte - XXXXXXXXXXXXXXXXXXXXXX             XXXXXXXXXXXXXXXXXXXXX - Usage - XXXXXXXXXXXXXXXXXXXXXXX
Dim col_ref As Byte
Dim row_ref As Byte
'------------------------------------------------------             -------------------------------------------------------

'XXXXXXXXXXXXXXXXXXXXXX - Loop - XXXXXXXXXXXXXXXXXXXXXX             XXXXXXXXXXXXXXXXXXXXX - Usage - XXXXXXXXXXXXXXXXXXXXXXX
'------------------------------------------------------             -------------------------------------------------------

'XXXXXXXXXXXXXXXXXX - Other Longs - XXXXXXXXXXXXXXXXXXX             XXXXXXXXXXXXXXXXXXXXX - Usage - XXXXXXXXXXXXXXXXXXXXXXX
'------------------------------------------------------             -------------------------------------------------------

'XXXXXXXXXXXXXXXXXXXX - Doubles - XXXXXXXXXXXXXXXXXXXXX             XXXXXXXXXXXXXXXXXXXXX - Usage - XXXXXXXXXXXXXXXXXXXXXXX
'------------------------------------------------------             -------------------------------------------------------

'XXXXXXXXXXXXXXXXXXXX - Integer - XXXXXXXXXXXXXXXXXXXXX             XXXXXXXXXXXXXXXXXXXXX - Usage - XXXXXXXXXXXXXXXXXXXXXXX

'------------------------------------------------------             -------------------------------------------------------

'XXXXXXXXXXXXXXXXXXXXX - String - XXXXXXXXXXXXXXXXXXXXX             XXXXXXXXXXXXXXXXXXXXX - Usage - XXXXXXXXXXXXXXXXXXXXXXX
Dim StrSendTo As String
Dim StrSendCc As String
Dim StrSendBcc As String
Dim StrAccountSend As String
Dim StrContent As String
Dim StrSubject As String
Dim StrJoinPath As String
'------------------------------------------------------             -------------------------------------------------------

'XXXXXXXXXXXXXXXXXXXXX - Array - XXXXXXXXXXXXXXXXXXXXXX             XXXXXXXXXXXXXXXXXXXXX - Usage - XXXXXXXXXXXXXXXXXXXXXXX
'------------------------------------------------------             -------------------------------------------------------

'XXXXXXXXXXXXXXXXXXXXX - Range - XXXXXXXXXXXXXXXXXXXXXX             XXXXXXXXXXXXXXXXXXXXX - Usage - XXXXXXXXXXXXXXXXXXXXXXX
'------------------------------------------------------             -------------------------------------------------------

'XXXXXXXXXXXXXXXXXXXX - Objects - XXXXXXXXXXXXXXXXXXXXX             XXXXXXXXXXXXXXXXXXXXX - Usage - XXXXXXXXXXXXXXXXXXXXXXX
'------------------------------------------------------             -------------------------------------------------------

'XXXXXXXXXXXXXXXXX - Outlook Folder - XXXXXXXXXXXXXXXXX             XXXXXXXXXXXXXXXXXXXXX - Usage - XXXXXXXXXXXXXXXXXXXXXXX
'------------------------------------------------------             -------------------------------------------------------

'XXXXXXXXXXXXXXXXXXXXXX - Date - XXXXXXXXXXXXXXXXXXXXXX             XXXXXXXXXXXXXXXXXXXXX - Usage - XXXXXXXXXXXXXXXXXXXXXXX
'------------------------------------------------------             -------------------------------------------------------

'XXXXXXXXXXXXXXXXXXXXX - Others - XXXXXXXXXXXXXXXXXXXXX             XXXXXXXXXXXXXXXXXXXXX - Usage - XXXXXXXXXXXXXXXXXXXXXXX
Dim olApp As Outlook.Application
Dim objNS As Outlook.Namespace
Dim objMail As Outlook.MailItem
Dim objSentItems As Outlook.MAPIFolder
Dim myInspector As Outlook.Inspector
'------------------------------------------------------             -------------------------------------------------------

'XXXXXXXXXXXXXXXXXXX - Booleans - XXXXXXXXXXXXXXXXXXXXX             XXXXXXXXXXXXXXXXXXXXX - Usage - XXXXXXXXXXXXXXXXXXXXXXX
'------------------------------------------------------             -------------------------------------------------------

'XXXXXXXXXXXXXXXXXXX - Constants - XXXXXXXXXXXXXXXXXXXX             XXXXXXXXXXXXXXXXXXXXX - Usage - XXXXXXXXXXXXXXXXXXXXXXX
'------------------------------------------------------             -------------------------------------------------------

'--------------------------------------------------------------------------------------------------------------------------
'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Code XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
'--------------------------------------------------------------------------------------------------------------------------


'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Excel initiation XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

'--- Disable screeen updating to prevent display errors and gain execution time -------------------------------------------
Application.ScreenUpdating = False

'--- Define the WB and SH as objects --------------------------------------------------------------------------------------
Set wb_proj = ThisWorkbook

'XXX--- Get the parameters ---XXX
'--- Get the number of lists
With wb_proj.Sheets("data")
    '--- Parameters
    col_ref = 2
    '--- To
    row_ref = 2
    StrSendTo = .Cells(row_ref, col_ref).Value
    '--- Cc
    row_ref = 3
    StrSendCc = .Cells(row_ref, col_ref).Value
    '--- Bcc
    row_ref = 4
    StrSendBcc = .Cells(row_ref, col_ref).Value
    '--- Account
    row_ref = 5
    StrAccountSend = .Cells(row_ref, col_ref).Value
    '--- Subject
    row_ref = 6
    StrSubject = .Cells(row_ref, col_ref).Value
    '--- Content
    row_ref = 7
    StrContent = .Cells(row_ref, col_ref).Value
    '--- Link to PDF
    row_ref = 8
    StrJoinPath = .Cells(row_ref, col_ref).Value
End With

'--- Check whether outlook is open, if it is use get object, if not use create object
On Error Resume Next
Set olApp = GetObject(, "Outlook.Application")
On Error GoTo 0
If olApp Is Nothing Then
    Set olApp = CreateObject("Outlook.Application")
End If

Set objNS = olApp.GetNamespace("MAPI")
objNS.Logon "Outlook", , False

'--- Prepare the mail object
Set objMail = olApp.CreateItem(olMailItem)

With objMail
    '--- Send using SP mailbox
    .SentOnBehalfOfName = StrAccountSend
    '--- TO
    .To = StrSendTo
    '--- BCC
    If StrSendBcc <> "" Then
        .BCC = StrSendBcc
    End If
    '--- CC
    If StrSendCc <> "" Then
        .CC = StrSendCc
    End If
    '--- Resolve all
    .Recipients.ResolveAll
    '--- Set subject
    .Subject = StrSubject
    '--- Copy the Excel data in the email
    '.HTMLBody = StrContent
    .Body = StrContent
    '--- File to join
    .Attachments.Add (StrJoinPath)
    '--- Send the email
    .Send
End With

End Subsend_email_tool_V1.00.xlsx (9.8 KB)


#11

You have to activate the reference to Outlook Library in your Excel file for it to work properly with the elements of code, also the code will send directly the email, if you don’t wanna do that, deactivate the “.send” and replace it with a “.display” to display the email.

BR


#12

Thanks a lot! will try


#13

You’re welcome :slight_smile:


#14

It worked flawlessly… Thank you! :slight_smile:


#15

You’re welcome, glad it was usefull to someone else :slight_smile: