Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sending Emails 2

Status
Not open for further replies.

andyk

Programmer
Jul 29, 2000
24
GB
I would like to send an email from within FoxPro. The VFP Help gives an example of invoking Excel using OLE and this works fine. Could anyone give me an example of sending an email using Outlook Express?

When I run the command:

oleApp = createobject("outlook.Application")

I get the error:

OLE Error code 0x80080005 : Server execution failed.

Should I be trying to use outlook express?

Thanks in advance.

Andy.
 
Hello Andy K,

Have you tried to use api calls?
I read the below on this site somewhere () maybe it was another site:

Quote:

Hello H Hill

the code below will open the users default Browser and e-mail for the browser
example i use Netscape Nav and Messenger , when i run this code it opens netscape to the coded website ...then opens my messenger e-mail.

*************************************************
DECLARE INTEGER ShellExecute IN SHELL32.DLL ;
INTEGER handle,;
STRING @sFile,;
STRING @lp,;
STRING @dir,;
STRING @dir1,;
INTEGER ncmd

handle = 0

*** THIS IS THE LINE THAT OPENS THE BROWSER
***(Whatever Browser the user has set to default)
a = ShellExecute(handle,"open","
*** THIS IS THE LINE THAT OPENS THE DEFAULT E-MAIL
b = ShellExecute(handle,"open","mailto:YourE-mailAddressHere","","",1)


****************************************************

Just replace the url in line a= with your own and replace
the mailto: in line b= to whoever you want the mail to be
sent to....
you can also specify a subject or priority in the mailto:
like this

mailto:whoever@wherever.com&SUBJECT=WHATEVER?PRIORITY=HIGH

notice that between the mailto:youraddress and the SUBJECT
i used a & but between the SUBJECT and priority i used ?
you only use the & once from there on you use ? to divide

Hope this help you

Jason

EndQuote

I too hope this helpes you, there is some more where this came from, but I cant find it right now...
Ropje
 
This is so simple I drop this in most my apps:

#Define MAIL_MESSAGE 0

#Define olByValue 1
Close data
Use ..\data\members2 in 0

Select members2

Scan for !empty(email)
cAddress = alltr(email)

cMessage_ID = ttoc(datetime())
cSubject = "Europa Application: " + cMessage_ID
cBody = 'Testing email for Karen S'

Public x
oApp=createobject("Outlook.Application")
oMail = oApp.CreateItem(MAIL_MESSAGE)

With oMail


.To = cAddress
* cc/bcc work ok
.cc= "Michaelo@srgroup.com.au"
.bcc='Michaelo@srgroup.com.au'

* .SenderName =""
* this is valid but I need permission for austpaper
.SentOnBehalfOfName="australianpaper@srgroup.com.au"
* "australianpaper@srgroup.com.au"



.Body = chr(13)+chr(13)+ cBody + .Body ;
+chr(13)+ chr(13) +"Dear "+alltr( alltr(title)+space(1)+alltr(firstname)+space(1)+alltr(surname) );
+ chr(13)+ chr(13)+"Welcome to my ole nightmare! " ;
+ chr(13)+chr(13)+"This message was automatically created but still generated a 'You do not have permission error!'" ;
+ chr(13)+ chr(13)+ " - Michael O"


* .Attachments.Add(set('defa')+sys(2003)+"\data\film" + ".dbf", olByValue, 2, "film.dbf")
* .Attachments.Add(set('defa')+sys(2003)+"\data\imports" + ".dbf", olByValue, 1, "imports.dbf")

* .Attachments.Add(this.OutputDir + this.cOutputTable + ".dbf", olByValue, 2, this.cOutputTable)
* .Attachments.Add(this.OutputDir + this.cProcessTable + ".dbf", olByValue, 1, this.cProcessTable)


.Subject = cSubject

.Save()
* let user send themselves
.Display


*.Send()
Endwith
Endscan

Close data
 
Hmm, looks like first sample will not allow to SEND mail, but just allow to OPEN mailing system for users. What when we need to send mail in background without any additional forms opening? Second sample is nice, but command 'oApp=createobject("Outlook.Application")' does not works, as mentioned in first message. The main problem is that MS application cannot be used through OLE in some installation cases.
Andyk, Check that Outlook files in Outlook folder are not read-only. We have had the same problem with invoking of MS Word when all its files was read-only. Check also that it is installed locally, not used from network.
In addition, check that Outlook (not Outlook Express) is installed. These are different applications. Outlook Express may come with Windows Installation. Outlook itself (that allows to run it using Outlook.Application name) is part of MS Office.
 
Thanks for all your replies,

I am actually running Outlook Express 5 on my development machine. My problem is that the target machine may be running Outlook or Outlook Express. Therefore I assume Ropje's solution is the most suitable. I have had some success with this solution after I swopped the use of '?' and '&' in the mailto: statement. i.e the following works:

mailto:whoever@wherever.com?SUBJECT=WHATEVER&body=abcd

Using this approach though, how do you include these special characters in subject/body text. Placing a '\' before them does not seem to work.

Many Thank Andy. :)
 
