Hello,
I'm trying to use the SentOnBehalfOfName in order to mask the default user email name with our shared group email name. I have SendAs permissions but when I click on the email send button, I still see my default user email and not the "GroupUser@Test.com" test example email. My code does not error out but something is wrong. Could you please have a look and help me out with this: I added this 4 Dim's and following highlighted code for the SentOnBehalfOfName...
Private Sub CmdEmailRpt_Click()
Dim rst As DAO.Recordset
Dim db As DAO.Database
Dim strSql As String
Dim strTo As String
Dim txtID As TempVars
Dim OutApp As Outlook.Application
Dim objOutlookTo As Outlook.MailItem
Dim objOutlookRecip As Recipient
Dim Recipients As Recipients
Set db = CurrentDb()
strSql = "Select * FROM Qry_Max_Pymt_PymtEmailDetail;"
Set rst = CurrentDb.OpenRecordset(strSql)
Set OutApp = CreateObject("Outlook.Application")
Set objOutlookTo = OutApp.CreateItem(olMailItem)
Set Recipients = objOutlookTo.Recipients
Set objOutlookRecip = Recipients.Add("GroupUser@Test.com")
objOutlookRecip.Type = 1
objOutlookTo.SentOnBehalfOfName = "GroupUser@Test.com"
'Resolve each Recipient's name.
For Each objOutlookRecip In objOutlookTo.Recipients
objOutlookRecip.Resolve
Next
With rst
Do While Not rst.EOF
strTo = !Email & ";"
TempVars("txtID") = rst!ID.Value
DoCmd.SendObject acSendQuery, "Max_Pymt_EmailDetails1", acFormatXLS, strTo, , "EmailTest@Test.com", "TestDetails - Test", "Greetings. Please find the attached payment detail for the payment released today from the Custodian. If you have any questions or would like additional information please contact Test@AnotherTest.com." & vbCrLf & vbCrLf, False
DoEvents
rst.MoveNext
Loop
End With
rst.Close
Set rst = Nothing
Set db = Nothing
End Sub
I'm trying to use the SentOnBehalfOfName in order to mask the default user email name with our shared group email name. I have SendAs permissions but when I click on the email send button, I still see my default user email and not the "GroupUser@Test.com" test example email. My code does not error out but something is wrong. Could you please have a look and help me out with this: I added this 4 Dim's and following highlighted code for the SentOnBehalfOfName...
Private Sub CmdEmailRpt_Click()
Dim rst As DAO.Recordset
Dim db As DAO.Database
Dim strSql As String
Dim strTo As String
Dim txtID As TempVars
Dim OutApp As Outlook.Application
Dim objOutlookTo As Outlook.MailItem
Dim objOutlookRecip As Recipient
Dim Recipients As Recipients
Set db = CurrentDb()
strSql = "Select * FROM Qry_Max_Pymt_PymtEmailDetail;"
Set rst = CurrentDb.OpenRecordset(strSql)
Set OutApp = CreateObject("Outlook.Application")
Set objOutlookTo = OutApp.CreateItem(olMailItem)
Set Recipients = objOutlookTo.Recipients
Set objOutlookRecip = Recipients.Add("GroupUser@Test.com")
objOutlookRecip.Type = 1
objOutlookTo.SentOnBehalfOfName = "GroupUser@Test.com"
'Resolve each Recipient's name.
For Each objOutlookRecip In objOutlookTo.Recipients
objOutlookRecip.Resolve
Next
With rst
Do While Not rst.EOF
strTo = !Email & ";"
TempVars("txtID") = rst!ID.Value
DoCmd.SendObject acSendQuery, "Max_Pymt_EmailDetails1", acFormatXLS, strTo, , "EmailTest@Test.com", "TestDetails - Test", "Greetings. Please find the attached payment detail for the payment released today from the Custodian. If you have any questions or would like additional information please contact Test@AnotherTest.com." & vbCrLf & vbCrLf, False
DoEvents
rst.MoveNext
Loop
End With
rst.Close
Set rst = Nothing
Set db = Nothing
End Sub