1

I am sending email on behalf of a Shared MailBox - generic system account?

How do I update the sender in Outlook mail?

I am getting a Run-Time error '438': Object doesn't support this property or method .From = "MYACCOUNT@ACCOUNT.com"

Function CreateEmail(MySQL As String)
'On Error GoTo Exit_Function:
Dim oOutlook As Outlook.Application
Dim oEmailItem As MailItem 'rs As Recordset

Dim rs As Recordset
Set rs = CurrentDb.OpenRecordset(MySQL)
If rs.RecordCount > 0 Then
    rs.MoveFirst
    Do Until rs.EOF
    If IsNull(rs!standard_e_mail_addr) Then
        rs.MoveNext
    Else
        If oOutlook Is Nothing Then
            Set oOutlook = New Outlook.Application
        End If
        Set oEmailItem = oOutlook.CreateItem(olMailItem)
        With oEmailItem
            .To = rs!standard_e_mail_addr
            .From = "MYACCOUNT@ACCOUNT.com" ' **
            .Subject = "Mandatory Action Required Submit In-Person Identification Form for " & rs!emp_fname
            .Body = "EmpNo: " & rs!emp_no & vbCr & _
                    "EmpName: " & rs!emp_fname & vbCr & _
                    "DO NOT REPLY."

            .Display
            .Send
             rs.Edit
             rs!EmailNotification_Send = Date
             rs.Update

        End With
        Set oEmailItem = Nothing
        Set oOutlook = Nothing
        rs.MoveNext
End If
Loop

Else
End If
rs.Close
Exit Function:
    Exit Function
End Function
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Yves
  • 12,059
  • 15
  • 53
  • 57
  • 1
    You need to add some narrative to your post and fix the code formatting. I tried and it won't let me. But really, what is the issue? Put whatever email address you want in place of "MYACCOUNT@ACCOUNT.com". – June7 Apr 17 '17 at 19:25
  • I am getting a Run-Time error '438': Object doesn't support this property or method .From = "MYACCOUNT@ACCOUNT.com" – Yves Apr 17 '17 at 19:37
  • 1
    See http://stackoverflow.com/questions/26427302/vba-code-to-send-email-from-secondary-email-address-in-outlook, http://stackoverflow.com/questions/33322540/change-the-from-field, http://stackoverflow.com/questions/26432256/sentonbehalfof-not-working-in-excel-2010-vba-code. If you find an answer in any of these, consider deleting your question as the site strives for one question without duplicates. – niton Apr 17 '17 at 20:28

2 Answers2

0

Okay, try: .SentOnBehalfOfName = """SenderName"" <MyAccount@Address.com>"

Also review: Use another account for sender

June7
  • 19,874
  • 8
  • 24
  • 34
0

First of all, there is no need to call Display before calling the Send method.

If you have the shared mailbox configured in Outlook you need to use the SendUsingAccount property which allows to set an Account object that represents the account under which the MailItem is to be sent. For example:

Sub SendUsingAccount() 
  Dim oAccount As Outlook.account  
  For Each oAccount In Application.Session.Accounts  
    If oAccount.AccountType = olPop3 Then  
      Dim oMail As Outlook.MailItem  
      Set oMail = Application.CreateItem(olMailItem)  
      oMail.Subject = "Sent using POP3 Account"  
      oMail.Recipients.Add ("someone@example.com")  
      oMail.Recipients.ResolveAll  
      oMail.SendUsingAccount = oAccount  
      oMail.Send  
    End If  
  Next  
End Sub 

Use SentOnBehalfOfName as long as your Exchange account has SendAs permission for the shared mailbox or distribution group, it will be sent from the shared account or group, not sent on behalf of.

    With oEmailItem
        .To = rs!standard_e_mail_addr
        .SentOnBehalfOfName = "MYACCOUNT@ACCOUNT.com" 
        .Subject = "Mandatory Action Required Submit In-Person Identification Form for " & rs!emp_fname
        .Body = "EmpNo: " & rs!emp_no & vbCr & _
                "EmpName: " & rs!emp_fname & vbCr & _
                "DO NOT REPLY."
        .Send
Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45