SEND EMAIL USING MS OUTLOOK

This forum is for eXpress++ general support.
Post Reply
Message
Author
User avatar
alepap
Posts: 94
Joined: Tue Jul 28, 2015 5:15 am

SEND EMAIL USING MS OUTLOOK

#1 Post by alepap »

Hi,

I would like to send an email using Outlook,

Lauch Outllook from the APP,
add a PDF file as attachment
add the email address

And ready to type text in Outlook.

Can anyone help?
Thanks,

Alexandre

User avatar
rdonnay
Site Admin
Posts: 4728
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: SEND EMAIL USING MS OUTLOOK

#2 Post by rdonnay »

You will have to experiment with this.
It send the email ok but it returned immediately.

Also, it will not work if Outlook is already running.

Code: Select all

#INCLUDE "dcdialog.CH"
#Pragma Library("ASCOM10.LIB")

#define olByReference   4
#define olMailItem      0


FUNCTION Main()

LOCAL GetList[0], cEmailAddress, cSubject, cAttachment, cText

cEmailAddress := Space(50)
cSubject := Space(50)
cAttachment := Space(50)
cText := ''

IF !IsFunction('SendMailToOutLook')
  DC_WinAlert('This sample is not available!')
  RETURN nil
ENDIF

@ 1,1 DCSAY '   Address' GET cEmailAddress GETSIZE 40 TABSTOP
@ 3,1 DCSAY '   Subject' GET cSubject TABSTOP
@ 5,1 DCSAY 'Attachment' GET cAttachment POPUP {|c|DC_PopFile(c)} TABSTOP
@ 7,1 DCSAY 'Text of Message'
@ 8,1 DCMULTILINE cText SIZE 75,10 TABSTOP

@ 1,60 DCPUSHBUTTON CAPTION 'Send' SIZE 9,1.2 ;
  ACTION {||SendMailToOutLook(Trim(cSubject), Trim(cText), ;
                   Alltrim(cAttachment), Alltrim(cEmailAddress) ), ;
                   DC_MsgBox('Message has been Sent!')} ;
  WHEN {||!Empty(cEmailAddress) .AND. !Empty(cSubject) } TABSTOP

DCREAD GUI FIT BUTTONS DCGUI_BUTTON_EXIT ;
   TITLE 'Send an E-Mail Message via OutLook' ;
   MODAL ;
   SETAPPWINDOW

RETURN nil

* ---------

PROC appsys ; RETURN

* ---------

FUNCTION SendMailToOutLook( cSubject, cText, acFile, acEmail )

LOCAL oOutlookApplication, oOutlookMailItem, i

IF Valtype(acFile) = 'C'
  acFile := { acFile }
ENDIF

IF Valtype(acEmail) = 'C'
  acEmail := { acEmail }
ENDIF

oOutlookApplication := CreateObject("Outlook.Application.16")

// Creating a new MailItem
oOutlookMailItem := oOutlookApplication:CreateItem(olMailItem)

 // Setting the new MailItem subject and body
 oOutlookMailItem:Subject := cSubject
 oOutlookMailItem:Body := cText

 // Setting the new MailItem recipients
 FOR i := 1 TO Len(acEmail)
   oOutlookMailItem:Recipients:Add(acEmail[i])
 NEXT

 // Adding the new MailItem a file attachment
 FOR i := 1 TO Len(acFile)
   IF !Empty(acFile[i])
     oOutlookMailItem:Attachments:Add(acFile[i])
   ENDIF
 NEXT

// Sending the new MailItem
oOutlookMailItem:Display()
// oOutlookMailItem:Send()

// Releasing Outlook
// oOutlookApplication:Quit()
oOutlookApplication:Destroy()


RETURN nil
The eXpress train is coming - and it has more cars.

Post Reply