Page 1 of 1
SEND EMAIL USING MS OUTLOOK
Posted: Tue Apr 23, 2019 4:39 am
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
Re: SEND EMAIL USING MS OUTLOOK
Posted: Tue Apr 23, 2019 5:28 am
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