1. Kari Paukku
  2. PowerBuilder
  3. Saturday, 18 February 2023 11:02 AM UTC

Hi,

I'm trying to add CC address to an email I send from PB.

Settting the subject, To (single receiver) work fine, but trying to add the CC gives error "incorrect number of parameters".

 

here is an extract of the code

// This part works fine
lole_Message = ole_outlook.CreateItem(0)

lole_Message.To = emailAddress
lole_Message.Subject = MailSubject

// And this fails on the add command
lole_recipient = lole_Message.Recipients.Add( "anybody@help.com" )
lole_recipient.Type = 2
lole_recipient.Resolve

What part am I missing?

 

Thanks,

Kari

 

ps. The code can use the users local Outlook

Accepted Answer
Miguel Leeuwe Accepted Answer Pending Moderation
  1. Saturday, 18 February 2023 14:27 PM UTC
  2. PowerBuilder
  3. # Permalink

Have a look at Roland Smith's Outlook sample. There's a "New" button on the window that should solve your doubts.

https://topwizprogramming.com/freecode_outlook.html

 

Looking at Roland's example, the way you add the TO address is incorrect: I think you should do something like this:

OLEObject oleMailItem
OLEObject oleRecipient, oleRecipientCC

oleMailItem = oleApplication.CreateItem(olMailItem)
oleMailItem.Subject    = "Test Email"
oleMailItem.BodyFormat = olFormatHTML
oleMailItem.HTMLBody   = "<HTML><BODY>Please enter the message text here.</BODY></HTML>"

oleRecipient = oleMailItem.Recipients.Add( trim( "someone@nothing.net" ) )
oleRecipient.Type = olTo // = 1
oleRecipient.Resolve

oleRecipientCC = oleMailItem.Recipients.Add( trim( "someone_in_CC@nothing.net" ) )
oleRecipientCC.Type = olCC // = 2
oleRecipientCC.Resolve

//oleMailItem.Display
oleMailItem.Send

// Avoid email being stuck in the Outbox:

// right now, with my outlook365, both sync versions below work for me, just try to see which one does the trick for you:
// Sync that works for us for Outlook 2013 and later:
oleNameSpace.SendAndReceive(true)

//// Sync that works for us for earlier versions of outlook, but should still work for newer versions? 
//// Not too sure, because in our code we do this ONLY for earlier versions of Outlook:
//try
//	lole_SyncObjects = oleNameSpace.SyncObjects 
//	
//	For li_i = 1 To lole_syncObjects.Count 
//		lole_sync = lole_syncObjects.Item[li_i]
//		lole_sync.Start()
//	Next 
//
//catch (oleRuntimeError RTErr2)
//	Messagebox("Error", "SyncObjects has failed: " + RTErr2.GetMessage(), exclamation!)
//end try
Comment
  1. Kari Paukku
  2. Saturday, 18 February 2023 15:43 PM UTC
Miguel,



Thanks, that did the trick. I added one more bit, which may not for every organisation (a permission thing), but this is what account to use when sending the email.



ole_item.SentOnBehalfOfName = SupportEmailAddress



Kari



  1. Helpful 2
  1. Miguel Leeuwe
  2. Saturday, 18 February 2023 16:12 PM UTC
that's great. Please mark as resolved
  1. Helpful
There are no comments made yet.


There are replies in this question but you are not allowed to view the replies from this question.