Solved

Send Email Using Outlook Express

Posted on 2002-06-04
19
1,165 Views
Last Modified: 2007-12-19
Hello All.

Set objOutlook = CreateObject("Outlook.Application")
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)

I use the code above to send email using Access 2000 and Outlook 2000.

I need to know what changes need to be made so that I can use Outlook Express with Access 97 on Windows 95.

Thanks
WonHop



0
Comment
Question by:WonHop
  • 8
  • 5
  • 5
  • +1
19 Comments
 
LVL 2

Expert Comment

by:Yoink
Comment Utility
WonHop, is the Outlook Express library referenced in Access97?
0
 
LVL 2

Author Comment

by:WonHop
Comment Utility
I don't think so.  It is on my home computer.  So chances are, it is not.  I was going to try to set it up tonight and I was trying to head off any pitfalls by setting everything up like I have it here at work with MS 2000.

WonHop
0
 
LVL 2

Expert Comment

by:Yoink
Comment Utility
If you open up a module, click on <Tools>, <References>, then scroll down until you find the MS Outlook library.
0
 
LVL 2

Expert Comment

by:Yoink
Comment Utility
WonHop, is the Outlook Express library referenced in Access97?
0
 
LVL 2

Author Comment

by:WonHop
Comment Utility
Thanks...Will I need to change:
Set objOutlook = CreateObject("Outlook.Application")
To
Set objOutlook = CreateObject("Outlook Express.Application")?

WonHop
0
 
LVL 2

Expert Comment

by:Yoink
Comment Utility
No, I do not believe you will have to make that change.
0
 
LVL 2

Author Comment

by:WonHop
Comment Utility
Great.  Thanks.  I will try it tonight.

WonHop

0
 
LVL 2

Expert Comment

by:Yoink
Comment Utility
Good luck!  {:>)
0
 
LVL 4

Expert Comment

by:Nevaar
Comment Utility
Sending via Outlook Express isn't that straight forward since it's not a "REAL" MAPI client.

I've made it work with Outlook Express.  I won't be able to post the code until this evening (Eastern US time).

It's not a simple modification to the Outlook way of doing things.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 2

Author Comment

by:WonHop
Comment Utility
Thanks Nevaar.

Yoink:  I did not see Outlook Express in the References on my home machine.  I did see it on a machine here at work.
I have Windows 95 and they have Windows 98.

Thanks
WonHop
0
 
LVL 4

Accepted Solution

by:
Nevaar earned 200 total points
Comment Utility
Here's the basic declarations and code.  I pieced it together from some info on Experts-exchange, a web site here and there.  Hope it helps.

Declare the following constants, types and external functions in a Module
NOTE: The external declarations must be hard-coded to the location of the Outlook Express DLL.
I haven't been able to work around that.

-------------------------------------------------------------------
' Outlook Express Declarations below:
'**************************
' CONSTANT Declarations
'**************************
Global Const SUCCESS_SUCCESS = 0
Global Const MAPI_USER_ABORT = 1
Global Const MAPI_E_FAILURE = 2
Global Const MAPI_E_LOGIN_FAILURE = 3
Global Const MAPI_E_DISK_FULL = 4
Global Const MAPI_E_INSUFFICIENT_MEMORY = 5
Global Const MAPI_E_BLK_TOO_SMALL = 6
Global Const MAPI_E_TOO_MANY_SESSIONS = 8
Global Const MAPI_E_TOO_MANY_FILES = 9
Global Const MAPI_E_TOO_MANY_RECIPIENTS = 10
Global Const MAPI_E_ATTACHMENT_NOT_FOUND = 11
Global Const MAPI_E_ATTACHMENT_OPEN_FAILURE = 12
Global Const MAPI_E_ATTACHMENT_WRITE_FAILURE = 13
Global Const MAPI_E_UNKNOWN_RECIPIENT = 14
Global Const MAPI_E_BAD_RECIPTYPE = 15
Global Const MAPI_E_NO_MESSAGES = 16
Global Const MAPI_E_INVALID_MESSAGE = 17
Global Const MAPI_E_TEXT_TOO_LARGE = 18
Global Const MAPI_E_INVALID_SESSION = 19
Global Const MAPI_E_TYPE_NOT_SUPPORTED = 20
Global Const MAPI_E_AMBIGUOUS_RECIPIENT = 21
Global Const MAPI_E_MESSAGE_IN_USE = 22
Global Const MAPI_E_NETWORK_FAILURE = 23
Global Const MAPI_E_INVALID_EDITFIELDS = 24
Global Const MAPI_E_INVALID_RECIPS = 25
Global Const MAPI_E_NOT_SUPPORTED = 26

