簡體   English   中英

使用Excel VBA發送IBM Lotus Notes電子郵件從錯誤的電子郵件地址發送

[英]Sending IBM Lotus Notes email using excel VBA sends from wrong email address

我目前有兩個Lotus Notes數據庫,每個數據庫都有各自的電子郵件地址。 不出所料,當我通過第一個數據庫向我的gmail帳戶發送電子郵件時,它顯示為“發件人:notesAccount1@db1.com”,當我使用第二個數據庫發送時,該消息顯示為“發件人:notesAccount2 @ db2” .com”中的Gmail。

我的工作代碼可以打開第二個數據庫 ,在收件箱中搜索包含特定關鍵字的電子郵件,然后從該電子郵件中提取一個電子郵件地址。 然后,它在第二個數據庫中創建一個新文檔,插入收件人的姓名,主題,正文等,發送電子郵件,並將其保存到我的已發送文件夾中。 到目前為止,一切都可以順利進行。

但是,當我使用此VBA方法將電子郵件從第二個數據庫發送到我的gmail帳戶時,該電子郵件在我的gmail中顯示為“發件人:notesAccount1@db1.com”-與第一個數據庫關聯的電子郵件。

我不知道為什么會這樣。 通常,對VBA與Lotus Notes以及Lotus Notes服務器/數據庫之間的交互的了解非常有限。 從技術上講,第一個數據庫是我的默認數據庫,只有我可以訪問,而第二個數據庫則在以后添加,並且多個人可以訪問它。 我不知道這是否相關。

將不勝感激! 謝謝。

注意:此代碼是從多個來源復制和改編的,包括SO,IBM和其他Notes來源的一些來源,以及Google拋棄我的其他任何方式,包括 http://www.fabalou.com/vbandvba/lotusnotesmail.asp

http://www-01.ibm.com/support/docview.wss?uid=swg21178583

代碼:(這將必須修改,因為我已取出服務器名稱和郵件文件名稱)

Sub ReadNotesEmail()

Dim sess As Object
Dim db As Object
Dim folder As Object
Dim docNext As Object
Dim memoSenders As Variant
Dim newEmail As Object
Dim view As Object
Dim entry As Object
Dim entries As Object
Dim templateEmail As Object

Dim mailServer As String
Dim mailFile As String
Dim folderName As String
Dim todayDate As String
Dim memoBody As String
Dim senderEmail As String

Dim emailStartPos As Integer
Dim emailEndPos As Integer

'This program will search a particular folder in a Notes database that I designate.
'It will search that folder for emails that contain certain key words. Once it finds
'an email that fits, it will grab the sender's email address (written in the body, not
'in the 'from') and send them an email.

'Name of folder to search for emails
folderName = "($Inbox)"

'Create a Lotus Notes session and open it (will require password)
Set sess = CreateObject("Lotus.NotesSession")
sess.Initialize ("")

'Set the mail server, mail file, and database. This will be the tricky part as I need this to
'look at the second mail server as opposed to the default mail server of jdyagoda
Set db = sess.GETDATABASE("***name of second Notes server***", "***name of second mail file***")

'Open the mail database in notes
If Not db.IsOpen = True Then
    Call db.Open
End If
Set folder = db.GetView(folderName)

'Now look through the emails one at a time with a loop that ends when no emails are left.
'If an email contains the key word, look for the email address of the person who submitted
'the contact-us form. It follows the string "Email:" and preceeds
'the string "Phone:".
Set doc = folder.GetFirstDocument
Do Until doc Is Nothing
    Set docNext = folder.GETNEXTDOCUMENT(doc)
    memoBody = LCase(doc.GetItemValue("body")(0))
    If (memoBody Like "*") Then 'This is where you designate the keyword

        'Here's where you extract the email address - taken out for the purpose of this SO question
        'senderEmail = testName@test.com

        'Now create a new email to the intended recipient

        Set newEmail = db.CREATEDOCUMENT
        Call newEmail.ReplaceItemValue("Form", "Memo")
        Call newEmail.ReplaceItemValue("SendTo", senderEmail)
        Call newEmail.ReplaceItemValue("Subject", "Thank you for your email")
        Call newEmail.ReplaceItemValue("body", "Test Body 1. This is a test.")
        newEmail.SAVEMESSAGEONSEND = True

        'Send the new email

        Call newEmail.ReplaceItemValue("PostedDate", Now()) 'Gets the mail to appeaer in the sent items folder
        Call newEmail.SEND(False)

    End If
    Set doc = docNext
Loop

End Sub

Notes通常會使用您用於登錄的ID的電子郵件地址發送郵件。 因此,如果您使用notesAccount1 / Domain登錄,則所有電子郵件都將來自notesAccount1@example.com。 如果要偽造發件人,則需要使用未公開的方法:將電子郵件直接注入mail.box。 除非您真的知道自己在做什么,否則不要嘗試這樣做。

我已經在我的博客上為郵件通知類發布了代碼,它支持這種變通方法,可以將發件人設置為外發電子郵件。 您可以在http://blog.texasswede.com/updated-mailnotification-class-now-with-html-email-support-and-web-links/找到最新的代碼。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM