cancel
Showing results for 
Search instead for 
Did you mean: 

MS Outlook VBO

DeclanKeeton
Level 3
​Hi,

I am looking to use the Outlook VBO to send emails as I need to use HTML enabled for the formatting.

I need to be able to send from a shared mailbox.

Does anybody have the code required to either amend the 'Send Email' action
or create a 'Send Email From' action.

(I can not use the POP3/SMTP object)

------------------------------
Declan Keeton
RPA Developer
E.ON
------------------------------
7 REPLIES 7

AmiBarrett
Level 12

Edit: Redoing this post, because I initially misread the query. (Thank you BP, for finally allowing edits!)

Just before the mail.save and mail.send lines, add this:

Inputs:

[SendFrom] - Text

Code:

if SendFrom <> Nothing
	mail.SentOnBehalfOfName = SendFrom
end if​

​Hi Ami,

Thanks to the forums for the edits as much happier with the edited than the original reply!

This worked perfectly and was quick to implement.

Thanks mate!



------------------------------
Declan Keeton
RPA Developer
E.ON
------------------------------

Hello Ami

I saw, that you support Declan by an issue with Outlook and Sent E-Mails on Behalf. I have the problem, that I cant sent E-Mails on behalf with this code from a shared mailbox. Maybe you can give me an hint, what I am doing wrongly​? Secondly, I am also not got the output that thee E-Mail was sent.

Dim oApp As Microsoft.Office.Interop.Outlook._Application
oApp = New Microsoft.Office.Interop.Outlook.Application
Dim myItem As Microsoft.Office.Interop.Outlook.MailItem

try
 myItem = oApp.CreateItemFromTemplate(templatePath)
myItem.From = FromAddress
 myItem.To = mailAddress
 myItem.Subject = myItem.Subject _
     .Replace("<Name>", firstName) _
     .Replace("<Surname>", lastName)
 myItem.HTMLBody = myItem.HTMLBody _
  .Replace( _
   "<span style='background:silver;mso-highlight:silver'>Ms. X</span> / <span style='background:silver;mso-highlight:silver'>Mr. Y</span>", firstLine) _
  .Replace( _
   "<span style='background:silver;mso-highlight:silver'>Sehr geehrte Frau X</span> / <span style='background:silver;mso-highlight:silver'>Sehr geehrter Herr Y</span>", firstLine) _
  .Replace( _
   "<span lang=FR style='mso-bidi-font-family:""xxxx Type Light"";background:lightgrey;mso-highlight:lightgrey;mso-ansi-language:FR'>Madame </span><span lang=FR style='mso-bidi-font-family:""XXXX Type Light"";mso-ansi-language:FR'>, / <span style='background:lightgrey;mso-highlight:lightgrey'>Monsieur</span>,</span>", firstLine) _
  .Replace( _
   "<span lang=IT style='mso-bidi-font-family:""xxxx Type Light"";background:lightgrey;mso-highlight:lightgrey;mso-ansi-language:IT'>Gentile signora X</span><span lang=IT style='mso-bidi-font-family:""xxxx Type Light"";mso-ansi-language:IT'> / <span style='background:lightgrey;mso-highlight:lightgrey'>Egregio signor Y</span></span>", firstLine)

 If(itMailInside.Length > 1)
  myItem.HTMLBody = myItem.HTMLBody _
  .Replace( _
   "<span style='background:lightgrey;mso-highlight:lightgrey'>tenuta</span> / <span style='background:lightgrey;mso-highlight:lightgrey'>tenuto</span>", itMailInside)
 End If

 myItem.Send()
 mailSent = True
 mailSent = False
 If myItem Is Nothing
 Else
  myItem.Close(Microsoft.Office.Interop.Outlook.OlInspectorClose.olDiscard)
 End If
Catch ex as Exception

End try

------------------------------
Andre Koepplin
Business Process Analyst
Wroclaw
------------------------------

Instead of myItem.From, try myItem.SentOnBehalfOfName .

------------------------------
Ami Barrett
Lead RPA Software Developer
Solai & Cameron
America/Chicago
------------------------------

Hi Ami - thanks for this, it worked for me too which is great and helped me resolve an urgent issue! I was wondering, is there a way to get confirmation that the email did actually send? I inputted an address incorrectly and the action completed fine but it was not actually received but it wasn't flagged at all within BP as an exception or an error?

------------------------------
Sophie Katherine Smith
HR Systems, Data and Quality Assurance Manager
Arup
Europe/London
------------------------------

Hey, Sophie - 
Typically, if an invalid address is specified, Outlook will still successfully send the message. In cases like this, the postmaster/daemon would handle the invalid recipient and send back a message stating that the destination would be invalid. I would think the only way to validate programmatically, is to check for a bounced e-mail in the inbox.

------------------------------
Ami Barrett
Sr Product Consultant
Blue Prism
Plano, TX
------------------------------

ah ok yes good point - thanks!

------------------------------
Sophie Katherine Smith
HR Systems, Data and Quality Assurance Manager
Arup
Europe/London
------------------------------