Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Sending SMTP email with CDO.Message in PowerBuilder 11.5

1,988 views
Skip to first unread message

Future Terraformer

unread,
Dec 30, 2010, 11:56:44 AM12/30/10
to
It took much fiddling to get it to work. I'm positing it for
posterity. Someday I might need this again.
Concerning general use of OLE objects, PB11.5 doesn't compile if you
try to use default properties
objMsg.Configuration.Fields("...stuff...") = "Username
Here!" //compile error
objMsg.Configuration.Fields("...stuff...").Value = "Username
Here!" //success

Documentation of the CDO.Message is available at the MSDN:
http://msdn.microsoft.com/en-us/library/ms526453(EXCHG.10).aspx

Powerbuilder didn't like string-indexed collections nor did it work
well with default properties (caused compile errors). So I got it all
ironed out and the following is my code:
And I'm not the king of error handling, it can probably be improved.
I'm just maintaining someone elses horrible mess, I don't regularly
develop in powerbuilder.

///////////////////////// use the CDO.Messsage object (IDispatch) to
send the email
OleObject objMsg
objMsg = CREATE OleObject

TRY
objMsg.ConnectToNewObject("CDO.Message")
objMsg.Configuration.Fields("http://schemas.microsoft.com/cdo/
configuration/sendusing").Value = 2
// Change the name of the mail server in the next line
objMsg.Configuration.Fields("http://schemas.microsoft.com/cdo/
configuration/smtpserver").Value = "mymailserver.domain.com"
objMsg.Configuration.Fields("http://schemas.microsoft.com/cdo/
configuration/smtpauthenticate").Value = 1
// Set the username and password in the next two lines
objMsg.Configuration.Fields("http://schemas.microsoft.com/cdo/
configuration/sendusername").Value = "Username Here!"
objMsg.Configuration.Fields("http://schemas.microsoft.com/cdo/
configuration/sendpassword").Value = "Password Here!"

// The to and the from users go in here.
objMsg.To = "us...@someplace.com"
objMsg.From = "some_other_user@somewhere_else.com"
// For formatted text, instead of TextBody use HTMLBody property,
using HTML code to format it.
objMsg.TextBody = "Example text from powerbuilder using
CDO.Message"
objMsg.Subject = "PBuilder use of CDO.Message"
objMsg.AddAttachment("C:\LabResults\Cow 987.pdf")
objMsg.DSNOptions = 14

objMsg.Configuration.Fields.Update()
objMsg.Send()
CATCH (Exception Ex)
MessageBox("Send Email Failure", "Email failed with the
following error: "+Ex.Text)
return false
END TRY

destroy objMsg
return true

bruce.a...@yahoo.com

unread,
Jan 27, 2011, 2:00:42 AM1/27/11
to
This group had been marked read only on the Sybase server. In addition, the feed between Google and the Sybase server is not currently working. If you post
through Google the post will never show up on the Sybase server, and most people who answer questions in that group will never see it. Instead, you may want to access the Sybase newsgroups directly at:

http://www.sybase.com/support/community-forums

0 new messages