2014-05-16 95 views
0

我在Access數據庫中使用VBA函數來調用Lotus Notes以向客戶發送自動電子郵件。電子郵件正在從用戶個人Lotus帳戶發送,以便他們在已發送郵件中記錄已發送電子郵件的歷史記錄。但是,我不希望客戶看到我們的內部電子郵件地址。通過VBA發送時,在Lotus Notes中設置「From」電子郵件地址

我們正在指示客戶不要回覆電子郵件(而不是給我們打電話),並希望電子郵件看起來來自[email protected]。我能夠將'ReplyTo'字段設置爲像[email protected]這樣的東西,如果客戶回覆電子郵件但「發件人」字段仍然來自用戶的真實電子郵件地址並且客戶可以看到這些信息,並仍然發送電子郵件到我們的地址。

我已經嘗試設置以下屬性,但他們似乎並不工作:

.DisplaySent = "[email protected]" 
.iNetFrom = "[email protected]" 
.iNetPrincipal = "[email protected]" 

(我現在有這些註釋掉在下面的VBA,因爲他們似乎沒有任何效果)

下面是我正在使用的VBA。有什麼建議麼? 謝謝!

Public Sub SendNotesMail(Subject As String, Attachment As String, Recipient As  Variant, BodyText As String, SaveIt As Boolean) 

    'Set up the objects required for Automation into lotus notes 
    Dim Maildb As Object 'The mail database 
    Dim UserName As String 'The current users notes name 
    Dim MailDbName As String 'THe current users notes mail database name 
    Dim MailDoc As Object 'The mail document itself 
    Dim AttachME As Object 'The attachment richtextfile object 
    Dim Session As Object 'The notes session 
    Dim EmbedObj As Object 'The embedded object (Attachment) 

    'Start a session to notes 
    Set Session = CreateObject("Notes.NotesSession") 

    'Next line only works with 5.x and above. Replace password with your password 
    'Session.Initialize ("password") 
    'Get the sessions username and then calculate the mail file name 
    'You may or may not need this as for MailDBname with some systems you 
    'can pass an empty string or using above password you can use other mailboxes. 
    UserName = Session.UserName 
    MailDbName = Left$(UserName, 1) & Right$(UserName, (Len(UserName) - InStr(1, UserName, " "))) & ".nsf" 

    'Open the mail database in notes 
    Set Maildb = Session.GETDATABASE("", MailDbName) 
    If Maildb.ISOPEN = True Then 
     'Already open for mail 
    Else 
     Maildb.OPENMAIL 
    End If 

    'Set up the new mail document 
    Set MailDoc = Maildb.CREATEDOCUMENT 
    MailDoc.principal = "[email protected]" 
    MailDoc.ReplyTo = "[email protected]" 
    'MailDoc.DisplaySent = "[email protected]" 
    'MailDoc.iNetFrom = "[email protected]" 
    'MailDoc.iNetPrincipal = "[email protected]" 
    MailDoc.Form = "Memo" 
    MailDoc.sendto = Recipient 
    MailDoc.Subject = Subject 
    MailDoc.Body = BodyText 
    MailDoc.SAVEMESSAGEONSEND = SaveIt 

    'Set up the embedded object and attachment and attach it 
    If Attachment <> "" Then 
     Set AttachME = MailDoc.CREATERICHTEXTITEM("Attachment") 
     Set EmbedObj = AttachME.EMBEDOBJECT(1454, "", Attachment, "Attachment") 
     MailDoc.CREATERICHTEXTITEM ("Attachment") 
    End If 

    'Send the document 
    MailDoc.PostedDate = Now() 'Gets the mail to appear in the sent items folder 
    MailDoc.SEND 0, Recipient 

    'Clean Up 
    Set Maildb = Nothing 
    Set MailDoc = Nothing 
    Set AttachME = Nothing 
    Set Session = Nothing 
    Set EmbedObj = Nothing 
End Sub 

回答

2

您無法更改From這種方式。它將始終與原始發件人一起發送。

有兩種方法可以解決這個問題。 第1號爲[email protected]創建郵箱,並從該郵箱發送所有郵件,而不是用戶的郵箱。所有的郵件將有一個「發送」標誌的原始發件人。根據mailclient的不同,回覆將在中央郵箱或用戶框中結束。

第2號你直接在服務器mail.box中創建郵件,比你能夠操縱所有的字段。之後,您可以在用戶郵箱中創建與發送郵件所需的所有項目相同的文檔。

+0

感謝您的回覆。選項#1我不幸因內部原因無法完成。我正在考慮選項2,因爲不熟悉如何實現這一點。我們正在使用Domino服務器,但我不確定如何直接在服務器電子郵件框中創建電子郵件。是否有任何網上資源提供有關如何做到這一點的見解?我試着搜索,但我不確定我甚至在尋找什麼。 – user3644787

+0

看看這裏http://stackoverflow.com/a/21900751/2065611 –

+0

以前的URL非常有幫助。謝謝。我會嘗試一下併發布結果。 – user3644787

1

在代碼中使用@NotesDomain解決方法。只需更改代碼中的這一行:

MailDoc.Principal = "[email protected]@NotesDomain" 

它應該工作。 Domino服務器查找「@NotesDomain」路由郵件,如果Principal字段以該字符串結尾,則From和ReplyTo字段將設置爲「@NotesDomain」之前的字符串。

有關「@NotesDomain」方法的更多信息,請參見here,位於「我如何更改代理生成的郵件的表面發件人?」部分。

+0

很酷的事情,沒有意識到這一點。但是,儘管我可以看到這一點,但它仍然沒有達到要求:郵件在「發件人」字段中以「不退」的方式到達,但真實姓名在Notes郵件客戶端仍然顯示爲「已發送」,並且仍然被打印到內部字段「From」,「INetFrom」和「$ OnBehalfOf」;對於外部發送的郵件,真實姓名在郵件標題中顯示爲「發件人」,並列爲「返回路徑」 - BTW:感謝鏈接朱莉的輝煌的文檔;有一天我一直在尋找它... –

相關問題