INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Sending e-mail via MAPI to Outlook

Sending e-mail via MAPI to Outlook

(OP)
Hi colleagues!

I had been using a Visual FoxPro 9 application (with MAPI commands) which sends e-mails automaticaly to the Outlook Express. Operating system was Windows XP. It is working well for years.

Now, I installed the same Visual FoxPro 9 application in a computer with Windows 7 Ultimate, , and the mail application is Outlook (not Outlook Express), which I configured accordingly, to receive mails from the Visual FoxPro 9 application.

But my Visual FoxPro 9 application presents error when it try to send mails to Outlook:
"Application is trying to access e-mail address information stored in Outlook..."
Even if I allow, the messages do not go to the Outlook outbox to be sent.

Do you have any solution?

Thank you.
SitesMasstec

RE: Sending e-mail via MAPI to Outlook

(OP)
Hi Mike!

I used your advice contained in the above link. But the error "Application is trying to access e-mail address information stored in Outlook..." do not desappeared. It appears again.

I am using Outlook 2007.

Thank you.
SitesMasstec

RE: Sending e-mail via MAPI to Outlook

(OP)
Hello colleagues!

Let me explain that I am using Windows 7 Ultimate with Outlook 2007. The solution proposed by Mike has not solved the problem. I've done researchs for days (and nights) but without a solution.

I simply cannot understand this: if I have any e-mail program (Outlook, Outlook Express, Eudora, etc), and if it is defined as the Default mail program, why the VFP program I wrote, to "send e-mails to the Out box of the default mail program" is not able to put my messages there??

Or MAPI is only for use with Outlook Express?

Is there another simpler approach to solve the problem, instead of using MAPI ?

Thank you,
SitesMasstec



RE: Sending e-mail via MAPI to Outlook

MAPI is the general solution, yet the full Outlook version is done secure by default and not allowing programmatic usage without the user confirming/allowing it, as you learned especially in case there is no antivirus software installed. So in short MS decided against the MAPI promise to generally allow programmatic mailing and decided for safety of users against becoming a spam sender or against viruses spreading with all their address book contacts.

>Even if I allow, the messages do not go to the Outlook outbox to be sent.
I can't reproduce that right now, last time I was configured that way an allow allowed sending mails.

If your main concern is sending mail and not also having it in the users outbox, there are many ways to send mails directly via SMTP protocol. This is partly a reasoning against the security concern. A virus developer would not automate a mail client, if he can send mails without user notice and without appearing in an outbox. There are commercial libraries removing these security prompts and I rather recommend against them. Get used to this security and ask users that want that mail feature via Outlook to allow sending.

Bye, Olaf.

RE: Sending e-mail via MAPI to Outlook

There are two different things going on with what you are saying. Employing the default email client, and programmatically sending emails.
You can most likely tell the default client to start an email using an HTML link with "sendto:". That should create a new email from your default email client, but that won't necessarily allow you to send it, just create it. And like Olaf says, email client makers have disabled the automation of the send functionality because of spammers.
Sending an email programmatically is a whole different process. You have to connect to an email server using telnet or VFP or whatever, use SMTP commands, and let its mechanism do the work. Which means you have to connect, possibly authenticate, feed the body, subject, header, attachments, destination and so on to the server and let it send the email. Your default email client does all of that.

-Dave Summers-
cheers
Even more Fox stuff at:
http://www.dave-summers.net/foxprolinks.htm

RE: Sending e-mail via MAPI to Outlook

I agree with Dave,

though there are ways to get to the default mapi mail client without specifying outlook.application via mapi.ocx or dlls and most probably that's what SitesMasstec already used. The mail API also includes sending, also reading contacts, outbox or inbox and more. Actually security prompts should also be concerned about reading contacts, as they can be used as recipients in further code sending mails via a known/hacked or simply self owned smpt server. You normally only need to be able to handle the default mapi mail client, if you want your actions to be transparent to the user in there, eg having sent items or draft mails saved or whatever your software offers to do in their mail client for them.