Global Const MAPI_E_NO_LIBRARY = 999
Global Const MAPI_E_INVALID_PARAMETER = 998

Global Const MAPI_ORIG = 0
Global Const MAPI_TO = 1
Global Const MAPI_CC = 2
Global Const MAPI_BCC = 3

Global Const MAPI_UNREAD = 1
Global Const MAPI_RECEIPT_REQUESTED = 2
Global Const MAPI_SENT = 4


'***********************
' FLAG Declarations
'***********************
Global Const MAPI_LOGON_UI = &H1
Global Const MAPI_NEW_SESSION = &H2
Global Const MAPI_DIALOG = &H8
Global Const MAPI_UNREAD_ONLY = &H20
Global Const MAPI_ENVELOPE_ONLY = &H40
Global Const MAPI_PEEK = &H80
Global Const MAPI_GUARANTEE_FIFO = &H100
Global Const MAPI_BODY_AS_FILE = &H200
Global Const MAPI_AB_NOMODIFY = &H400
Global Const MAPI_SUPPRESS_ATTACH = &H800
Global Const MAPI_FORCE_DOWNLOAD = &H1000

Global Const MAPI_OLE = &H1
Global Const MAPI_OLE_STATIC = &H2

Type MAPIRecip
  Reserved As Long
  RecipClass As Long
  Name As String
  Address As String
  EIDSize As Long
  EntryID As Long 'Originally String
End Type

Type MAPIFileTag    'Not used at all now
  Reserved As Long
  TagLength As Long
  Tag() As Byte
  EncodingLength As Long
  Encoding() As Byte
End Type

Type MAPIFile
  Reserved As Long
  Flags As Long
  Position As Long
  PathName As String
  FileName As String
  FileType As Long 'Originally MAPIFileTag
End Type

Type MAPIMessage
  Reserved As Long
  Subject As String
  NoteText As String
  MessageType As String
  DateReceived As String
  ConversationID As String
  Flags As Long       ' Swapped with Originator
  Originator As Long  ' Swapped with Flags
  RecipCount As Long
  Recipients As Long
  FileCount As Long   ' Swapped with Files
  Files As Long       ' Swapped with Filecount
End Type

Declare Function MAPILogon Lib "c:\program files\outlook express\msoe.dll" _
                                (ByVal UIParam&, ByVal User$, ByVal Password$, _
                                ByVal Flags&, ByVal Reserved&, Session&) As Long
Declare Function MAPILogoff Lib "c:\program files\outlook express\msoe.dll" _
                                (ByVal Session&, ByVal UIParam&, ByVal Flags&, _
                                ByVal Reserved&) As Long
Declare Function MAPISaveMail Lib "c:\program files\outlook express\msoe.dll" _
                                (ByVal Session As Long, ByVal UIParam As Long, _
                                message As MAPIMessage, ByVal Flags As Long, _
                                ByVal Reserved As Long, MsgID As String) As Long
Declare Function MAPISendMail Lib "c:\program files\outlook express\msoe.dll" _
                                (ByVal Session As Long, ByVal UIParam As Long, _
                                message As MAPIMessage, ByVal Flags As Long, _
                                ByVal Reserved As Long) As Long
Declare Function MAPIAddress Lib "c:\program files\outlook express\msoe.dll" _
                                (lInfo&, ByVal Session&, ByVal UIParam&, _
                                Caption$, ByVal nEditFields&, Label$, nRecipients&, Recip() _
                                As MAPIRecip, ByVal Flags&, ByVal Reserved&) As Long
Declare Function MAPIDeleteMail Lib "c:\program files\outlook express\msoe.dll" _
                                (ByVal Session&, ByVal UIParam&, ByVal MsgID$, _
                                ByVal Flags&, ByVal Reserved&) As Long
Declare Function MAPIDetails Lib "c:\program files\outlook express\msoe.dll" _
                                (ByVal Session&, ByVal UIParam&, Recipient As MAPIRecip, _
                                ByVal Flags&, ByVal Reserved&) As Long
Declare Function MAPIFindNext Lib "c:\program files\outlook express\msoe.dll" _
                                 (ByVal Session&, ByVal UIParam&, MsgType$, SeedMsgID$, _
                                 ByVal Flag&, ByVal Reserved&, MsgID$) As Long
Declare Function MAPIReadMail Lib "c:\program files\outlook express\msoe.dll" _
                                (lMsg&, nRecipients&, nFiles&, ByVal Session&, _
                                ByVal UIParam&, MessageID$, ByVal Flag&, _
                                ByVal Reserved&) As Long
Declare Function MAPIResolveName Lib "c:\program files\outlook express\msoe.dll" _
                                (ByVal Session&, ByVal UIParam&, ByVal UserName$, _
                                ByVal Flags&, ByVal Reserved&, Recipient As MAPIRecip) As Long
Declare Function MAPISendDocuments Lib "c:\program files\outlook express\msoe.dll" _
                                (ByVal UIParam&, ByVal DelimStr$, ByVal FilePaths$, _
                                ByVal FileNames$, ByVal Reserved&) As Long


-------------------------------------------------------------------

The following is the operational code


Dim Junk as Long
Dim strEmailAddress As String
Dim OESession     As Long
Dim OEmessage     As MAPIMessage
Dim OERecipients() As MAPIRecip
Dim OEFiles()      As MAPIFile
Dim OERecipientCount As Long
Dim OEFileCount As Long
ReDim OERecipients(0 To 100)
ReDim OEFiles(0 To 10)


' Login to Outlook Express
MAPILogon 0, "", "", MAPI_NEW_SESSION, 0, OESession


' Set subject and message text
OEmessage.NoteText = "BODY TEXT"
OEmessage.Subject = "SUBJECT TEXT"
   
' Set recipient address (assuming only one)
OERecipients(0).RecipClass = MAPI_TO
OERecipients(0).Address = StrConv("smtp:" & strEmailAddress, vbFromUnicode)
OERecipientCount = 1
ReDim Preserve OERecipients(0 To OERecipientCount - 1)
OEmessage.RecipCount = OERecipientCount
OEmessage.Recipients = VarPtr(OERecipients(0))

' Attach any files (assuming only one)
OEFileCount = 1
OEFiles(0).PathName = StrConv(strFilename, vbFromUnicode)
OEFiles(0).FileName = StrConv("DISPLAY FILE NAME", vbFromUnicode)
ReDim Preserve OEFiles(0 To OEFileCount - 1)
OEmessage.FileCount = OEFileCount
OEmessage.Files = VarPtr(OEFiles(0))

' Send the message
junk = MAPISendMail(0, 0, OEmessage, 0, 0)
If junk <> 0 Then MsgBox "OE SendMail failure (" & Format$(junk) & ")"


0
 
LVL 4

Expert Comment

by:Nevaar
Comment Utility
I forgot to mention this. I use the code on Access 2000, but I don't see any real reason that it shouldn't work on Access 97.
0
 
LVL 2

Author Comment

by:WonHop
Comment Utility
Thanks Vevaar.
NOTE: The external declarations must be hard-coded to the location of the Outlook Express DLL.
I haven't been able to work around that.
   Sad to say but I have never gotten into coding to or really with dll's.  
How would I code what you have mentioned.  What part of the code is it and what is the dll's name?

Thanks
0
 
LVL 4

Expert Comment

by:Nevaar
Comment Utility
The DLL should be MSOE.DLL
0
 
LVL 2

Author Comment

by:WonHop
Comment Utility
Thanks Vevaar.  I will try it tonight.
0
 
LVL 2

Author Comment

by:WonHop
Comment Utility
Nevaar.  How are you doing.  The code worked perfectly!!!!
Thanks a lot.

I increased the point to 200.

Thanks

WonHop
0
 
LVL 2

Author Comment

by:WonHop
Comment Utility
Thanks a lot.

WonHop
0
 

Expert Comment

by:luckie
Comment Utility
Hi, Nevaar
   With MAPI32.dll how do you send two attached files? I will open up another question when I hear your response. Thanks
Jacky Luk (luckie)
email: luckie@netvigator.com

here is the code:

 Dim oMsg(500) As MAPIMessage
    Dim oRecipients(500) As MapiRecip
    Dim oAttachments(2) As MapiFile
    Dim lSession As Long
    Dim lResult As Long
    Dim db As Database
    Dim rs As Recordset
    Dim strSQL As String
    Dim i As Integer
    Dim j As Integer
   
   
    Set db = CurrentDb
    strSQL = "Select * from HKLTS_Contact_People"
   
    Set rs = db.OpenRecordset(strSQL)
   
    ' Logon
    lResult = MAPILogon(0, "", "", MAPI_LOGON_UI + MAPI_NEW_SESSION, 0, lSession)
   
    If lResult <> 0 Then
        MsgBox "Logon failed. Result = " & lResult
        Exit Sub
    End If
   
   
    'stick attachments
    With oAttachments(0)
       .PathName = "C:\bpcontacts\1.txt"
       .FileName = "Demo.txt"
   End With
   
    With oAttachments(1)
        .PathName = "C:\bpcontacts\error.bmp"
        .FileName = "1.txt"
   End With
   
 

    ' Fill out the recipient
    i = 0
    rs.MoveFirst
    Do While Not rs.EOF
       ' Fill out the message
    With oMsg(i)
        .Reserved = 0
       
        .NoteText = "To : " & rs!companyname & Chr(10) & Chr(13) & _
        "Dear " & rs!firstname & " " & rs!lastname & Chr(10) & Chr(13) & Chr(10) & Chr(13) & _ .....
 



 
        .FileCount = 2  'no attachments
        .RecipCount = i + 1 'only 1 recipient
        .Subject = "Dear Customer"
       
       
    End With

   
   
    With oRecipients(i)
        ' TODO: Change "test@online.microsoft.com" to the address you want to send to
        .Name = rs!emailaddress
        .RecipClass = MAPI_TO
        .Reserved = 0
    End With
   
    lResult = MAPIResolveName(lSession, 0, oRecipients(i).Name, 0, 0, oRecipients(i))
   
    If lResult <> 0 Then
        MsgBox "MAPIResolveName failed. Result = " & lResult
        Exit Sub
    End If
   
   
    i = i + 1
    rs.MoveNext
    Loop
   
  '  For j = i To 1 Step -1
    ' Next j

   
   
    ' Send the message
 '   For i = 0 To 1
     
    lResult = MAPISendMail(0, 0, oMsg(1), oRecipients, oAttachments, 0, 0&)
'    Next i
   
   
    If lResult = 0 Then
        MsgBox ("Message sent!")
    Else
        MsgBox "Message not sent! Result = " & lResult
    End If
     
    ' Log off
    lResult = MAPILogoff(lSession, 0, 0, 0)
   
    If lResult <> 0 Then
        MsgBox "Logoff failed. Result = " & lResult
    End If

End Sub



the following has resulted:
Global Const MAPI_E_FAILURE = 2
Thanks

0
 
LVL 4

Expert Comment

by:Nevaar
Comment Utility
You mentioned an errors code of 2.  On which line of code did it explode?

BTW, while I haven't used the MAPI32 function, I found something on A1VBCode.com which may help you. Basically, the function declarations are different. Also there's a slight difference in the MAPIFile type structure which may explain your error.

======================================================
Global Const MAPI_E_AMBIG_RECIP = MAPI_E_AMBIGUOUS_RECIPIENT
Global Const MAPI_E_AMBIGUOUS_RECIPIENT = 21
Global Const MAPI_E_ATTACHMENT_NOT_FOUND = 11
Global Const MAPI_E_ATTACHMENT_OPEN_FAILURE = 12
Global Const MAPI_E_ATTACHMENT_WRITE_FAILURE = 13
Global Const MAPI_E_BAD_RECIPTYPE = 15
Global Const MAPI_E_BLK_TOO_SMALL = 6
Global Const MAPI_E_DISK_FULL = 4
Global Const MAPI_E_FAILURE = 2
Global Const MAPI_E_INSUFFICIENT_MEMORY = 5
Global Const MAPI_E_INVALID_EDITFIELDS = 24
Global Const MAPI_E_INVALID_MESSAGE = 17
Global Const MAPI_E_INVALID_RECIPS = 25
Global Const MAPI_E_INVALID_SESSION = 19
Global Const MAPI_E_LOGIN_FAILURE = 3
Global Const MAPI_E_LOGON_FAILURE = MAPI_E_LOGIN_FAILURE
Global Const MAPI_E_MESSAGE_IN_USE = 22
Global Const MAPI_E_NETWORK_FAILURE = 23
Global Const MAPI_E_NO_MESSAGES = 16
Global Const MAPI_E_NOT_SUPPORTED = 26
Global Const MAPI_E_TEXT_TOO_LARGE = 18
Global Const MAPI_E_TOO_MANY_FILES = 9
Global Const MAPI_E_TOO_MANY_RECIPIENTS = 10
Global Const MAPI_E_TOO_MANY_SESSIONS = 8
Global Const MAPI_E_TYPE_NOT_SUPPORTED = 20
Global Const MAPI_E_UNKNOWN_RECIPIENT = 14
Global Const MAPI_E_USER_ABORT = MAPI_USER_ABORT
Global Const MAPI_ORIG = 0
Global Const MAPI_USER_ABORT = 1
Global Const SUCCESS_SUCCESS = 0

Type MapiFile
    Reserved As Long
    Flags As Long
    Position As Long
    PathName As String
    FileName As String
    FileType As String
End Type

Type MAPIMessage
    Reserved As Long
    Subject As String
    NoteText As String
    MessageType As String
    DateReceived As String
    ConversationID As String
    Flags As Long
    RecipCount As Long
    FileCount As Long
End Type

Type MapiRecip
    Reserved As Long
    RecipClass As Long
    Name As String
    Address As String
    EIDSize As Long
    EntryID As String
End Type

Declare Function BMAPIAddress Lib "MAPI32.DLL" (lInfo&, ByVal Session&, ByVal UIParam&, Caption$, ByVal nEditFields&, Label$, nRecipients&, Recip() As MapiRecip, ByVal Flags&, ByVal Reserved&) As Long

Declare Function BMAPIGetAddress Lib "MAPI32.DLL" (ByVal lInfo&, ByVal nRecipients&, Recipients() As MapiRecip) As Long

Declare Function BMAPIGetReadMail Lib "MAPI32.DLL" (ByVal lMsg&, Message As MAPIMessage, Recip() As MapiRecip, File() As MapiFile, Originator As MapiRecip) As Long

Declare Function BMAPIReadMail Lib "MAPI32.DLL" (lMsg&, nRecipients&, nFiles&, ByVal Session&, ByVal UIParam&, MessageID$, ByVal Flag&, ByVal Reserved&) As Long

Declare Function MAPIDeleteMail Lib "MAPI32.DLL" (ByVal Session&, ByVal UIParam&, ByVal MsgID$, ByVal Flags&, ByVal Reserved&) As Long

Declare Function MAPIDetails Lib "MAPI32.DLL" Alias "BMAPIDetails" (ByVal Session&, ByVal UIParam&, Recipient As MapiRecip, ByVal Flags&, ByVal Reserved&) As Long

Declare Function MAPIFindNext Lib "MAPI32.DLL" Alias "BMAPIFindNext" (ByVal Session&, ByVal UIParam&, MsgType$, SeedMsgID$, ByVal Flag&, ByVal Reserved&, MsgID$) As Long

Declare Function MAPILogoff Lib "MAPI32.DLL" (ByVal Session&, ByVal UIParam&, ByVal Flags&, ByVal Reserved&) As Long

Declare Function MAPILogon Lib "MAPI32.DLL" (ByVal UIParam&, ByVal User$, ByVal Password$, ByVal Flags&, ByVal Reserved&, Session&) As Long

Declare Function MAPIResolveName Lib "MAPI32.DLL" Alias "BMAPIResolveName" (ByVal Session&, ByVal UIParam&, ByVal UserName$, ByVal Flags&, ByVal Reserved&, Recipient As MapiRecip) As Long

Declare Function MAPISaveMail Lib "MAPI32.DLL" Alias "BMAPISaveMail" (ByVal Session&, ByVal UIParam&, Message As MAPIMessage, Recipient() As MapiRecip, File() As MapiFile, ByVal Flags&, ByVal Reserved&, MsgID$) As Long

Declare Function MAPISendDocuments Lib "MAPI32.DLL" (ByVal UIParam&, ByVal DelimStr$, ByVal FilePaths$, ByVal FileNames$, ByVal Reserved&) As Long

Declare Function MAPISendMail Lib "MAPI32.DLL" Alias "BMAPISendMail" (ByVal Session&, ByVal UIParam&, Message As MAPIMessage, Recipient() As MapiRecip, File() As MapiFile, ByVal Flags&, ByVal Reserved&) As Long

0

Featured Post

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now