Email problem

Email problem

Postby Marc Vanzegbroeck » Tue Mar 06, 2018 4:17 pm

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  Expand view  RUN
   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  Expand view  RUN
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
Marc Vanzegbroeck
 
Posts: 1159
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium

Re: Email problem

Postby Jack » Tue Mar 06, 2018 5:16 pm

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.)
*
Jack
 
Posts: 288
Joined: Wed Jul 11, 2007 11:06 am

Re: Email problem

Postby Marc Vanzegbroeck » Tue Mar 06, 2018 6:19 pm

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
Marc Vanzegbroeck
 
Posts: 1159
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 50 guests