Results 1 to 1 of 1
  1. #1
    Join Date
    Jul 2003

    Unanswered: An old question: Access and Outlook Express (for Experts only)

    Some time ago everybody told that it was impossible to attach a file to OE
    (by code), because OE hasn't the necessary automation to do that.

    However somebody turn around the problem and now it's possible to send a
    normal email using OE. (see the code below)

    With this code, OE doesn't open (just ask if we let to send the email).
    If we open OE, we can see the email sent.

    My question: with the code below, can we open OE and control the sending
    of the email? Is there a way to do that?

    Thank you for any idea.


    [code find here:]

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

    Private Type MAPIFileDesc
    Reserved As Long
    flags As Long
    Position As Long
    PathName As String
    FileName As String
    FileType As Long
    End Type

    Private Type MAPIMessage
    Reserved As Long
    Subject As String
    NoteText As String
    MessageType As String
    DateReceived As String
    ConversationID As String
    Originator As Long
    flags As Long
    RecipCount As Long
    Recipients As Long
    FileCount As Long
    Files As Long
    End Type

    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

    Public Sub SendMailWithOE(ByVal vSubject As String, _
    ByVal vMessage As String, _
    ByRef vRecipients As String, _
    Optional ByVal vFiles As String)

    Dim aFiles() As String
    Dim aRecips() As String

    Dim FilePaths() As MAPIFileDesc
    Dim Recips() As MapiRecip
    Dim Message As MAPIMessage

    Dim z As Long

    aFiles = Split(vFiles, ",")
    ReDim FilePaths(LBound(aFiles) To UBound(aFiles))
    For z = LBound(aFiles) To UBound(aFiles)
    With FilePaths(z)
    .Position = -1
    .PathName = StrConv(aFiles(z), vbFromUnicode)
    End With
    Next z

    aRecips = Split(vRecipients, ",")
    ReDim Recips(LBound(aRecips) To UBound(aRecips))
    For z = LBound(aRecips) To UBound(aRecips)
    With Recips(z)
    .RecipClass = 1
    If InStr(aRecips(z), "@") <> 0 Then
    .Address = StrConv(aRecips(z), vbFromUnicode)
    .Name = StrConv(aRecips(z), vbFromUnicode)
    End If
    End With
    Next z

    With Message
    .FileCount = UBound(FilePaths) - LBound(FilePaths) + 1
    .Files = VarPtr(FilePaths(LBound(FilePaths)))
    .NoteText = vMessage
    .RecipCount = UBound(Recips) - LBound(Recips) + 1
    .Recipients = VarPtr(Recips(LBound(Recips)))
    .Subject = vSubject
    End With
    MAPISendMail 0, 0, Message, 0, 0
    End Sub

    Private Sub Test_SendMailWithOE()
    Dim aFiles() As Variant
    Dim aRecips() As String
    Dim Files As String
    Dim Message As String
    Dim Recipients As String
    Dim Subject As String

    ' not required
    Files = "C:\twacker.log"
    Files = Files & "," & "C:\readme.txt"

    ' required
    Recipients = "SomeOne@Some.Domain"

    ' not required
    Recipients = Recipients & "," & "SomeOneElse@SomeOther.Domain"

    Message = "Let me know if you get this, please."

    Subject = "Test"

    SendMailWithOE Subject, Message, Recipients, Files

    End Sub
    Last edited by jmruas; 06-21-04 at 18:15.

Posting Permissions

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