When I run the command:

oleApp = createobject("outlook.Application")

I get the error:

OLE Error code 0x80080005 : Server execution failed.

Should I be trying to use outlook express?


No. Outlook Express provides no COM interface and therefore, cannot be instantiated as an Automation server. MS Outlook can be automated and Jolicoeur's example is accurate.
 
is there a way to email using lotus notes ver 4.6? if the answer is yes, could anyone please put some code on how this is done?
 
It is possible, but it is very hard to eliminate user logon dialog box at the start of Lotus Notes automation server (I was not able to suppress it - need more skill in programming and administration of Lotus Notes). If you still need it, contact me, because I need some time to find code I used 6 months ago to investigate the ability of sending EMails using Lotus Notes.
In any case, SMTP mail works near everywhere. And wwIPStuuf class library does this very well. Only one disadvantage - you will need to make carbon copy of each mail to some mail box, if you need to track all mail sending from your application.
 
According to MS, Outlook does not yet talk directly to Notes Mail (though it does work with cc:Mail).

If Notes can be configured to provide SMTP features, then as Volodymyr said it should work fine. I seem to recall one of my clients was using Outlook to talk to Notes via SMTP, and once configured it worked fine (well, as good as you would expect for a combination Microsoft/Lotus Notes interface).
 
If you are not stuck on using Microsoft products and can switch to Eudora. I have routines that automatically email from records in a database. I have a program that runs 24/7 that does nothing but look at the database for things to email and another that populates the database with things that need to be sent by email. If you want to see if it will work for you ,

You will need a ftp program that allows you to enter a username and passwrd to access s secure server. Like WebDrive or CuteFtp.

Server = ibs.internationalbid.net (note no www. or ftp.)
username = fpug (lower case only)
password = 73897253
download = \\sharedcode\emailque\*.*

If you do not have a ftp program you can get one at or email me and I'll sent the files to you. Please mention emailque in the email. It is 2.6 code but it is running right now under VFP6 SP3.

Feel free to alter the code to fit your needs. If you make it run better, send me a copy back. [sig]<p>David W. Grewe<br><a href=mailto:Dave@internationalbid.net>Dave@internationalbid.net</a><br><a href= > </a><br> [/sig]
 
I am attempting to tackle this problem myself. I am not using Outlook, however. Our email system here is Pegasus. Okay everyone, get off the floor, stop laughing and help me!!

I like what ROPJE is suggesting, but is there any way to add an attachment through code? Otherwise, I am open to other suggestions. Unfortunately, Outlook does not seem to be an option in my case.

Thanks,
Steve
 
I am currently using a program called mailsend that let you sent an email from the command line.

I have an on error routine that sends me an email whenever there is an error in the application. I have foxpro generate a dos batch file with all the parameters that mailsend.exe requires. Mailsend is available as shareware and can be registered for about US$20. Most of the parameters that I use are stored in a table which makes it easy to maintain.

Another option you might want to use is a tip recieved from someplace else.



HJ
 
Oopadelic offers a free html mailer. Additionally if you are running IIS on NT you can use the CDONTS interface to the SMTP server.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top