A
Andy Levy
I am using the Outlook Object Model in my MS Access application .
I am sending mail via Outlook. I would like to know whether it is possible
to specify in the code what account the mail should be sent from, as i would
like to send certain emails from differing email addresses.
My code is below.
AL
Public Function SendMessage(DisplayMsg As Boolean, Email As String, subject
As String, text As String, Optional AttachmentPath)
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment
' Create the Outlook session.
Set objOutlook = CreateObject("Outlook.Application")
' Create the message.
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
With objOutlookMsg
' Add the To recipient(s) to the message.
Set objOutlookRecip = .Recipients.Add(Email)
objOutlookRecip.Type = olTo
' Set the Subject, Body, and Importance of the message.
.subject = subject
.Body = text
' Resolve each Recipient's name.
For Each objOutlookRecip In .Recipients
objOutlookRecip.Resolve
Next
' Should we display the message before sending?
If DisplayMsg Then
.Display
Else
.Save
.send
End If
End With
Set objOutlook = Nothing
End Function
I am sending mail via Outlook. I would like to know whether it is possible
to specify in the code what account the mail should be sent from, as i would
like to send certain emails from differing email addresses.
My code is below.
AL
Public Function SendMessage(DisplayMsg As Boolean, Email As String, subject
As String, text As String, Optional AttachmentPath)
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment
' Create the Outlook session.
Set objOutlook = CreateObject("Outlook.Application")
' Create the message.
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
With objOutlookMsg
' Add the To recipient(s) to the message.
Set objOutlookRecip = .Recipients.Add(Email)
objOutlookRecip.Type = olTo
' Set the Subject, Body, and Importance of the message.
.subject = subject
.Body = text
' Resolve each Recipient's name.
For Each objOutlookRecip In .Recipients
objOutlookRecip.Resolve
Next
' Should we display the message before sending?
If DisplayMsg Then
.Display
Else
.Save
.send
End If
End With
Set objOutlook = Nothing
End Function