It's also no crime to send mails without further traces. Any order form in a shop site may submit a mail to the shop owner directly via mailto action, but that's not at all state of the art. Web forms rather submit your order to a server side api. That's also a reason you get a order confirmation to your mailbox from the shop instead of vice versa having an order to them in your sent items. Orders coming in to them first are stored into their sites database and then processed via data flow to furhter order processing code, not via mails. Order processing code then eg sends an order confirmation in the first place, etc.

Bye, Olaf.

RE: Sending e-mail via MAPI to Outlook

2
Hi SitesMasstec,

I am a Visual Foxpro programmer since 1997. I have realized the automation of email clients via MAPI and VBA as well.

This works well with the following email clients:

- MAPI & VBA: Outlook 97 / 2000 / 2003 / 2010 / 2013
- MAPI: Outlook Express
- MAPI: Mozilla Thunderbird

But with one exception:

- Outlook 2007 !!! MAPI & VBA does not work completely correct !!!

I was looking for a solution by google, by forums, by MSDN, etc. - not only for a few hours - but rather for many days !!!

I have installed many service packs for Office 2007 and Outlook 2007 !!!

No solution !!!

I gave it up - my conclusion is: Outlook 2007 is unfortunately very buggy / faulty

Best regards, Stefan

RE: Sending e-mail via MAPI to Outlook

(OP)
Hello!

The research done by Stefan proved useful for me: Thunderbird is running well integrated with MAPI.

Thank you,

SitesMasstec

RE: Sending e-mail via MAPI to Outlook

(OP)
Hi colleagues!

I followed the advide of Stefan above and, as I had told, it worked fine:

Under Windows 7 - Home Premium - my VFP program sent e-mails to the Outbox of the Thunderbird mail program.

And I thought the problem was solved... until yesterday, when I installed the same program to send e-mails to the Outbox of Thunderbird mail program, in another computer running Windows 7 Ultimate edition!

I did everything I had done in my computer running Windows 7 Home Premium (I ran the application program and Thinderbird as Administrator, registered OCX files, etc), even one thing more: accessing the Windows Firewall and adding a new rule: Unlock 587 door for sending e-mails.

What more am I missing with Windows 7 Ultimate edition ?

Thank you,
SitesMasstec

RE: Sending e-mail via MAPI to Outlook

Is Thunderbird itself correctly configured to send/receive Mails?

RE: Sending e-mail via MAPI to Outlook

Also, what OCX are we talking about? msmapi32.ocx?
Did you register it with C:\Windows\SysWow64\regsvr32.exe?

Bye, Olaf.

RE: Sending e-mail via MAPI to Outlook

(OP)
Hi Olaf!

Yes, Thunderbird is correctly configured to send/receive mails, but the Windows do NOT have the \SysWow64 folder! (It has \System and \System32 folders) MSMAPI32.OCX is registered with C:\Windows\System32\regsvr32.exe

Windows 7 Ultimate is in 32 bits mode.

Thank you,
SitesMasstec


RE: Sending e-mail via MAPI to Outlook

Huh, a real 32bit only system? Sure this is a 32bit CPU?

Ok, besides that doubt: What code? What error?

Bye, Olaf.

RE: Sending e-mail via MAPI to Outlook

(OP)

Well, the "My Computer", "Properties", shows Windows 7 32 bits.

My application catches the error and shows a customized message "Problem sending e-mails" for the application not able to put the e-mail in the Thunderbird Outbox.

Thanks,
SitesMasstec

RE: Sending e-mail via MAPI to Outlook

We can't mend code we don't know just knowing there is any error.
It's OK that you keep an error message from your users,m but not from yourself or developers, that should be able to help you.

It's impossible to address a problem, if it's unknown what detail fails.
So please, again, provide your mail code and the error happening.

Bye, Olaf.

RE: Sending e-mail via MAPI to Outlook

Hi SitesMasstec,

i suggest to check the programm assignments in the control panel.

Take a look at the following screen shot (i have a german windows):



Important to check the last setting, MAPI !!!

If You want to use Thunderbird, make this settings for Tunderbird instead of Outlook smile

Best regards, Stefan

RE: Sending e-mail via MAPI to Outlook

