Results 1 to 7 of 7

Thread: Look out outLook

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2001
    Posts
    152

    Look out outLook

    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
    My software never has bugs. It just develops random features.

  2. #2
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    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.

    Code:
    Attribute VB_Name = "basCommon"
    Option Explicit
    
    ' Constant values used within the E-Mail setup.
    Private Const cstrEMAILRECIEVER As String = "[email protected]"
    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
    Last edited by alex_read; Jul 25th, 2008 at 02:28 AM.

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Aug 2001
    Posts
    152
    Code:
    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
    My software never has bugs. It just develops random features.

  4. #4
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    Are you creating a proper setup package with this program when you distribute it?

    What errors do you catually get?

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Aug 2001
    Posts
    152
    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

    Code:
    Set objMAPIMessages = New MAPIMessages

    Error is : Invalid use of new keyword.
    My software never has bugs. It just develops random features.

  6. #6
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    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...;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...EN-US;Q170883&

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Aug 2001
    Posts
    152
    I'm Using VB6 Enterprise....
    I'll try those Idea's.

    Thanks, PJ
    My software never has bugs. It just develops random features.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width