Link to home
Start Free TrialLog in
Avatar of josephbarron
josephbarron

asked on

Sending Outlook Emails with PowerBuilder

I have a client that has a database in SQL Server. It has a front end PowerBuilder application that I developed. They use this for Membership management and send emails regurlarly. A new VP has come on board that wants to send Emails through Outlook, but wants the Body to be personalized to recipient.

Dear John:

Your company, Verizon, Inc. is a very important member....

They also want to add attachments and set the subject line. The data for the merge is in SQL Server and I have the perfect spot to put the button control. Problem is, I don't know a good resource for connecting to Outlook 2003, loading the information and pressing the send button, in an automagical way.

Any guidence would be greatly appreciated.

Regards,
Avatar of diasroshan
diasroshan
Flag of Kuwait image

Hi,

If u check the PB examples u will find a good way to do what u want...

If u run PB examples,
expand the tree 'window controls'
under that there is RichPad RTE Control..

Check that out... it shows how to mail an RTE control... u can use the same to personalise and send a document.

Cheers,
Rosh
Avatar of josephbarron
josephbarron

ASKER

Actually found the solution using the Redemption DLL solution. It works around most of the issues with OLE connections to Outlook and the security blocks that MICrosoft has put in place to plug holes.

http://www.dimastr.com/redemption/

Works real well and there are plenty of examples on this board of how to use it.


integer rc
oleobject oleSafeMailItem
oleobject oleTmp
oleobject oleOutlook
oleobject oleNameSpace
STRING ls_email, ls_company_name, ls_full_name, ls_path, ls_body_text, ls_checked

li_send_total = dw_details.rowcount()  

FOR li_counter = 1 to li_send_total
      ls_email = dw_details.getitemstring(li_counter, "email")
      ls_full_name = dw_details.getitemstring(li_counter, "fullname")
      ls_company_name = dw_details.getitemstring(li_counter, "Company")
      ls_body_text = wf_create_body(li_counter)  // This function creates the body text using <FN> for first name, <LN> for last name, etc.
      ls_path = TRIM(sle_attachment.text)
                ls_email = "tom@company.com"

      oleOutlook = create oleobject
      rc = oleOutlook.ConnectToNewObject('Outlook.Application')

      oleNameSpace = oleOutlook.GetNameSpace('MAPI')
      oleNameSpace.Logon('', '', true, true)
      
      oleSafeMailItem = create oleobject
      rc = oleSafeMailItem.ConnectToNewObject('Redemption.SafeMailItem')
                  
      oleTmp = create oleobject
      oleTmp = oleOutlook.CreateItem(0)
      oleSafeMailItem.Item = oleTmp
      oleSafeMailItem.Recipients.Add(LS_EMAIL)
      oleSafeMailItem.Recipients.ResolveAll
      IF TRIM(sle_attachment.TEXT) = "" THEN
            // No Attachment
      ELSE
            oleSafeMailItem.Attachments.Add(TRIM(sle_attachment.TEXT))
      END IF
      oleSafeMailItem.Subject = trim(sle_subjectLine.text)
      oleSafeMailItem.body = trim(ls_body_text)
      oleSafeMailItem.Send
                  
      if isValid(oleSafeMailItem) then destroy oleSafeMailItem
                  
      if isValid(oleNameSpace) then
             oleNameSpace.logoff()
             destroy oleNameSpace
      end if
                  
      if isValid(oleOutlook) then
             oleOutlook.DisconnectObject()
                       destroy oleOutlook
      end if
                  
NEXT
ASKER CERTIFIED SOLUTION
Avatar of PAQ_Man
PAQ_Man
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial