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 mail through outlook.application 1

Status
Not open for further replies.

kmjpr

Programmer
Feb 1, 2002
12
IN
hi
i hae microsift outlook 97 installed on my system. when i include microsoft outlook 8.0 reference and write this peice of code. the vb application shows no error but the mail never reaches out to its destination.
Dim AppOutlook As Outlook.Application
Dim objmail As Outlook.MailItem

Private Sub Form_Load()
Set AppOutlook = CreateObject("Outlook.application")
Set objmail = AppOutlook.CreateItem(olMailItem)

aa.To = "test@test.com"
aa.Subject = "test"
aa.Body = "hello"
aa.Send

End Sub
any help
 
It looks like yo've grabbed this code from two different sources as your declarations don't match your variables used.

If you use Option Explicit in the Declarations section of each form you may avoid this.

Try this

Dim appoutlook As Outlook.Application
Dim objmail As MailItem
Set appoutlook = CreateObject("Outlook.application")
Set objmail = appoutlook.CreateItem(olMailItem)

objmail.To = "test@test.com"
objmail.Subject = "test"
objmail.Body = "hello"
objmail.Send
Set appoutlook = Nothing
Let me know if this helps
________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'There are 10 kinds of people in the world: those who understand binary, and those who don't.'
 
hi johnwm
thnaks for answering ..yeah u r quite right.. i messed up the code but anyhow... i tried ur code but again the same result .. this peice of code gives no error but the mail never reaches my mailbox...
bye
 
Have you checked in Outlook that you're set up to send automatically?
Check Outlook/Tools/Options/Mail Setup/Send Immediately when connected.
Also Automatically dial during a background Send/Receive
The above code does work for me. Let me know if this helps
________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'There are 10 kinds of people in the world: those who understand binary, and those who don't.'
 
I tried this code just as a test and I get a compliler error (invalid outside procedure)on the keyword SET for:
Set appoutlook = CreateObject("Outlook.application")
I have made reference to outlook 9.0.
Any ideas?
 
Where have you pasted this code?
The code as posted should be used in a procedure, for example the Click Event of a CommandButton Let me know if this helps
________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'There are 10 kinds of people in the world: those who understand binary, and those who don't.'
 
hi johnwm
hello again , i didn't find any option known as 'Mail Setup/Send Immediately when connected' in Outlook/tools/options.
also i opened outlook and i found all my messages there in the inbox . every message has a error statement saying - ' No transport provider was available for delivery to this recipient'
what is this error . how can i over come it . and where is that mail Setup option described by you( remember i have outlook 97 installed on my system)...
bye and thanks
 
hi johnwm
just one point .. i'm trying to use outlook 97 and not outlook express . is that my error..
bye
 
At least the messages are getting into Outlook!

So the problem is with settings in Outlook97. Sorry I haven't got 97 on any of my machines available at this moment. I'll try and find one tomorrow.

It sounds like we're looking for a 'connect on demand' setting of some kind Let me know if this helps
________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'There are 10 kinds of people in the world: those who understand binary, and those who don't.'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top