Well, Thunderburd has to be the standard mail client (in the same manner as browsers nag you to want to be the standard browser of your system).

Without knowing your code and error it's quite impossible to tell what stage of your mail creation and sending fails. Whether it's already creating a mapi session or mail item or sending it. So you better introduce the capability to log errors for your own inspection, even if it means nothing to your users, even if it means nothing to you, we can't mend code not even knowing which line errors. And you also won't help yourself going forward, if you never inspect error messages.

Bye, Olaf.

RE: Sending e-mail via MAPI to Outlook

OK, I can contribute some english screenshots, though of Windows 8.1:

First of all, go to Control panel. That should have "Default Programs":


The problem may be, Thunderbird is not your default mail client on that machine, it's not so much OS related. But as I said previously Browsers nag you to be standard/default browser. Mail clients are not nagging for that, so typically the first mail client software installed will be the mapi default client.


Click on "Set your default programs" here. This takes a while but then lists software candidate for being some default of something (not only mail or internet) are listed left. What Stefan shows is what you get, if you pick Outlook from there. You should be able to pick Thunderbird, I show you what you get, if you pick Windows Mail:


You see I can pick two options here. This varies, but Thunderbird should also offer some option to be default mail client. Ideally the option is listed under MAPI. So MS Mail does not seem to be a mapi compliant mail client. Indeed I never heard of automating MS Mail since that replace Outlook Express.

Anyway, see what you get, when you go that way to set up defaults and pick Thunderbird.

The point about MAPI is, that you actually shouldn't care about what mail client is used to act on your MAPI session login and commands. Whatever mail client set up as the default/standard and MAPI compliant Mail client should act on it. But it is, as Stefan said in his overview.

You don't need to give up on Thunderbird on that machine, as you might get this fixed. There is no better more general way than MAPI anyway. What worked better, but also varies with the security settings is automating Outlook (desktop version) directly, not through MAPI. That's a route you can only go, if you have a customer installing Outlook on all clients in an automatable way.

The only option aside direct automation and MAPI is sending mails via SMTP or IMAP protocol directly, meaning no storage of a mail inside an outbox or sent items, as already mentioned at my post from 22 Feb 16 22:06:

Quote (myself)

If your main concern is sending mail and not also having it in the users outbox (remark: or later sent items), there are many ways to send mails directly via SMTP protocol.

That would involve knowing a mail server and credentials to login to it, all the config usually known to and configured with the mail client. But you may send all mails via own account connecting to eg your own site smtp or imap mail server.

Bye, Olaf.

RE: Sending e-mail via MAPI to Outlook

Hi Olaf,

thankx for Your detailed step by step instruction!

That's exactly the way to go to the settings smile

Cause i don't own an english windows, i could only upload a german screen shot.

Best regards, Stefan

RE: Sending e-mail via MAPI to Outlook

Thanks, Stefan.

I have a mixed situation. At work I use english licenses for various reasons, at home german. What I can't contribute is Windows 7 specific screenshots and Thunderbird specific options, but SitesMasstec should now be able to find out, whether Thunderbird is the default client or change that.

Bye, Olaf.

RE: Sending e-mail via MAPI to Outlook

(OP)
Thank you very much Stefan and Olaf!

Yes, I had defined Thunderbird as my Default mail program.

Now, I am going to change my code in order to get the specific error, as Olaf strongly suggested.

I had not done this before because the very same program is working fine in 2 machines:
- One PC with Windows XP Professional & Outlook Express;
- One PC with Windows 7 Home Premium & Thunderbird.

Thanks,
SitesMasstec

RE: Sending e-mail via MAPI to Outlook

Well, I strongly suggest you at least LOG (not necessarily display) the error, any error. To be able to see it.

So in the same error handling routine you only display "Problem sending e-mails" you also log AERROR and other info you get, especially what line fails with what error.
Are you doing a TRY..CATCH there? then CATCH TO loException. That'll give you an object based on the Exception class, with several properties of interest:
Details, ErrorNo, LineNo, LineContents, Procedure, StackLevel. All these should be saved to some file, DBF or TXT.

