Email problem

Post Reply
Marc Vanzegbroeck
Posts: 1102
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium
Contact:

Email problem

Post by Marc Vanzegbroeck »

Hi,

Normaly I use tmail for sending email. And it's working fine.
Now I want to send a HTML email with attachement, so I want to use:

Code: Select all

    LOCAL oOutlook, oMail
     #define olMailItem 0
        TRY
       oOutlook := GetActiveObject( "Outlook.Application" )
    CATCH
       TRY
       oOutlook := CreateObject( "Outlook.Application" )
       CATCH
         ?  "ERROR! Outlook not avialable. [" + Ole2TxtError()+ "]"
        RETURN
      END
    END


    oMail = oOutlook:CreateItem( olMailItem )

    oMail:Recipients:Add( "email@domain.com" )

    oMail:Subject = "Test"

    oMail:Attachments:Add( "c:\temp\Factuur  20170001.pdf" )

    oMail:HTMLBody = maakhtmlemail(adatum,aproject,auren)

    oMail:Display = .T.
 
But this is only working when outlook is open.
If it's closed, I get an error at the line

Code: Select all

oMail:Recipients:Add( "email@domain.com" )
Is there a way to avoid this problem?
Thanks.
Regards,
Marc

FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
Jack
Posts: 249
Joined: Wed Jul 11, 2007 11:06 am

Re: Email problem

Post by Jack »

Here is my code :
TRY
oOutLook := GetActiveObject( "Outlook.application" )
MsgWait("Outlook al open !","Info",2)
CATCH
TRY
oOutLook := CreateObject( "Outlook.application" )
MsgWait("Ouverture Outlook !!","Info",2)
CATCH
MsgAlert( "Outlook not installed" )
return .T.
END
END
*
*
oMailItem := oOutLook:Invoke("CreateItem", 0)
oMailitem:to:="test1@skynet.be"
oMailitem:CC:="test2t@skynet.be;test3@telenet.be"
oMailItem:Set("Subject","Mail test")
oMailItem:Set("Body","Mail")
if file("c:\excel\all.xls")
oMailItem:Attachments:Add("c:\all.xls")
endif
oMailItem:display(.F.)
*
Marc Vanzegbroeck
Posts: 1102
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium
Contact:

Re: Email problem

Post by Marc Vanzegbroeck »

Thank you Jack,

Now it's working even when outlook in not running.
Regards,
Marc

FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
Post Reply