Home > Archive > Programming with dBASE > November 2005 > Outlook OLE









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Outlook OLE
John

2005-11-08, 9:24 am

I was wondering if it possible to send an email using Outlook (or Express) using dbase with OLE.

I have searched for some info from the newsgroups but found no nothing on the subject

Ideally I would like to create the outlook object, set up all the properties, add an attachment and then just let the use click on the send button.

Can this be done?

Thanks,

John
Bernd Hohenester

2005-11-08, 9:24 am

Hello John,

> I was wondering if it possible to send an email using Outlook (or Express) using dbase with OLE.
>
> I have searched for some info from the newsgroups but found no nothing on the subject
>
> Ideally I would like to create the outlook object, set up all the properties, add an attachment and then just let the use click on the send button.
>
> Can this be done?


Have a look at SendMaEx.cc in dbase.binaries (posting from 10.10.2005).
You need also SendMail.cc from the dUFLP.

cu
Bernd
John

2005-11-08, 9:24 am

Bernd Hohenester Wrote:

> Have a look at SendMaEx.cc in dbase.binaries (posting from 10.10.2005).
> You need also SendMail.cc from the dUFLP.


Thanks Bernard for the info.

All works well EXCEPT when I attach a file. I get prompted with 'Stopped on exception throw of type EXCEPTION'.
This happens inside the following loop:
// add attachments
for i = 1 to this.Attachments.size
oItem.attachments.add(this.Attachments[i])
endfor

Any ideas what might be causing this. arraysize ie definately 1

I tries several types of files for attaching but none of them work.

Thanks

Bernard
Bernd Hohenester

2005-11-08, 9:24 am

Hello John,

> All works well EXCEPT when I attach a file. I get prompted with 'Stopped on exception throw of type EXCEPTION'.
> This happens inside the following loop:
> // add attachments
> for i = 1 to this.Attachments.size
> oItem.attachments.add(this.Attachments[i])
> endfor
>
> Any ideas what might be causing this. arraysize ie definately 1
>
> I tries several types of files for attaching but none of them work.


Hmm, i use this .cc in my applications even with attachments and have no
problems. Please specify the whole pathname and filename in attachments
and of course the file must exist. The programline should look like

EmailMsg.Attachments.add("c:\temp\table.dbf")


I send you an enhanced version of SendMaEx.cc. You must specify one or
more recipients to send the email. If not, now the email-window is
displayed. And i added this behaviour for attachments. If a file in
attachments does not exist, the email-window is displayed.

cu
Bernd





/*
----------------------------------------------------------------
Description:

This class is derived from SendMail.cc and extends its
function Send().

While SendMail.cc uses Outlook Express this class first tries
to send the email with Outlook. If this attempt leads to
an error, then Outlook Express is used.


Programmers:

Adapted by Bernd Hohenester from some code snippets in the
newsgroups.


History:

10 Oct 2005 initial release


Usage:

set procedure to SendMaEx.cc additive
EmailMsg = new EmailEx()
EmailMsg.Dest = "username@domain.ext"
EmailMsg.ccDest = ""
EmailMsg.bccDest = ""
EmailMsg.Subject = "Title / Subject"
EmailMsg.Message = "Enter your message here..."
EmailMsg.Attachments.add("FileName1.ext")
EmailMsg.Attachments.add("FileName2.ext")
EmailMsg.Attachments.add("FileName3.ext")
EmailMsg. Send(bSendWithOutloo
kExpress)
close procedure SendMaEx.cc


If you are using SendMail.cc you can easily swap to SendMaEx.
Change the two lines

set procedure to SendMail.cc additive
EmailMsg = new Email()

to

set procedure to SendMaEx.cc additive
EmailMsg = new EmailEx()


Properties:

As the class is derived from SendMail.cc it uses the same properties.
Please look in the header of SendMail.cc for a description.

Its function Send() uses a new parameter:

bSendWithOutlookExpr
ess - if true forces the class to use Outlook
Express
instead of Outlook. If false or none the class first
tries to
send the email with Outlook.


*/


class EmailEx of Email custom from "sendmail.cc"

this.recipients = new array()


function Send(bSendWithOutloo
kExpress)

// forced to send the email with OE
if bSendWithOutlookExpr
ess
return super::send()
endif

local oOutlook, oItem, cTemp, i, ch


try
oOutlook = new OleAutoClient("Outlook.Application")

oItem = oOutlook.CreateItem(0)


// convert recipients from string to an array
this.recipients = new array()

cTemp = ""
for i = 1 to len(this.Dest)
ch = substr(this.Dest, i, 1)
if not ch $ ";,"
cTemp += ch
else
if len(ltrim(rtrim(cTem
p))) > 0
this.recipients. add(ltrim(rtrim(cTem
p)))
cTemp = ""
endif
endif
endfor
if len(ltrim(rtrim(cTem
p))) > 0
this.recipients. add(ltrim(rtrim(cTem
p)))
endif


// add recipients to email
for i = 1 to this.recipients.size
oItem.recipients.add(this.recipients[i])
endfor
this.AutoSend = oItem.recipients.ResolveAll

// add subject
oItem.subject = this.Subject

// add message
oItem.body = this.Message

// add ccDest
oItem.cc = this.ccDest

// add bccDest
oItem.bcc = this.bccDest

// add attachments
for i = 1 to this.Attachments.size
if new file().exists(this.Attachments[i])
oItem.attachments.add(this.Attachments[i])
else
this.AutoSend = false
endif
endfor


if this.AutoSend
// send the email
oItem.Send()
if type("oOutlook.Assistant") <> "O"
oOutlook.quit()
endif
else
oItem.Display()
endif


// housekeeping
release oItem

release oOutlook

catch(exception e)

// call Send() from SendMail.cc
super::send()

endtry

return

endclass
John

2005-11-09, 7:23 am

Bernd Hohenester Wrote:

Please specify the whole pathname and filename in attachments
> The programline should look like
>
> EmailMsg.Attachments.add("c:\temp\table.dbf")


That was it. Needed to the add absolute path.

Thanks for your help Bernard.

Much Appreciated.

John
Bernd Hohenester

2005-11-09, 8:23 pm

Hello John,

> That was it. Needed to the add absolute path.


You're welcome.

cu
Bernd
John Jay

2005-11-10, 1:23 pm


Hi John

> I was wondering if it possible to send an email using Outlook (or Express)

using dbase with OLE.
Look at post OLE outlook posted by john in this newsgroup dated 11-7-2005

John Jay
Best Marine


John Jay

2005-11-10, 8:23 pm

Please disreguard my last reply , it was for a different thread.
Opps
John Joy



Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com