设置'来自'通过VBA发送时Lotus Notes中的电子邮件地址

时间:2014-05-16 13:32:28

标签: access-vba ms-access-2010 lotus-notes

我在Access数据库中使用VBA函数来调用Lotus Notes以向客户发送自动电子邮件。电子邮件是从用户个人Lotus帐户发送的,以便他们在已发送邮件中包含已发送电子邮件的历史记录。但是,我不希望客户看到我们的内部电子邮件地址。

我们正在指示客户不要回复电子邮件(请致电我们)并希望电子邮件看起来来自noreply@company.com。我可以将'ReplyTo'字段设置为noreply@company.com,如果客户回复电子邮件但“来自”字段仍然来自用户的真实电子邮件地址并且客户可以查看该信息并仍然向我们的地址发送电子邮件。

我已尝试设置以下属性,但它们似乎不起作用:

.DisplaySent = "noreply@company.com"
.iNetFrom = "noreply@company.com"
.iNetPrincipal = "noreply@company.com"

(我目前在下面的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 = "noreply@company.com"
    MailDoc.ReplyTo = "noreply@company.com"
    'MailDoc.DisplaySent = "noreply@company.com"
    'MailDoc.iNetFrom = "noreply@company.com"
    'MailDoc.iNetPrincipal = "noreply@company.com"
    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 个答案:

答案 0 :(得分:2)

你不能改变这种方式。它将始终与原始发件人一起发送。

有两种方法可以解决这个问题。 1号为noreply@company.com创建一个邮箱,并从该邮箱发送所有邮件而不是用户的邮件。然后所有邮件都会有一个标记&#34;由&#34;原始发件人。根据mailclient,回复将在中央邮箱或用户框中结束。

没有。 2您可以直接在服务器mail.box中创建邮件,而不是您可以操作所有字段。然后,您将在用户邮箱中创建相同的文档,其中包含已发送邮件的所有必要项目。

答案 1 :(得分:1)

在代码中使用@NotesDomain解决方法。只需在代码中更改这一行:

MailDoc.Principal = "noreply@company.com@NotesDomain"

它应该有效。 Domino服务器查找“@NotesDomain”路由邮件,如果Principal字段以此字符串结尾,则字段From和ReplyTo将设置为“@NotesDomain”之前的字符串。

有关“@NotesDomain”方法的更多信息,请参阅“如何更改代理生成的邮件的明显发件人?”部分中的here