I
IgaJim
Hi, I've trawled the web for a solution to this:
I need to send a text and HTML multipart email from Access 2003 intefacing
with Outlook 2003 methods. I've tried .textbody and various others. Please
help.
Here's a sample of what I have so far:
Public Sub SendOutlook(NotifyId As Integer, strFrom As String, strTo As
String, Subject As String, HTMLBody As String, SendUsing As String, Server As
String, ServerPort As String, AttachmentPath As String, Retries As Integer,
ErrorBit As Boolean, ErrorDesc As String)
On Error GoTo ErrorHandler:
Dim objOutlook As Object
Dim MAPISession As Outlook.NameSpace
Dim MAPIFolder As Outlook.MAPIFolder
Dim MAPIMailItem As Outlook.MailItem
Dim oRecipient As Outlook.Recipient
Dim blnSuccessful As Boolean
Set objOutlook = CreateObject("Outlook.Application")
If objOutlook Is Nothing Then
'Outlook isn't already running - create a new instance...
Set objOutlook = CreateObject("Outlook.Application")
End If
Set MAPISession = objOutlook.Session
If Not MAPISession Is Nothing Then
strFrom = MAPISession.CurrentUser
MAPISession.Logon , , True, False
Set MAPIFolder = MAPISession.GetDefaultFolder(olFolderDrafts)
If Not MAPIFolder Is Nothing Then
Set MAPIMailItem = MAPIFolder.Items.Add(olMailItem)
If Not MAPIMailItem Is Nothing Then
With MAPIMailItem
If Not IsNull(strFrom) And Len(strFrom) > 0 Then
.SentOnBehalfOfName = strFrom
End If
.To = strTo
.Subject = Subject
.HTMLBody = HTMLBody
If Not IsNull(AttachmentPath) And Len(AttachmentPath) > 0 Then
.Attachments.Add AttachmentPath
End If
.Send
End With
End If
End If
End If
blnSuccessful = True
ExitRoutine:
Set MAPISession = Nothing
Set objOutlook = Nothing
MAPISession.Logoff
Exit Sub
ErrorHandler:
MsgBox "An error has occured in the user defined Outlook VBA function" &
vbCrLf & vbCrLf & _
"Error Number: " & CStr(Err.Number) & vbCrLf & _
"Error Description: " & Err.Description, vbApplicationModal +
vbCritical
Set MAPISession = Nothing
Set objOutlook = Nothing
MAPISession.Logoff
End Sub
I need to send a text and HTML multipart email from Access 2003 intefacing
with Outlook 2003 methods. I've tried .textbody and various others. Please
help.
Here's a sample of what I have so far:
Public Sub SendOutlook(NotifyId As Integer, strFrom As String, strTo As
String, Subject As String, HTMLBody As String, SendUsing As String, Server As
String, ServerPort As String, AttachmentPath As String, Retries As Integer,
ErrorBit As Boolean, ErrorDesc As String)
On Error GoTo ErrorHandler:
Dim objOutlook As Object
Dim MAPISession As Outlook.NameSpace
Dim MAPIFolder As Outlook.MAPIFolder
Dim MAPIMailItem As Outlook.MailItem
Dim oRecipient As Outlook.Recipient
Dim blnSuccessful As Boolean
Set objOutlook = CreateObject("Outlook.Application")
If objOutlook Is Nothing Then
'Outlook isn't already running - create a new instance...
Set objOutlook = CreateObject("Outlook.Application")
End If
Set MAPISession = objOutlook.Session
If Not MAPISession Is Nothing Then
strFrom = MAPISession.CurrentUser
MAPISession.Logon , , True, False
Set MAPIFolder = MAPISession.GetDefaultFolder(olFolderDrafts)
If Not MAPIFolder Is Nothing Then
Set MAPIMailItem = MAPIFolder.Items.Add(olMailItem)
If Not MAPIMailItem Is Nothing Then
With MAPIMailItem
If Not IsNull(strFrom) And Len(strFrom) > 0 Then
.SentOnBehalfOfName = strFrom
End If
.To = strTo
.Subject = Subject
.HTMLBody = HTMLBody
If Not IsNull(AttachmentPath) And Len(AttachmentPath) > 0 Then
.Attachments.Add AttachmentPath
End If
.Send
End With
End If
End If
End If
blnSuccessful = True
ExitRoutine:
Set MAPISession = Nothing
Set objOutlook = Nothing
MAPISession.Logoff
Exit Sub
ErrorHandler:
MsgBox "An error has occured in the user defined Outlook VBA function" &
vbCrLf & vbCrLf & _
"Error Number: " & CStr(Err.Number) & vbCrLf & _
"Error Description: " & Err.Description, vbApplicationModal +
vbCritical
Set MAPISession = Nothing
Set objOutlook = Nothing
MAPISession.Logoff
End Sub