Shared Mail Inbox Outlook

GatesV

Member
Good day BP Gurus,

I am also facing a similar issue, where after modifying the code of the Internal_Get Items code to handle shared mailboxes, I am able to read emails from the shared mailbox Inbox folder, but unable to read from a sub folder within that Inbox.

Was anybody able to solve that issue so we can read from shared mailboxes sub folder?

Thanks in advance for your help!
 

jonnymop5

Member
I can move from subfolders now. I haven't yet tried to read from subfolders. I will try it in the next couple of days and get back to you.
 

GatesV

Member
I can move from subfolders now. I haven't yet tried to read from subfolders. I will try it in the next couple of days and get back to you.

Thank you. I appreciate any help you can offer. I also need to move from shared mailbox folder to another. I'll look into that tomorrow (Tuesday), but I might need some insight.
 

jonnymop5

Member
Hi GatesV,
I can read from shared boxes and move to subfolders (then move again to other subfolders).

Shoot me exactly what you are looking for and I will help you out.

Thanks,
Jon
 

GatesV

Member
Hi @jonnymop5 !

What I need to do is:

1- Read email from a subfolder of a shared mailbox.
2- Move email from a subfolder of a shared mailbox to another subfolder of that same mailbox.
3- Save mail attachments from an email located in a subfolder of a shared mailbox.

I've been successful in reading mail from the Inbox folder of a shared mailbox, but that's not what I need to do and I haven't been able to mingle with the code to achieve the above requirements.
Code:
' Commented out for the use of shared mailboxes.
'Dim folder = _nameSpace.GetDefaultFolder(Outlook_Folder_ID)

'    Use this code instead when dealing with shared mailboxes.
Dim FMMail = Mailbox_Name
Dim vRecipient = _nameSpace.CreateRecipient(FMMail)
Dim folder = _nameSpace.GetSharedDefaultFolder(vRecipient, Outlook_Folder_ID)

Thanks a lot for your help!
 
Last edited:

GatesV

Member
I'm sorry, now it seems to be working. I'm not really sure what changed :) Thanks anyway

Yesterday, I tried reading mail from an Inbox subfolder of a shared mailbox after implementing the code above. I couldn't get it to work. I was also getting an error stating: "Could not execute code stage because exception thrown by code stage: The attempted operation failed. An object could not be found."

Today, I'm not trying the code again cause I know it didn't work the previous day. So I have a look at this post again, wondering if I missed something. I then notice @drubiano has brought a slight modification to the code. So I figure it wouldn't hurt to try this out, even though I had a feeling it did pretty much the exact same thing. It worked! I was able to read from an Inbox subfolder of a shared mailbox.

I'm really happy, thinking @drubiano's code is what made it work. So I then proceed with making modifications to other code has I now need to move mail from a shared mailbox Inbox subfolder to another subfolder in that same shared mailbox. To test it out, I create a new subfolder and proceed with it. I run the code again to read the mail, and it no longer works, while it worked a minute ago!

I notice @drubiano above mentioned the code wasn't working for him and then suddenly, it started working and he didn't know what he changed. That lead me to wonder... Is it possible that the Microsoft Exchange Server takes time to react to subfolder structure modifications brought to a shared mailbox and that these modifications have an impact, preventing the code from being able to find these subfolders until the server refreshes?

You bet it does! If you have Cached Exchange Mode turned on in your Outlook settings, you'll have issues with your code every time your folder structure changes, until your cache is refreshed. Turn off the Cached Exchange Mode and you'll be fine.

This is where you'll find out how to modify this setting. Of course, you need to turn it OFF, not ON like this link is telling you.

https://support.office.com/en-us/ar...nge-mode-7885af08-9a60-4ec3-850a-e221c1ed0c1c
 
Last edited:

GatesV

Member
Hi @jonnymop5 !

What I need to do is:

1- Read email from a subfolder of a shared mailbox.
2- Move email from a subfolder of a shared mailbox to another subfolder of that same mailbox.
3- Save mail attachments from an email located in a subfolder of a shared mailbox.

I've been successful in reading mail from the Inbox folder of a shared mailbox, but that's not what I need to do and I haven't been able to mingle with the code to achieve the above requirements.
Code:
' Commented out for the use of shared mailboxes.
'Dim folder = _nameSpace.GetDefaultFolder(Outlook_Folder_ID)

'    Use this code instead when dealing with shared mailboxes.
Dim FMMail = Mailbox_Name
Dim vRecipient = _nameSpace.CreateRecipient(FMMail)
Dim folder = _nameSpace.GetSharedDefaultFolder(vRecipient, Outlook_Folder_ID)

Thanks a lot for your help!
I'm all good now @jonnymop5 ! Thanks for your offer to help.
 

GatesV

Member
Hey,

I've set the bot to read/move from the shared mailbox, and all is working well. Im looking to get the bot to 'Get Sent Mail' as well as 'Send Mail' from the shared mailbox, but getting "Value does not fall within the expected range." each time.

