Click to See Complete Forum and Search --> : Look out outLook
PJMAXX
Oct 22nd, 2002, 08:24 PM
I've been searching msdn and here among a few other places,
but can't seem to find any consistant info on out look so I'll
just ask a few Questions that maybe someone can help me with.
First of all I have about 6 machines running outlook 97 and Up
(Outlook2002).This seems to be a problem when trying to
write code to do a simple email....
MAPI seems to work well for early versions
But I get errors with newer versions...
I used a object lib. but that gives me problems with early versions.
What is the best way to email with so many versions?
What about late binding? Is That posible?
This is really driving me nutz
Thanks for any help.
PJ
alex_read
Oct 23rd, 2002, 02:44 AM
Are you using createobject() to create your Outlook references?
This is what I use for E-Mailing from Outlook if it helps you, rather than call on Outlook itseelf, I use the MAPI controls. From your project menu, goto the references option & change the drop down box to view *.ocx files. In your system directory, you'll have a MSMAPI32.ocx file which you'll need to add in to get this to work.
EDIT: removed attachment and personal E-mail addresses.
Attribute VB_Name = "basCommon"
Option Explicit
' Constant values used within the E-Mail setup.
Private Const cstrEMAILRECIEVER As String = "someone@somewhere.com"
Private Const cstrEMAILSUBJECT As String = "Alert: UPS Battery Is Running!"
Private Const cstrEMAILBODY As String = "Mains power has been tripped and the UPS battery is now in operation."
Private Const cstrMAPIPROFILENAME As String = "MsOutlook profile1 name"
Private Const cstrMAPIPROFILEPASSWORD As String = "MsOutlook profile1 password"
Public Sub SendEMail()
' **** Sends an E-Mail using the above constant variables to a specified user. ****
Dim objMAPISession As MAPISession
Dim objMAPIMessages As MAPIMessages
' Attempt to create a new MAPI session object on the local pc. The session properties are then setup in the following order:
' DownLoadMail is set to avoid accessing the users inbox & message list.
' LogonUI is set to avoid flashing the profile selection box to the user on startup to allow a specified entry.
' The UserName and Password of a MAPI logon (i.e. existing MsOutlook profile in this case are then set (MS.com Q180172).
' Finally, this MAPI Session information structure is taken and used to logon to the MAPI E-Mail server / Outlook with.
Set objMAPISession = New MAPISession
If Not (objMAPISession Is Nothing) Then
With objMAPISession
.DownLoadMail = False
.LogonUI = False
.UserName = cstrMAPIPROFILENAME
.Password = cstrMAPIPROFILEPASSWORD
.SignOn
End With
' Once a logged on session has been established, a messaging object can then be setup. The following creates a new
' message, and passing in the constant variables declared above, sets out the recipient, subject and body details in
' this new mail message. The resolve method is called to check the current recipient mail address is actually valid,
' then the send method sends this E-Mail out without a confirmation messagebox being shown to the user.
Set objMAPIMessages = New MAPIMessages
If Not (objMAPIMessages Is Nothing) Then
With objMAPIMessages
.SessionID = objMAPISession.SessionID
.Compose
.MsgSubject = cstrEMAILSUBJECT
.RecipIndex = 0
.RecipType = mapToList
.RecipAddress = cstrEMAILRECIEVER
.ResolveName
.MsgNoteText = cstrEMAILBODY
.Send vDialog:=False
End With
' Finally the object variables are cleared from the PC's memory as they are no longer needed, the resources these
' variables were using will speed up excecution of other system processes and this will avoid memory leaks.
Set objMAPIMessages = Nothing
End If
objMAPISession.SignOff
Set objMAPISession = Nothing
End If
End Sub
PJMAXX
Oct 23rd, 2002, 06:09 AM
Dim ol As Object 'Outlook.Application
Dim olMail As Object ' Outlook.MailItem
Dim ma As Object
Set ol = CreateObject("Outlook.Application")
Set olMail = ol.CreateItem(0)
olMail.Recipients.Add Text1.Text
olMail.Subject = Text2.Text
olMail.Body = Text3.Text
olMail.Importance = olImportanceHigh
olMail.Send
Set olMail = Nothing
ol.Quit
Set ol = Nothing
Or
MAPISession1.SignOn
MAPISession1.UserName = Text6.Text
MAPISession1.Password = Text7.Text
MAPISession1.DownLoadMail = False
MAPIMessages1.SessionID = MAPISession1.SessionID
MAPIMessages1.Compose
If Text1.Text <> "" Then
MAPIMessages1.RecipDisplayName = Me.Text1
Else
MAPIMessages1.Show
End If
MAPIMessages1.AddressResolveUI = False
MAPIMessages1.MsgSubject = Me.Text2
MAPIMessages1.MsgNoteText = Me.Text3.Text
MAPIMessages1.ResolveName
MAPIMessages1.Send False
MAPISession1.SignOff
These two I have tried among others......
Thanks for the reply......
pj
alex_read
Oct 23rd, 2002, 06:53 AM
Are you creating a proper setup package with this program when you distribute it?
What errors do you catually get?
PJMAXX
Oct 23rd, 2002, 05:09 PM
My code is working (MAPI)
Except those pesty Prompts ..
For profile
An app is trying to use an email addy thats entered in outlooks
contacts folder.
and
an app is trying to send email on your behalf.
Your Module give me an error on this line
Set objMAPIMessages = New MAPIMessages
Error is : Invalid use of new keyword.
alex_read
Oct 25th, 2002, 04:30 AM
For the second bit, I guess you could try either deleting the new keyword or removing the statement setting it altogether (as well as the if statement to check if the messages object is set to nothing). That's weird as I don't get this problem.
What version of vb are you using? If this is learning or professional edition, you could check this site out:
http://support.microsoft.com/default.aspx?scid=KB;EN-US;q194751
For the first one, you can write this inside an NT service project. If you aren't installing this on a win9x platform, you can add-in the MS control to run the app as a service which supresses all messages from appearing when it sends the e-mail:
http://support.microsoft.com/default.aspx?scid=KB;EN-US;Q170883&
PJMAXX
Oct 25th, 2002, 06:31 PM
I'm Using VB6 Enterprise....
I'll try those Idea's.
Thanks, PJ
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.