Sending E-Mail on Behalf of another Address

RogerCooper

Registered User.
Local time
Today, 06:22
Joined
Jul 30, 2014
Messages
701
I need to be able to send invoices from my computer on behalf of accounts receivable. I have achieved partial success with the following code.

'Public Sub doEmailOutlook(sTo As String, sSubject As String, sBody As String, sFile As String, Optional bFileAttach As Boolean = False, Optional bPreview As Boolean = False)
Public Sub doEmailOutlook()
On Error GoTo doEmailOutlookErr
Dim strEmail As String
Dim strMsg As String
Dim oLook As Object
Dim oMail As Object
'Test Values
sTo = "rogercoop@aol.com"
sSubject = "Test Message"
RR = "accounts.receivable@spectroline.com"
sBody = "Test Message body"
Set oLook = CreateObject("Outlook.Application")
Set oMail = oLook.createitem(0)
With oMail
.ReplyRecipients.Add "accounts.receivable@spectroline.com"
.to = sTo
'.body = sBody
.htmlbody = sBody
.Subject = sSubject
.sender = "accounts.receivable@spectroline.com"
'sentonbehalfofname = "accounts.receivable@spectroline.com"
If sFile <> "" Then
.Attachments.Add (sFile)
End If
If bFileAttach = True Then
.Attachments.Add (CurrentProject.Path & "\YourFile.pdf")
End If
If bPreview = True Then
.display
Else
.Send
End If
End With
If bPreview = False Then
Set oMail = Nothing
Set oLook = Nothing
End If
Exit Sub
doEmailOutlookErrExit:
Exit Sub
doEmailOutlookErr:
MsgBox Err.Description, vbOKOnly, Err.Source & ":" & Err.Number
Resume doEmailOutlookErrExit
End Sub


This changes the reply-to address but does not change the sending address. If I use the sentonbehalfofproperty it still shows my address as the sending address. How can I truly get it to send on behalf of?
 

Users who are viewing this thread

Back
Top Bottom