Bye, Olaf.

RE: Sending e-mail via MAPI to Outlook

Just to muddy the waters. If you are using MSMAPI32.OCX then you are not using MAPI, you are using Simple MAPI. And, starting with Outlook 2007, Simple MAPI is no longer fully supported.

RE: Sending e-mail via MAPI to Outlook

(OP)
Hello Strongm!

Well it works in these:
Windows XP Professional & Outlook Express
Windows 7 Home Premium & Thunderbird

Do you think I have to change SimpleMAPI (indeed, I did not know about this 'Simple' version) to a 'complete' MAPI? If positive, how to find that MAPI and how to install it?

Thank you,
SitesMasstec

RE: Sending e-mail via MAPI to Outlook

You might want to try BLAT to send the email as it may give you better debug information.

RE: Sending e-mail via MAPI to Outlook

The OCX is just a way to use it via OLE class support. One of the well known ways for VFP to use MAPI is via its MSMAPI.MAPISESSION class.
A way not using MSMAPI32.OCX is using CDO.MESSAGE, which needs cdosys.dll. I don't even know a way to use MAPI directly.

MAPI is present on any OS. Neither the MSMAPI32.OCX nor CDOSYS.DLL are always there, but MAPI32.DLL

The situation is more omplicated, though, as wanting to support the default mapi client you have to use what it is using, which is either simple or extended MAPI. The HKLM\Software\Clients\Mail::(default) registry value is telling what the default mail client is binding (but for example not on my Win10 system)

There is one way to explicitly use extended mapi I see over at Craig Boyds site: http://www.sweetpotatosoftware.com/spsblog/2006/10...
I wonder whether a default mail client implementing simple mapi is also automated via extended mapi.

You only need to support mapi overall, if you want your mail to appear in the users default mail client outbox/sent items. This is an implicit question for you for the third time. Do you really need this feature of sending the mail through the mail client? This is what makes everything so complicated. It's simpler in regard of dependencies of settings and mail clients to send mails without automating them and instead directly use the SMTP or IMAP protocols, eg by using BLAT.DLL or EXE - don't thnik you have to implement the whole protocols, of course you use a tool that does that for you. If the user should have hands on the mails sent, you could save it to your own applications data. Your app then becomes a mail client itself, though not a MAPI compliant mail client, ie your app is not automatable and you don't contribute to the standard sent items folder.

Bye, Olaf.

RE: Sending e-mail via MAPI to Outlook

(OP)
Hello colleagues!

Error is (using SimpleMAPI):

OLE IDispatch exception code 0 from MAPIMessages... (1429)

Thanks,
SitesMasstec

RE: Sending e-mail via MAPI to Outlook

(OP)
Reminder:

MSMAPI32.OCX (SimpleMAPI) works fine in Windows 7 Home Premium & Thunderbird

SitesMasstec

RE: Sending e-mail via MAPI to Outlook

And in what line of which code does this error happen?
And what do other elements of the array you get from AERROR tell?

Bye, Olaf.

RE: Sending e-mail via MAPI to Outlook

>works fine in Windows 7 Home Premium & Thunderbird

Unsurprisingly, it (should) work fine with any client that supports Simple MAPI (which Outlook Express and Thunderbird do, but Outlook 2007 and later do not - at least not fully. As I recall they only really implement MAPISendMail)

RE: Sending e-mail via MAPI to Outlook

(OP)


Dear collegues:

Thank you all again for your valuable help.

My application can be configured to execute the 2 types of function: SendViaMAPI and MAPISendMail, in order to try the 2 modes.

Note that I removed the line containing the ON ERROR RETURN(.F.) command.


Command line which show error "OLE IDispatch exception code 0 from MAPIMessages... (1429)":
(program uses one or another command, as it is configured)

IF SendViaMAPI(RemetEmail, destinatario(DESTIN), ASSUNTO, TEXTOTOTAL, @aryAttachments)

or

IF MAPISendMail(RemetEmail, destinatario(DESTIN), ASSUNTO, TEXTOTOTAL, @aryAttachments)




