Code to send email from Outlook Express
Originally from here, just afraid that it can gone. Can run in Access also (of course):
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 MAPIFileTag
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()
Dim aRecips(0 To 0) As String
aRecips(0) = "smtp:t...@syspac.com"
SendMailWithOE "Send Mail Through OE", "Sure, you can, Tom!", aRecips
End Sub
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 MAPIFileTag
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()
Dim aRecips(0 To 0) As String
aRecips(0) = "smtp:t...@syspac.com"
SendMailWithOE "Send Mail Through OE", "Sure, you can, Tom!", aRecips
End Sub
1 Comments:
I would try to play with MAPISendMail argumets - should be some flag to show message. This one looks what you need:
MAPI_DIALOG
A dialog box should be displayed to prompt the user for recipients and other sending options. When MAPI_DIALOG is not set, at least one recipient must be specified.
Look here:
http://msdn2.microsoft.com/en-us/library/ms527908.aspx
Post a Comment
<< Home