2017-04-17 56 views
1

我正在代表共享郵箱 - 通用系統帳戶發送電子郵件?如何更新發件人電子郵件地址

如何更新Outlook郵件中的發件人?

我得到一個運行時錯誤 '438':對象不支持此屬性或方法。從= 「[email protected]

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 = "[email protected]" ' ** 
      .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 
+1

您需要添加一些敘述到您的文章並修復代碼格式。我試過了,它不會讓我。但是,真的,這有什麼問題?把你想要的任何電子郵件地址代替「[email protected]」。 – June7

+0

我得到運行時錯誤'438':對象不支持此屬性或方法.From =「[email protected]」 – Yves

+1

請參閱http://stackoverflow.com/questions/26427302/vba-code-發送電子郵件從二次電子郵件地址在展望,http://stackoverflow.com/questions/33322540/change-the-from-field,http://stackoverflow.com/questions/26432256/ sentonbehalfof - 不工作功能於Excel的2010年VBA代碼。如果您在任何這些問題中找到答案,請考慮刪除您的問題,因爲該網站會爭取一個沒有重複的問題。 – niton

回答

0

首先,在調用Send方法之前,沒有必要調用Display

如果您在Outlook中配置了共享郵箱,則需要使用SendUsingAccount屬性,該屬性允許設置Account對象,該對象表示MailItem要發送到的帳戶。例如:

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 ("[email protected]") 
     oMail.Recipients.ResolveAll 
     oMail.SendUsingAccount = oAccount 
     oMail.Send 
    End If 
    Next 
End Sub 

使用SentOnBehalfOfName只要您的Exchange帳戶有共享的郵箱或通訊組的SendAs權限,它會從共享帳戶或組被髮送,而不是名義發出的。

With oEmailItem 
     .To = rs!standard_e_mail_addr 
     .SentOnBehalfOfName = "[email protected]" 
     .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 
相關問題