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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Automatic e-mail 1

Status
Not open for further replies.

ChrisRChamberlain

Programmer
Mar 23, 2000
3,392
GB
The following code from a command button should enable a user to e-mail directly through MS Outlook Express.

It requires the user to actually send the message from Outlook Express.

Any alternatives that don't require user intervention?

*--
oform = CREATEOBJECT([FORM])

WITH oform
[tab].AddObject([Session1],[oleControl],[MSMAPI.mapiSession])
[tab].AddObject([Message1],[oleControl],[MSMAPI.mapiMessages])
[tab].Session1.Signon
[tab].Message1.sessionid = oform.Session1.sessionid
[tab].Message1.Compose
[tab].Message1.RecipDisplayName = [support@lithoplas.com]
[tab].Message1.AttachmentPathname = [C:\autoexec.bat]
[tab].Message1.msgSubject = [Program error]
[tab].Message1.msgNoteText = [This is a test]
[tab].Message1.Send(1) && Incorrect parameter?
[tab].Session1.Signoff
ENDWITH

RELEASE oform
*--

TIA

Chris [sig][/sig]
 
Use
.Messge1.SEND(0)
[sig]<p>Vlad Grynchyshyn<br><a href=mailto:vgryn@softserve.lviv.ua>vgryn@softserve.lviv.ua</a><br><a href= Serve</a><br>The professional level of programmer could be determined by level of stupidity of his/her bugs[/sig]
 
Vlad

Thanks - unfortunately the 0 parameter creates the following error:-

The host 'smtp.freeserve.net' could not be found. Please verify that you have entered the server name correctly. Account: 'Lithoplas', Server: 'smtp.freeserve.net', Protocol: SMTP, Port: 25, Secure(SSL): No, Socket Error: 11001, Error Number: 0x800CCC0D

Chris [sig][/sig]
 
Hi Chris,

Alternatively, you can use boolean values as the parameter.

.T. (1) - Obtain user confirmation.

.F. (0) - Bypass user & submit message to the server.

For future reference, the name of the MAPI controls help file is Mapi98.chm. [sig]<p>Jon Hawkins<br><a href=mailto: jonscott8@yahoo.com> jonscott8@yahoo.com</a><br><a href= > </a><br>The World Is Headed For Mutiny,<br>
When All We Want Is Unity. - Creed[/sig]
 
Chris, we used this way quite far ago and it worked, but this, of course, requires proper configureation of Exchange server. I have no much of experiense with MAPI controls, we use wwIPStuff and Outlook to send mail, so I cannot say exactly what the problem. Old code with MAPI controls works here ok...
[sig]<p>Vlad Grynchyshyn<br><a href=mailto:vgryn@softserve.lviv.ua>vgryn@softserve.lviv.ua</a><br><a href= Serve</a><br>The professional level of programmer could be determined by level of stupidity of his/her bugs[/sig]
 
Jon

Thanks for the info - since making the last post, the client informs me that all PCs in the projected application will now be using Microsoft Office so presumably one could use Outlook as an automation server instead?

Chris
 
Vlad

The purpose of the original code was to send an e-mail back to the developer when an error was found in the application.

The user would respond &quot;Yes&quot; to MESSAGEBOX([ERROR! etc...]) and the e-mail would be sent without further user intervention.

.RecipDisplayName = [support@anywhere.com] && e-mail address
.msgSubject = [Program error] && e-mail title
.msgNoteText = ERRORLOG.error && memo field containing error details etc


MESSAGEBOX([Your error was e-mailed etc...])

Now that the users can use Outlook as opposed to Outlook Express, the question is what is the best way of automating Outlook to achieve this?

Chris
[sig][/sig]
 
I know only one way to automate Outlook, so it is the best one ;) Just kidding.
See sample below. I removed all errors checking and multiple attachment processing to give genral idea.

Code:
* following is required for correct work with OLE automation
_VFP.OLEServerBusyRaiseError  = .T.
_VFP.OLERequestPendingTimeout = 0
_VFP.OLEServerBusyTimeout     = 5000

oOutlook = CREATEOBJECT(&quot;Outlook.Application&quot;)

oLogon = oOutlook.GETNAMESPACE(&quot;MAPI&quot;)
oLogon.LOGON()

oOutlook.CREATEITEM(1) && this is really needed, don't ask why ;)
oMail = oOutlook.CREATEITEM(0) && olMailItem

