send mail thru VB 6.0 app - will work with OUTLOOK & OUTLOOK EXPRESS

i am trying to send an email using the CLIENT'S default mail program (either OUTLOOK or OUTLOOK EXPRESS)

must open email so they can alter subject, text, attachment, etc. before sending mail

i have tried MAPI, but it does not like OUTLOOK EXPRESS and gets an error 19 (invalid MAPI session) whenever the machines default mail program is OUTLOOK EXPRESS.

any ideas ?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Do you _have_ to use Outlook/OE to do it for you? There is a standalone mailing/smtp control that you could use to accomplish this. You could create your own form for editing the email, and then use the control to actually send it, without involving OE/Outlook. The reason I say this is because you'll also run into problems if their default email program is Eudora or something else. It's best if you have control over the entire process. But if this isn't plausible, then we can help further...
kevman63Author Commented:
i would prefer to send it using the default mail client on there machine, so they could see it in SENT items history...

the biggest problem is MAPI.  works one way for OUTLOOK, works another way for OE.

with the  standalone mailing/smtp control do i have to have the user run a setup at all ?  mainly we want to keep it as simple as possible - users clicks button, email pops up to with these filled in:
 <attachment> (optional)

using default mail client seems ideal, "But if this isn't plausible, then we can help further..."

anymore help would be appreciated...

MS KB article that does NOT help:;EN-US;315458
Hmm... I simply don't think that is going to work, then. Yes, it would be probably be nice to have it in Sent Items, so they could archive emails that are sent. If this is neccessary, then you can do one of two things:
1) Require then to use Outlook. BAD Idea.
2) Use the DLL I'm about to give you, and simply send an additional copy to the person's email address, and include a subject line or sender they can filter on (they can filter it into their sent mail folder or another folder).

Check this out:

I've used that DLL for some of my applications. It supports attachments, which is key. It is very easy to use. So easy, in fact, that you can create your own mail client within an hour.

The only thing it requires as far as setup is this: 1) You need to register the DLL in your program's setup, or create a script that registers the dll for them (regsvr32 "C:\Path\vbSendMail.dll"), and 2) You'll need to know their smtp server name, login information, and email address. I'm even pretty sure that if their email server doesn't require logins, then all you need is their email address (it will look up the rest). You may experiment with searching for these settings in the registry. Perhaps OE/Outlook stores them in a place you can access. Alternatively, if you can locate a "free" smtp server, you can have it automatically send through that, so that you don't even need those settings.

This is a pretty solid DLL, it's been around for a few years. I've had no problems with it. I would reccommend this route. Like I said, you can always provide them the option to forward it to their own email address with a filterable subject line or something. And if they need to edit the information in any way, you can create a form that looks like the OE/Outlook mail sender, with just what they need to be able to edit. It wouldn't be difficult at all.

It includes great documentation, two example executables, and the source code. In fact, if you load the code up into your project, you won't even need to have them register the separate DLL; simply compile it into your software.

Again, this seems right to me, but only you know what functionality you really need, so take this with a grain of salt. :)
Active Protection takes the fight to cryptojacking

While there were several headline-grabbing ransomware attacks during in 2017, another big threat started appearing at the same time that didn’t get the same coverage – illicit cryptomining.

I have done this in both VB6 and Access97.  I can put the code up here tomorrow if you would like.
In Access97 (likely the same in 2000) you use the following
Dim sendTo as string
Dim sendSubject as string
Dim sendMsgText as string

DoCmd.SendObject acSendNoObject, , , sendTo, , , sendSubject, sendMsgText, False

Here is the code I use in VB (basically)
Create a standard .exe and place a command button on the form - then paste this code into the form.
Goto Projects/References/Browse and set a reference to C:\Program Files\Microsoft Office\Office\msotl85.olb

Private Declare Function GetUserName Lib "advapi32" _
   Alias "GetUserNameA" _
  (ByVal lpBuffer As String, _
   nSize As Long) As Long

Private Declare Function lstrlenW Lib "kernel32" _
  (ByVal lpString As Long) As Long

Private Const MAX_USERNAME As Long = 15

Private Function GetLocalUserName() As String

  'return the name of the user
   Dim tmp As String

   tmp = Space$(MAX_USERNAME)

   If GetUserName(tmp, Len(tmp)) Then
      GetLocalUserName = TrimNull(tmp)
   End If

End Function

Private Function TrimNull(startstr As String) As String

   TrimNull = Left$(startstr, lstrlenW(StrPtr(startstr)))
End Function

Private Sub MailMain()
Dim myOlApp As Outlook.Application
Dim myItem As MailItem
Dim myAttachments As Attachments
Dim MyItemSize As Long
Dim sUserName As String

    Set myOlApp = CreateObject("Outlook.Application")
    Set myItem = myOlApp.CreateItem(olMailItem)
    Set myAttachments = myItem.Attachments

    ' get username - not required
    sUserName = GetLocalUserName()
    'add subject text
    myItem.Subject = "Message from " & sUserName
    'add body text
    myItem.Body = "Anything you want"

