Page 1 of 1

Email through outlook

Posted: Sun Sep 27, 2009 11:40 pm
by hag
Hello all:

I would like to email some information directly from my app. However I would like the program to open outlook and have the subject automatically appear on subject line and a link placed into the text.
I have some code now it automatically mails me error log messages. But it doesnt open the email so the user can add some comments.
Suggestions and code please. Thanks in advance.

Re: Email through outlook

Posted: Mon Sep 28, 2009 7:18 am
by Enrico Maria Giordano
This is a working sample:

Code: Select all

#include "Fivewin.ch"


FUNCTION MAIN()

    SHELLEXECUTE( 0, 0, "mailto:e.m.giordano@emagsoftware.it?subject=This is a test&body=www.emagsoftware.it", 0, 0, 1 )

    RETURN NIL
EMG

Re: Email through outlook

Posted: Mon Sep 28, 2009 1:32 pm
by James Bott
Harvey,

Enrico's solution will work, or if you are using the DEFINE MAIL syntax just add FROM USER to get the new message dialog to appear.

Regards,
James

Re: Email through outlook

Posted: Mon Sep 28, 2009 7:14 pm
by hag
Thanks to both. Perfect.

Re: Email through outlook

Posted: Tue Oct 27, 2009 12:33 pm
by Sakis
Hello to all

Enrico code work's only with XP. can anyone post the code for thw same task but on Vista.

Best Regards
Dionisis

Re: Email through outlook

Posted: Tue Oct 27, 2009 12:40 pm
by Marco Turco
Hi,
this routine will use Outlook via OLE if available otherwise the default mail client.


#include "FiveWin.ch"
#include "Mail.ch"

FUNCTION Interactivemessage()
paramet cSubject, cBody, aTo, aFiles, lDirectSend,lUseCC

LOCAL oOutLook,oMailItem,oRecip,oAttach,i,lOffice,lMailMancante,cVar
local nSelected,oDlg1

if lUseCC=NIL
lUseCC:=.f.
endif

if lDirectSend=NIL
lDirectSend:=.f.
endif

if cSubject=NIL
cSubject:=""
endif
if cBody=NIL
cBody:=""
endif
if aFiles=NIL
aFiles:=array(0,0)
endif

lMailMancante:=.f.
for i:=1 to len(aTo)
if len(alltrim(aTo[i,2]))=0
lMailMancante:=.t.
endif
next

if lMailMancante
MsgStop("Indirizzo di posta elettronica assente","Attenzione")
return
endif

lOffice:=.t.
TRY
oOutLook := CreateObject( "Outlook.Application" )
oMailItem := oOutLook:CreateItem( 0 )
oRecip := oMailItem:Recipients
CATCH
lOffice:=.f.
END

****

if lOffice
if lUseCC
cVar:=""
for i:=1 to len(aTo)
cVar:=cVar+aTo[i,2]+";"
next
oMailItem:Bcc:=cVar
else
for i:=1 to len(aTo)
oRecip:Add( aTo[i,2] )
next
endif

oMailItem:Subject := cSubject

oMailItem:Body := cBody

if len(aFiles)>0
oAttach := oMailItem:Attachments
for i:=1 to len(aFiles)
oAttach:Add( aFiles[i,1] )
next
endif

if lDirectSend
oMailItem:Send()
else
oMailItem:display(.t.)
endif
else
for i:=1 to len(aTo)
aTo[i,1]:=alltrim(aTo[i,2])
aTo[i,2]:=alltrim(aTo[i,2])
next


oMail:=tMail():New( cSubject,cBody,,,,, .f., .t.,,aTo,aFiles)

ACTIVATE MAIL oMail
retcode:=oMail:nRetCode

do case
case retcode=1
MsgStop("Invio interrotto dall'utente","Errore")
case retcode=9
MsgStop("Troppi files da inviare","Errore")
case retcode>0
MsgStop("Errore nell'invio della mail ("+alltrim(str(retcode,3))+")","Errore")
endcase
endif
return

Re: Email through outlook

Posted: Tue Oct 27, 2009 3:24 pm
by James Bott
Dionisis,

>Enrico code work's only with XP. can anyone post the code for thw same task but on Vista.

Have you tried:

DEFINE MAIL...

James

Email through outlook

Posted: Thu Oct 29, 2009 9:18 am
by Richard Chidiak
Dionisis

Enrico's code work on Vista

Note : i use microsoft Outlook and it prompts the inbox

HTH

Richard