* Modify properties of the new letter
WITH oMail
  .SUBJECT = pcSUBJECT
  .BODY = pcMESSAGE
  .TO = STRTRAN(allt(pcSENDTO),',',';') && outlook separator for addresses is ';'
  .CC = STRTRAN(allt(pcCC),',',';')
  .BCC = STRTRAN(allt(pcBCC),',',';')
  .Attachments.Add(paLAATTACHFILE) && here you can improve to use array of multiple attachments
  .SEND
ENDWITH
[sig]<p>Vlad Grynchyshyn<br><a href=mailto:vgryn@softserve.lviv.ua>vgryn@softserve.lviv.ua</a><br><a href= Serve</a><br>The professional level of programmer could be determined by level of stupidity of his/her bugs[/sig]
 
Vlad

* Modified version of your code. Version is OutLook 2000

_VFP.OLEServerBusyRaiseError = .T.
_VFP.OLERequestPendingTimeout = 0
_VFP.OLEServerBusyTimeout = 5000

oOutlook = CREATEOBJECT([Outlook.Application])

oLogon = oOutlook.GETNAMESPACE([MAPI])
oLogon.LOGON()

oOutlook.CREATEITEM(1)
oMail = oOutlook.CREATEITEM(0)

WITH oMail
[tab].SUBJECT = [Hello World]
[tab].BODY = [This is a test]
[tab].TO = [support@anywhere.com]
[tab].SEND
ENDWITH

* E-mail arrives in Outbox but Outlook does not send

* Additional code to try to force Outlook to send message
oFolder = oLogon.GetDefaultFolder(4) && Go outbox, folder 4
oSend = oFolder.Items(1).Send && Send waiting items

* E-mail remains in Outbox, Outlook still does not send.

Any further ideas, please?

Chris



[sig][/sig]
 
Chris, I never had such problem on any computer and even don't have idea why it don't works. We have many customers an never received complains about such kind of fails. Only one can say: something bad with configuration in Outlook. Maybe somebody else know better?

[sig]<p>Vlad Grynchyshyn<br><a href=mailto:vgryn@softserve.lviv.ua>vgryn@softserve.lviv.ua</a><br><a href= Serve</a><br>The professional level of programmer could be determined by level of stupidity of his/her bugs[/sig]
 
Vlad

I'm sure you are right in saying the fault lies with Outlook. Neither liking or being a user of Outlook isn't a help.

The e-mail in the Outbox is italicised - any clue?

Chris
 
Vlad

The e-mail in the Outbox is italicised - any clue? Please ignore.

What perhaps I didn't make clear is that Outlook would not be on line at the time the e-mail was sent to the Outbox.

Chris
 
Hi Chris,

FWIW, you may wanna look at Vbaoutl9.chm, it's got plenty of examples of automating outlook using VBA.

Jon

Jon Hawkins
jonscott8@yahoo.com

The World Is Headed For Mutiny,

When All We Want Is Unity. - Creed
 
Jon

Thanks for the info.

We don't have the luxury of being able to stay online this side of the pond, so there would not be an Internet connection by default.

The code works providing you are on line, but obviously waits for the next connection otherwise. What I want to do is to get to connect, if offline, and then send the e-mail.

Chris
 
To establish an internet connection, you could use wwIPStuff from west-wind.com(I believe) or you could use Robert Abrham's FTP object class(available for download on universalthread.com).

Both are just wrappers for the WinInet.dll functions.

Jon Hawkins
jonscott8@yahoo.com

The World Is Headed For Mutiny,

When All We Want Is Unity. - Creed
 
Sorry.
The below from ChrisrChamberlain works for me when I remove the (1) from the send.

Any alternatives that don't require user intervention?

*--
oform = CREATEOBJECT([FORM])

WITH oform
.AddObject([Session1],[oleControl],[MSMAPI.mapiSession])
.AddObject([Message1],[oleControl],[MSMAPI.mapiMessages])
.Session1.Signon
.Message1.sessionid = oform.Session1.sessionid
.Message1.Compose
.Message1.RecipDisplayName = [support@lithoplas.com]
.Message1.AttachmentPathname = [C:\autoexec.bat]
.Message1.msgSubject = [Program error]
.Message1.msgNoteText = [This is a test]
.Message1.Send(1) && Incorrect parameter?
.Session1.Signoff
ENDWITH

RELEASE oform
 
Hi ChuckH,

works for me when I remove the (1) from the send.

I would assume that is because if you do not explicitly pass the parameter, VFP initializes it to .F.

So,

Message1.Send

is the equivalent of

Message1.Send(.F.)
or
Message1.Send(0) Jon Hawkins
jonscott8@yahoo.com

The World Is Headed For Mutiny,
When All We Want Is Unity. - Creed
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top