End Sub

Private Sub Command1_Click()

    Call MailMain

End Sub
One more thing;
The Reference Type Library above is For "OUTLOOK" which comes with MS Office. You may need to search for a different reference type library If you use "Outlook Express".

Enjoy - bdb
kevman63Author Commented:

many thanks for the vb project group - very nice work... is there any way to automatically get the SMTP server IP # ?
You shouldn't need the IP address for this module, though there are ways to find it (search around on Google for using VB to find IP addresses of servers). In fact, it includes the code needed for those lookups, just in case you're curious (check out the archive in that folder). The code has a property SMTPHost that should accept a text version of the server, like: I suggest wading through the example programs, as well as the .doc documentation file, as it has a wealth of information about it. For your purposes, you can probably get by with the introductory code of that manual, as you'll only likely be needing basic functionality. I'm pretty sure this will be a much easier solution than the MAPI method or hooking to the Outlook/OE libraries. Plus, you won't run into version dependencies (since different people have different versions of software), which will save you a lot of headache. Just remember that whenever possible, keep your code as self-contained as it can be. It makes everyone happier in the end :)

Let me know if you need more assistance with it...
kevman63Author Commented:

ok, one MAJOR stumbling block, but i think we can get past it:

when i run in VB environment, no problem, works great.

when i compile and run EXE, get error # 429 - ActiveX Component cannot create object - and EXE fails

any thoughts ?  do DLL's need to be in System - System32 folder ?

HELP!  i'm sooooooo close!
kevman63Author Commented:
nevermind, read DOCS (duh!) and registered that crafty little DLL!
Ugh, I hate that error so much...

It may not have to be in the system/system32 folders, but you'll probably need to register the DLL...
> regsvr32 "C:\path\dll_location.dll"

Another thing that will work _better_ is if you put the actual class module in your project instead of referencing the dll. This way, you don't have to worry with "dll hell" as we like to call it. DLLs are great in theory, but always cause problems. So my suggestion would be to remove your reference in your project, put the actual code modules in there, and have it be part of your executable. But registering it should solve your immediate problem...
kevman63Author Commented:
not sure what you mean by this:  "put the actual class module in your project instead of referencing the dll."

i am all too familiar with DLL/OCX hell, but i goto PROJECT - REFERENCES and see nothing about that dll, only the standard stuff you get with a VB windows app...

In the root folder of the vbSendMail project, you'll see three files: SendMail.cls, modMXQuery.bas, and frmSck.frm. You need to put these three files in your project (Project-> Add File). Once they are in your project, you'll have no problems with referencing that DLL. That should solve all your problems.

Or, you can still use the DLL method. You'd just have to make sure that it gets registered on every user's machine first...
kevman63Author Commented:
ok, here is how it is now:

the zip i downloaded had a project GROUP, and includes the above files in a different projecyt, but still part of the group (this was how it came, i never use groups)

when i removed that project and tried to add above files to a single project, tells me "SendMail.cls cannot be made public - will bve private" - needless to say app fails when you try to run it...

i appreciate your help, and rest assured, you're going to get these points... !
Hmm, it should be ok. I'm assuming you're making a standalone executable? It doesn't have to be public if it is within the program.

How are you instantiating your clsSendMail object? Are you still using "Private WithEvents poSendMail as vbSendMail.clsSendMail"? If so, you need to reference the class by clsSendMail, not vbSendMail.clsSendMail. Also, make sure you're copying the files above to your own directory, not referencing the files that are already there. Let me know if that solves the issues... It works on my end, so we'll keep working until you're all set...
kevman63Author Commented:
"you need to reference the class by clsSendMail, not vbSendMail.clsSendMail"


thanks alot, that works great!

BTW - even with no attachment, it takes at least 5-6 seconds to go from 22/23 % to 100% - my boss is telling me that is too long!!! - any idea ?  if not, no biggy... he can just learn patience!

i'm gonna keep this for app for myself, if you want i'll send you the finished result... its mostly your work anyway ;->
Hmm, I can't think of any reason it'd be slowing down, unless your connection is slow or your SMTP server is slow. It may also speed it up if you use it's IP address instead of domain name (so it doesn't have to do the lookup). Other than that, I can't think of anything that would be bogging it down. Mine is pretty quick because I run my own free smtp server (, so if he really needs speed, that may be an option. You may try and see if the DLL option works faster; I don't see why it would, but you never know.

And good to hear it at least works! vbSendMail is a pretty nifty tool; I use it to send error logs back to me from the software I write, so I know exactly what is going on with it. And yeah, I'd like to see what you've got; it'd be cool (david AT frictionlessfloor DOT com). Let me know if you need anything else!

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
can vbSendMail auto search for a free smtp server?
or do i have to manually set one for it?
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.