AlanG
02-27-2005, 06:48 AM
Hi
I can send emails with or without attachments from Access using MS Outlook no problem, but I have one user who flatly refuses to install Outlook on his machine (don't ask why - it's beyond me!!!).
Consequently I've been trying to be able to use Outlook Express instead (which he's quite happy to use!!!!) and found the following freeware code (credit to the author Lyle Fairfield) which uses the msoe.dll
I've modified the code to suit my needs, but despite several (un)happy hours of trying, can't work out what I'm missing to be able to add an attachment to the email.
I'd be very grateful if anyone can add the arguments needed to pass to the .dll to enable adding an attachment.
Thanks............
Alan
Option Compare Database
Option Explicit
Type MAPIRecip
Reserved As Long
RecipClass As Long
Name As String
Address As String
EIDSize As Long
EntryID As String
End Type
Type MAPIFileTag
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
End Type
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
Files As Long
FileCount 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
Sub SendMailWithOE(ByVal strSubject As String, ByVal strMessage As String, _
ByRef aRecips As Variant)
Dim recips() As MAPIRecip
Dim message As MAPIMessage
Dim z As Long
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)
Else
.Name = StrConv(aRecips(z), vbFromUnicode)
End If
End With
Next z
With message
.NoteText = strMessage
.Subject = strSubject
.RecipCount = UBound(recips) - LBound(aRecips) + 1
.Recipients = VarPtr(recips(LBound(recips)))
End With
MAPISendMail 0, 0, message, 0, 0
End Sub
Sub TestSendMailwithOE(strSubject As String, strBody As String)
Dim aRecips(0 To 0) As String
aRecips(0) = "someone@somewhere.com"
SendMailWithOE strSubject, strBody, aRecips
End Sub
Private Sub cmdEmail_Click()
Call TestSendMailwithOE("test", "testing message")
End Sub
I can send emails with or without attachments from Access using MS Outlook no problem, but I have one user who flatly refuses to install Outlook on his machine (don't ask why - it's beyond me!!!).
Consequently I've been trying to be able to use Outlook Express instead (which he's quite happy to use!!!!) and found the following freeware code (credit to the author Lyle Fairfield) which uses the msoe.dll
I've modified the code to suit my needs, but despite several (un)happy hours of trying, can't work out what I'm missing to be able to add an attachment to the email.
I'd be very grateful if anyone can add the arguments needed to pass to the .dll to enable adding an attachment.
Thanks............
Alan
Option Compare Database
Option Explicit
Type MAPIRecip
Reserved As Long
RecipClass As Long
Name As String
Address As String
EIDSize As Long
EntryID As String
End Type
Type MAPIFileTag
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
End Type
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
Files As Long
FileCount 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
Sub SendMailWithOE(ByVal strSubject As String, ByVal strMessage As String, _
ByRef aRecips As Variant)
Dim recips() As MAPIRecip
Dim message As MAPIMessage
Dim z As Long
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)
Else
.Name = StrConv(aRecips(z), vbFromUnicode)
End If
End With
Next z
With message
.NoteText = strMessage
.Subject = strSubject
.RecipCount = UBound(recips) - LBound(aRecips) + 1
.Recipients = VarPtr(recips(LBound(recips)))
End With
MAPISendMail 0, 0, message, 0, 0
End Sub
Sub TestSendMailwithOE(strSubject As String, strBody As String)
Dim aRecips(0 To 0) As String
aRecips(0) = "someone@somewhere.com"
SendMailWithOE strSubject, strBody, aRecips
End Sub
Private Sub cmdEmail_Click()
Call TestSendMailwithOE("test", "testing message")
End Sub