****************************************************
FUNCTION SendViaMAPI(tcFrom, tcTo, tcSubject, tcBody, taFiles)
****************************************************
EXTERNAL ARRAY taFiles
***ON ERROR RETURN(.F.) ==== removed to shiw errors ====
* two new lines:
LOCAL loMapiForm AS FORM
DO FORM MAPI2.SCX NOSHOW NAME loMapiForm LINKED
* your code, slightly modified:
LOCAL loSession, loMessages
*!* loSession = CREATEOBJECT( "MSMAPI.MAPISession" ) && replaced by the next line:
loSession = m.loMapiForm.oleControl1 && control name to be modified by you depending on OLE name on the dummy form
loSession.Signon()
IF (loSession.SessionID > 0)
*!* loMessages = CREATEOBJECT( "MSMAPI.MAPIMessages" ) && replaced by the next line:
loMessages = m.loMapiForm.oleControl2 && control name to be modified by you, too
loMessages.SessionID = loSession.SessionID
ENDIF
WITH loMessages
.Compose()
.RecipDisplayName = tcTo
.RecipType = 1
.ResolveName()
.MsgSubject = tcSubject
.MsgNoteText = tcBody
IF PCOUNT() > 4
FOR lnCountAttachments = 1 TO ALEN(taFiles)
.AttachmentIndex = .AttachmentCount
.AttachmentName = JUSTFNAME(taFiles(lnCountAttachments))
.AttachmentPosition = .AttachmentIndex
.AttachmentPathName = taFiles(lnCountAttachments)
ENDFOR
ENDIF
.SEND(.F.) && T abre o Outlook para enviar, F envia automativamente
* (send in .T. to not send email automatically but instead see it in outlook)
ENDWITH
loSession.Signoff()
STORE .NULL. TO loSession, loMessages
RELEASE loSession, loMessages
RETURN .T.
ENDFUNC





****************************************************
FUNCTION MAPISendMail(tcFrom, tcTo, tcSubject, tcBody, taFiles)
****************************************************
EXTERNAL ARRAY taFiles
***ON ERROR RETURN(.F.) ==== removed to shiw errors ====
* two new lines:
LOCAL loMapiForm AS FORM
DO FORM MAPI2.SCX NOSHOW NAME loMapiForm LINKED
* your code, slightly modified:
LOCAL loSession, loMessages
*!* loSession = CREATEOBJECT( "MSMAPI.MAPISession" ) && replaced by the next line:
loSession = m.loMapiForm.oleControl1 && control name to be modified by you depending on OLE name on the dummy form
loSession.Signon()
IF (loSession.SessionID > 0)
*!* loMessages = CREATEOBJECT( "MSMAPI.MAPIMessages" ) && replaced by the next line:
loMessages = m.loMapiForm.oleControl2 && control name to be modified by you, too
loMessages.SessionID = loSession.SessionID
ENDIF
WITH loMessages
.Compose()
.RecipDisplayName = tcTo
.RecipType = 1
.ResolveName()
.MsgSubject = tcSubject
.MsgNoteText = tcBody
IF PCOUNT() > 4
FOR lnCountAttachments = 1 TO ALEN(taFiles)
.AttachmentIndex = .AttachmentCount
.AttachmentName = JUSTFNAME(taFiles(lnCountAttachments))
.AttachmentPosition = .AttachmentIndex
.AttachmentPathName = taFiles(lnCountAttachments)
ENDFOR
ENDIF
.SEND(.F.) && T abre o Outlook para enviar, F envia automativamente
* (send in .T. to not send email automatically but instead see it in outlook)
ENDWITH
loSession.Signoff()
STORE .NULL. TO loSession, loMessages
RELEASE loSession, loMessages
RETURN .T.
ENDFUNC

RE: Sending e-mail via MAPI to Outlook

We're one step further, fine.

You still don't tell the line of error, which line errors.

You can find this out with general error handling via ON ERROR DO errhandler WITH Lineno() - besides other parameters.

See the ON ERROR help topic. Even that simple errHandler routein there is giving more info on any error to you. You don't need to guess which line errors, you can know by LINENO()...