Any ideas on how to correct this?

Thanks for the help

Hi @sck360

Were you able to get the Send Mail to work from a shared mailbox? I'm looking to do the same but I'm unsure how to address this. Thanks for getting back to us and let us know if you're up and running doing this.
 

GatesV

Member
Hi @sck360

Were you able to get the Send Mail to work from a shared mailbox? I'm looking to do the same but I'm unsure how to address this. Thanks for getting back to us and let us know if you're up and running doing this.
That's the way to do it...

Code:
If SendFrom <> Nothing
    mail.SentOnBehalfOfName = SendFrom
End if

SendFrom is to be an optional input to the Send Email action. You need to include the email address of the shared mailbox.
 

Jatin Kalra

New Member
Hey,

I've set the bot to read/move from the shared mailbox, and all is working well. Im looking to get the bot to 'Get Sent Mail' as well as 'Send Mail' from the shared mailbox, but getting "Value does not fall within the expected range." each time.

Any ideas on how to correct this?

Thanks for the help
Hi ,

Tried same thing to get email from Sent Item folder from Shared Mail box.
But getting error "Value does not fall within the expected range." each time.
But same code working fine when tried to get email from Shared mail box Inbox folder.

Thanks in advance. Please provide expertise.
 

jonnymop5

Member
Gates,
I tried to put your code in and I it is not working. I tried the below (which I thought was the combo of what you were sending. Anyone know what I'm doing wrong.

View attachment 1582813972004.png


That's the way to do it...

Code:
If SendFrom <> Nothing
    mail.SentOnBehalfOfName = SendFrom
End if

SendFrom is to be an optional input to the Send Email action. You need to include the email address of the shared mailbox.
 

GatesV

Member
Gates,
I tried to put your code in and I it is not working. I tried the below (which I thought was the combo of what you were sending. Anyone know what I'm doing wrong.

View attachment 5244

@jonnymop5

Sorry for taking that long to get back to you. I've been swamped lately.

The IsNot operator determines if two object references refer to different objects. However, it does not perform value comparisons.

Try it the way I've put it, using the <> symbol.

Let me know if it works out.
 

GatesV

Member
@jonnymop5

They say an image is worth a thousand words. So here are the screenshots and the full code that enables to send an email from a shared mailbox. I've also added a little bonus for adding a priority level to the email, which isn't part of the original Blue Prism code.
Code:
Dim app = CreateObject("Outlook.Application")
Dim mail = app.CreateItem(0)
Dim addressCount As Integer

If [To] <> "" Then
    Dim toAddresses = Split([To], ";")
    For addressCount = LBound(toAddresses) To UBound(toAddresses)
    Dim recipient = mail.Recipients.Add(toAddresses(addressCount))
    recipient.Resolve
    If recipient.Resolved Then recipient.Type = OlMailRecipientType.olTo
    Next
End if

If CC <> "" Then
    Dim ccAddresses = Split([CC], ";")
    addressCount = 0
    For addressCount = LBound(ccAddresses) To UBound(ccAddresses)
    Dim recipient = mail.Recipients.Add(ccAddresses(addressCount))
    recipient.Resolve
    If recipient.Resolved Then recipient.Type = OlMailRecipientType.olCC
    Next
End If

If BCC <> "" Then
    Dim bccAddresses = Split([BCC], ";")
    addressCount = 0
    For addressCount = LBound(bccAddresses) To UBound(bccAddresses)
    Dim recipient = mail.Recipients.Add(bccAddresses(addressCount))
    recipient.Resolve
    If recipient.Resolved Then recipient.Type = OlMailRecipientType.olBCC
    Next
End If

mail.Subject = Subject
mail.HTMLBody = Message

If On_Behalf_Of <> Nothing
    mail.SentOnBehalfOfName = On_Behalf_Of
End if

Select Case Priority_Level
    Case 0
        mail.Importance = 0
    Case 2
        mail.Importance = 2
    Case Else
        mail.Importance = 1
End Select

For Each att As String In Attachments.Split(";"c)
    If att = "" Then Continue For
    mail.Attachments.Add(att)
Next

mail.Save
mail.Send
 

Attachments

  • 1.jpg
    122.4 KB · Views: 34
  • 2.jpg
    187 KB · Views: 30
  • 3.jpg
    114.6 KB · Views: 34
  • 4.jpg
    248.4 KB · Views: 30

GatesV

Member
Have you included the input parameter in the Send Email code stage like you see in the 3rd and 4th screenshots?
 

jonnymop5

Member
Hi GatesV,
I just wanted to follow-up that I got the the shared email working. I had missed a start parameter. Those screenshots were great. Thanks!
 

Jatin Kalra

New Member
Hi there, anyone knows how you forward an email with specific profile(email account) from the shared mailbox?

Start Stage : Add Start up Parameter : [From]

Code Stage :
Inputs : From Type [From]

Add in Code Section:
If [From] <> "" Then
mail.SentOnBehalfOfName = From
end if
 
Top