繁体   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