https://msdn.microsoft.com/en-us/library/fheb37ye(...

Also see http://sweetpotatosoftware.com/SPSBlog/2008/11/24/... and http://doughennig.com/papers/Pub/Jan98.pdf

If you begin using such standards, you begin to know and not guess or assume, which code fails and why.

Normally I would just take your code, execute and see where it errors, but in this case, it strongly depends on your environment, your computer. So you need to first implement a good error handling routine to know the line of error. Also look into the help topic AERROR. You can use this function also within the errHandler procedure to get more error info. For example the OLE class might have a detail message of importance.

Bye, Olaf.

RE: Sending e-mail via MAPI to Outlook

(OP)


Hello Olaf!

Here are the error message and bellow the code (note that line 395 is .ResolveName() )

Well, strange is that, as I press <enter> in the error message red window, my e-mail was sent to Outbox and from there to the recipients!

Thanks,
SitesMasstec



****************************************************
FUNCTION SendViaMAPI(tcFrom, tcTo, tcSubject, tcBody, taFiles)
****************************************************
EXTERNAL ARRAY taFiles
***ON ERROR RETURN(.F.) retirado nesta versao de teste (EMAITEST.PRG) em 30/03/2016
* two new lines:
LOCAL loMapiForm AS FORM
DO FORM MAPI2.SCX NOSHOW NAME loMapiForm LINKED
* your code, slightly modified:
LOCAL loSession, loMessages
*!* loSession = CREATEOBJECT( "MSMAPI.MAPISession" ) && replaced by the next line:
loSession = m.loMapiForm.oleControl1 && control name to be modified by you depending on OLE name on the dummy form
loSession.Signon()
IF (loSession.SessionID > 0)
*!* loMessages = CREATEOBJECT( "MSMAPI.MAPIMessages" ) && replaced by the next line:
loMessages = m.loMapiForm.oleControl2 && control name to be modified by you, too
loMessages.SessionID = loSession.SessionID
ENDIF
WITH loMessages
.Compose()
.RecipDisplayName = tcTo
.RecipType = 1
.ResolveName() <==== LINE 395
.MsgSubject = tcSubject
.MsgNoteText = tcBody
IF PCOUNT() > 4
FOR lnCountAttachments = 1 TO ALEN(taFiles)
.AttachmentIndex = .AttachmentCount
.AttachmentName = JUSTFNAME(taFiles(lnCountAttachments))
.AttachmentPosition = .AttachmentIndex
.AttachmentPathName = taFiles(lnCountAttachments)
ENDFOR
ENDIF
.SEND(.F.) && T abre o Outlook para enviar, F envia automativamente
* (send in .T. to not send email automatically but instead see it in outlook)
ENDWITH
loSession.Signoff()
STORE .NULL. TO loSession, loMessages
RELEASE loSession, loMessages
RETURN .T.
ENDFUNC

RE: Sending e-mail via MAPI to Outlook

Now we get warmer. What is the value of tcTo and is this address part of the Thunderbird Address book of that computer?
Are you even needing to resolve tcTo? This method only is needed, if you try to resolve names (First Last) to mailadresses, you can simply skip that step, if tcTo is a mail address, instead simply set .RecipAddress = tcTo

Bye, Olaf.

RE: Sending e-mail via MAPI to Outlook

(OP)
Olaf:

Interestingly, I just changed error routine you suggested (please see the red error window - "Mensagem de erro")

After I pressed <enter> ("Tecle <enter> ") ro close this error window, the e-mail is sent to the Outbox of the Thunderbird e-mail program.

I have not changed anything more in the program except the error routine.

I cannot understand why this happens. I think it should cancel the execution of the program (now, after I press <enter>) as it had done before!

Thanks,
SitesMasstec

RE: Sending e-mail via MAPI to Outlook

The error is clearly stating the ResolveName routine has thrown an exception. I don't know what you finally used, as I pointed you to several things, but if the error handling ends by continuing the code and it works, then all you need to remove is - as I already said - the call to the ResolveName maethod.

