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

Sending automatic emails through unknown email program

Status
Not open for further replies.

ycim

Programmer
Feb 9, 2005
95
CA
I have an smallapplication that gets distributed to clients. I have some code to automatically send through Outlook, which works fabulously (I found it on another thread here!). However, what if my client does not use Outlook as their primary email? Here is the code that I currently use. How can it be modified to accomodate for *unknown* email programs?

Code:
Dim strWAEmail, strWABody, strWASubject As String
    Dim objOutlook As Outlook.Application
    Dim objEmail As Outlook.MailItem
    
    Set objOutlook = CreateObject("Outlook.application")
    Set objEmail = objOutlook.CreateItem(olMailItem)
    
    strWAEmail = "recipient name goes here"
    strWASubject = "Subject of Email"
    strWABody = "Body of email goes here"
    
    With objEmail
    .To = strWAEmail
    .SentOnBehalfOfName = "Team.EmailAddress@work.com"
    .Subject = strWASubject
    .Body = strWABody
    .Importance = olImportanceHigh
    .Send
    End With
    
    Set objEmail = Nothing
    
    MsgBox "message sent"
 
Yes...but then I am back to receiving the annoying "trying to send on behalf..." message which I am trying to avoid!

This code does not seem to bring up that message at all. (which is a whole different thread!)
thread705-1343702
 
I do not think you can resolve both problems. If you are distributing to an unknown site with an unknown email program, I think the users will want to know that an email is being sent.
 
How about if I have the system detect Outlook as the default mail editor? If it is not, then I do not allow the emailing. If it is, then all is good.

The problem is that I don't know how to automatically detect the default email program.

Any suggestions?
 
How about a solution that doesn't rely on the user's email program?
I have successfully used a freeware DLL called vbSendMail.dll in several of my VB apps. The code is freely distributed. You need to set a few properties, the most important being the name of an SMTP server the user has access to.

I don't have a link handy, but should be easy enough to find with Google.


 
Sweet! I will try that and let you know how it goes! Thanks for the tip!
 
Thanks, guys. I am currently looking for a solution to the same sort of problem.

I just downloaded the vbSendMail package and tried it to see what I could do. Unfortunately, the first thing I got was a pop-up saying

Failed to load control "winsock" from MSWINSCK.OCX. Your version of MSWINSCK.OCX may be outdated. Make sure you are using the version of the control that was provided with your application."

followed by another, similar dialog indicating "Run-time error '372'"

Interestingly, the copy of vbSendMail.dll in vbSendMail.zip seems to have been created in 2003 and the copy of MSWINSCK.OCX in my c:\windows\system32 directory is dated 12/12/1996 even though I have Win XP SP2 and Visual Studio 2005. Any thoughts on where I might look to find the correct version of MSWINSCK.OCX?

Thanks,
Paul
 
Why not simply use CDO ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
PHV - unless CDO has changed over the years since I last used it, isn't it used in a Microsoft Exchange environment? The OP's original problem is that he needs to be able to send emails regardless of whether the user has Outlook installed. And if he doesn't have Outlook, chances are it's not a MS Exchange environment.

 
CDO may be used if you know the address of your smtp provider.
 
A starting point:
Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = "your subject here"
objMessage.Sender = "sendername@somedomain.com"
objMessage.To = "somename@domain.com"
objMessage.TextBody = "your body text here"
With objMessage.Configuration.Fields
.Item(" = 2
.Item(" = "smtp.someserver.com"
.Item(" = 25
.Update
End With
objMessage.Send
 
I even found a FAQ:
faq181-5705

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks for the discussion on CDO. I didn't even know about this. PHV, the code looks great and I can't wait to try it out.

Thanks to everyone for your help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top