Besides, did you read, what strongm pointed to? It also confirms, what your error handler tells you: ResolveName does not work. There is a hotfix described there, you coudl do, but you don't need to resolve names to mail adresses, you can simply skip that step, remove that line or comment it out.

Bye, Olaf.

RE: Sending e-mail via MAPI to Outlook

Things to do in short:

1. Code change:

CODE

...
WITH loMessages
 .Compose()
 .RecipDisplayName = tcTo
 .RecipAddress= tcTo
 .RecipType = 1
* .ResolveName()
 .MsgSubject = tcSubject
 .MsgNoteText = tcBody
... 

2. Hotfix of Mapi32.dll:
https://support.microsoft.com/en-us/kb/980681

If (1) doesn't work, use (2) and then add back the .ResolveName

Bye, Olaf.

RE: Sending e-mail via MAPI to Outlook

(OP)
Hello Olaf!

Well, I will change code to * .ResolveName(), so it will not be executed and no error will appear.

But what about if in the trap the error routine I put the command:
IF ERROR() = 1429
RETURN
ENDIF

Will it be the same (for the error 1429 -- 'The Automation server is transmitting an error to Visual FoxPro') ?

Thanks,
SitesMasstec

RE: Sending e-mail via MAPI to Outlook

Well, if you do something like that you suppress any OLE error. error 1429 is not so special, all OLE errors throw this VFP error number.
You shouldn't do something like that.

Bye, Olaf.

RE: Sending e-mail via MAPI to Outlook

(OP)
Ok, Olaf, I did not suppressed the error, I used...

in the trap error routine:

IF ERROR() >= 1427 AND ERROR() <= 1429
? "E-mail invalid"
RETURN .F.
ENDIF


And the main program will show for the user: "Problem with sending e-mail to ... " and will not put the e-mail with error in the Outbox

Thanks,
SitesMasstec

RE: Sending e-mail via MAPI to Outlook

Why would someone insist on using a tool that causes so much problem. There are so many other options.

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483: How to get the best response from the forum first.

RE: Sending e-mail via MAPI to Outlook

(OP)
Hello Mike!

I need to use a tool that sends messages with attachments to the Outbox of an e-mail program, so that, after sending the messages, they can be found in the Sent box.

As far as I know, SMTP just sends the messages but doesn't save the mails in any box. And I need the messages saved.

Thank you,
SitesMasstec

RE: Sending e-mail via MAPI to Outlook

OK, then you're not suppressing the error, but doing so for error numbers 1427-1429 is much too general.
Those eror numbers can also happen, when any other OLE error happens with any other OLE class.

If you want to handle error specific to this line you use TRY CATCH here:

CODE

TRY
 .ResolveName()
Catch
  ? "Couldn't resolve name"
EndTry 

Besides you can really say the resolving of names failed instead of displaying a general email error. And again said: You only need this, if you'd like to let tcTo be a real name of a person resolved to the mail address, which then is resolved by a lookup in the address book of the mail client.

> I need the messages saved
As I already said about this feature: You may save the mails you send in your own application for users to refer back to them and know what they sent.

Bye, Olaf.

RE: Sending e-mail via MAPI to Outlook

In regard of error handling, the ideal place to catch errors of MSMAPI.MAPISESSION and MSMAPI.MAPIMESSAGES is within their Error event. But since you can't change these classes, the first step to introduce Error event code is subclassing these OLE classes with VFPs general OLEControl Class:





Then use the myMAPISession in your code or drag it into your form. Of course repeat this , creatiung myMAPIMessages with the Microsoft MAPI Messages Control.

You can actually also use the Ole class from the second dialog directly on your form and then add code to Error, but you'll need to do that again and again for every usage of the Mapisession control. And if you use the control in code you use it as is.

Don't try to cover specific errors via catching certain error numbers in the general error handler, that's not the best idea at least for any OLE errors, because you cover really all OLE errors, also of totally different OLE classes, controls or automation servers and say they are mail errors. You can use general catching of certain error numbers, where they generally apply to every occurrence of that error number, but the OLE errors happen with a wide variety of OCXes and DLLs - well, all of them.

Bye, Olaf.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close