如何用VB脚本用其他邮箱发送Lotus Notes邮件
How to send lotus notes mail with VB script with other mail box
您好,我正在使用 VB 脚本发送 Lotus Notes 邮件。现在我想用我的莲花笔记中打开的其他邮箱而不是我的邮箱发送邮件。我尝试了不同的选择,但没有运气。我正在使用以下代码发送邮件。
您可以在下面找到代码URL:
https://gallery.technet.microsoft.com/scriptcenter/fe141119-9599-46a7-90ca-8dbc66d50297
option explicit
' --------------------------------------------------------------------------
' -- Create Lotus Notes email (and add attachment) using VB Script
' --
' -- Version 1.01
' --
' -- Created by : Michael Green
' -- migreen@westpac.com.au
' --
' -- Based on in-complete/partially working script from :
' -- http://en.allexperts.com/q/Using-Lotus-Notes-1427/Creating-LotusNotes-email-using-1.htm
' --
' -- Created : 06/10/2009
' -- Last Updated: 07/10/2009
' --------------------------------------------------------------------------
Dim oSession ' AS NotesSession
Dim strServer
Dim strUserName
Dim strMailDbName
Dim oCurrentMailDb ' as NOTESDATABASE
Dim oMailDoc ' as NOTESDOCUMENT
Dim ortItem ' as NOTESRICHTEXTITEM
Dim ortAttacment ' as NOTESRICHTEXTITEM
Dim oEmbedObject ' as ????
dim cstrAttachment
Dim blAttachment
cstrAttachment = "c:\Temp\Telstra.xls"
blAttachment = True
' Start a session to notes
wscript.echo "## Connecting to Lotus Notes session..."
Set oSession = CreateObject("Notes.NotesSession")
wscript.echo("NotesVersion : " & oSession.NotesVersion)
wscript.echo("NotesBuildVersion: " & oSession.NotesBuildVersion)
wscript.echo("UserName : " & oSession.UserName)
wscript.echo("EffectiveUserName: " & oSession.EffectiveUserName)
wscript.echo "## GetEnvironmentString..."
strServer = oSession.GetEnvironmentString("MailServer",True)
wscript.echo("Server :" & strServer)
' eg. CN=Michael V Green/OU=CORPAU/OU=WBCAU/O=WBG
strUserName = oSession.UserName
strMailDbName = Left(strUserName, 1) & Right(strUserName, (Len(strUserName) - InStr(1, strUserName, "")))&".nsf"
wscript.echo("MailDbName :" & strMailDbName)
wscript.echo "## Getting current Notes database..."
' open the mail database in Notes
set oCurrentMailDb = oSession.CurrentDatabase
wscript.echo("fileName:" & oCurrentMailDb.fileName)
wscript.echo("filePath:" & oCurrentMailDb.filePath)
wscript.echo("server:" & oCurrentMailDb.server)
wscript.echo("Title:" & oCurrentMailDb.Title)
If oCurrentMailDb.IsOpen = True Then
' Already open for mail
wscript.echo "## Lotus Notes mail database is already open !"
Else
wscript.echo "## Opening Lotus Notes mail database..."
oCurrentMailDb.OPENMAIL
End If
' Create a document in the back end
Set oMailDoc = oCurrentMailDb.CREATEDOCUMENT
' Set the form name to memo
OMailDoc.form = "Memo"
with oMailDoc
.SendTo = "migreen@westpac.com.au"
.BlindCopyTo = "mgreen@ozemail.com.au"
.CopyTo = "migreen@westpac.com.au"
.Subject = "This is a test of VB scripting driving Lotus Notes 7 "
end with
set ortItem = oMaildoc.CREATERICHTEXTITEM("Body")
with ortItem
.AppendText("Test of RTF Item append")
.AddNewLine(2)
.AppendText("Signature")
End With
' Create additional Rich Text item and attach it
If blAttachment Then
Set ortAttacment = oMailDoc.CREATERICHTEXTITEM("Attachment")
' Function EMBEDOBJECT(ByVal TYPE As Short, ByVal CLASS As String, ByVal SOURCE As String, Optional ByVal OBJECTNAME As Object = Nothing) As Object
' Member of lotus.NOTESRICHTEXTITEM
Set oEmbedObject = ortAttacment.EMBEDOBJECT(1454, "", cstrAttachment, "Attachment")
End If
wscript.echo "## Sending email..."
with oMailDoc
.PostedDate = Now()
.SAVEMESSAGEONSEND = "True"
.send(false)
end with
wscript.echo "## Sent !"
' close objects
set oMailDoc = nothing
set oCurrentMailDb = nothing
set oSession = nothing
只需替换这些行(完全是废话,但我在另一个post中告诉过你):
strMailDbName = Left(strUserName, 1) & Right(strUserName, (Len(strUserName) - InStr(1, strUserName, "")))&".nsf"
wscript.echo("MailDbName :" & strMailDbName)
wscript.echo "## Getting current Notes database..."
' open the mail database in Notes
set oCurrentMailDb = oSession.CurrentDatabase
wscript.echo("fileName:" & oCurrentMailDb.fileName)
wscript.echo("filePath:" & oCurrentMailDb.filePath)
wscript.echo("server:" & oCurrentMailDb.server)
wscript.echo("Title:" & oCurrentMailDb.Title)
If oCurrentMailDb.IsOpen = True Then
' Already open for mail
wscript.echo "## Lotus Notes mail database is already open !"
Else
wscript.echo "## Opening Lotus Notes mail database..."
oCurrentMailDb.OPENMAIL
End If
与
strServer = "ServerNameWhereMailboxIs"
strMailDbName = "mail\nameofotherdatabase.nsf"
set oCurrentMailDb = oSession.GetDatabase( strServer, strMailDbName )
这样就可以了。
由于您的问题在我回答后发生了变化,为了将来有人发现这个问题,我会为 "sending an email in the name of another sender" 添加一些代码:
在 Lotus Notes 中,"send" 一封邮件不可能不留下真正发件人的痕迹:
当您收到这样一封由其他人发送的邮件时,您会看到该邮件来自其他邮箱,但其中包含 "Sent by" 的信息以及 [=40] 的邮件地址=]发件人。
为了至少让 "visual" 发件人看起来正确,您需要添加不同情况下需要的不同字段:这些字段是 Principal
、InetPrincipal
、From
和 InetFrom
.
但是:在正确配置的 Domino 服务器上,这无济于事:它将从 "real" 发件人计算这些字段并忽略您给他的内容。
但是有一个技巧可以让路由器单独保留这些字段:您必须将 NotesDomain 添加到地址。如果将以下行添加到代码中,路由器将忽略这些并保持字段不变:
MailDoc.principal = "noreply@company.com@NotesDomain"
MailDoc.inetprincipal = "noreply@company.com@NotesDomain"
MailDoc.from = "noreply@company.com@NotesDomain"
MailDoc.inetfrom = "noreply@company.com@NotesDomain"
如果你真的需要"hide"完全从收件人那里得到真正的发件人,那么你不能在邮件数据库中创建邮件,而是直接在服务器的"mail.box"中创建它,然后就可以了"Save" 它而不是 "Send" 它。但这还有其他缺点,这里不再讨论。
关于"send from/reply to"我只想多留一个答案,因为这个问题是我在求助时发现的:
我发现只有我自己的邮件地址会显示给外部收件人或不使用 IBM Notes 的人。即使我通过不同的邮件文件(邮寄)发送邮件,也只会显示我自己的邮寄地址,而且我也是收件人可以回复的人。所以我尝试了一些东西,它奏效了。
经过一些测试,这条线帮助我解决了内部和外部问题:
sender = """John Doe""" & "<support@domain.de>"
MailDoc.ReplyTo = sender
MailDoc.SMTPOriginator = sender
MailDoc.sender = sender
MailDoc.principal = sender
MailDoc.inetprincipal = sender
MailDoc.from = sender
MailDoc.inetfrom = sender
MailDoc.displayfrom = sender
您好,我正在使用 VB 脚本发送 Lotus Notes 邮件。现在我想用我的莲花笔记中打开的其他邮箱而不是我的邮箱发送邮件。我尝试了不同的选择,但没有运气。我正在使用以下代码发送邮件。
您可以在下面找到代码URL:
https://gallery.technet.microsoft.com/scriptcenter/fe141119-9599-46a7-90ca-8dbc66d50297
option explicit
' --------------------------------------------------------------------------
' -- Create Lotus Notes email (and add attachment) using VB Script
' --
' -- Version 1.01
' --
' -- Created by : Michael Green
' -- migreen@westpac.com.au
' --
' -- Based on in-complete/partially working script from :
' -- http://en.allexperts.com/q/Using-Lotus-Notes-1427/Creating-LotusNotes-email-using-1.htm
' --
' -- Created : 06/10/2009
' -- Last Updated: 07/10/2009
' --------------------------------------------------------------------------
Dim oSession ' AS NotesSession
Dim strServer
Dim strUserName
Dim strMailDbName
Dim oCurrentMailDb ' as NOTESDATABASE
Dim oMailDoc ' as NOTESDOCUMENT
Dim ortItem ' as NOTESRICHTEXTITEM
Dim ortAttacment ' as NOTESRICHTEXTITEM
Dim oEmbedObject ' as ????
dim cstrAttachment
Dim blAttachment
cstrAttachment = "c:\Temp\Telstra.xls"
blAttachment = True
' Start a session to notes
wscript.echo "## Connecting to Lotus Notes session..."
Set oSession = CreateObject("Notes.NotesSession")
wscript.echo("NotesVersion : " & oSession.NotesVersion)
wscript.echo("NotesBuildVersion: " & oSession.NotesBuildVersion)
wscript.echo("UserName : " & oSession.UserName)
wscript.echo("EffectiveUserName: " & oSession.EffectiveUserName)
wscript.echo "## GetEnvironmentString..."
strServer = oSession.GetEnvironmentString("MailServer",True)
wscript.echo("Server :" & strServer)
' eg. CN=Michael V Green/OU=CORPAU/OU=WBCAU/O=WBG
strUserName = oSession.UserName
strMailDbName = Left(strUserName, 1) & Right(strUserName, (Len(strUserName) - InStr(1, strUserName, "")))&".nsf"
wscript.echo("MailDbName :" & strMailDbName)
wscript.echo "## Getting current Notes database..."
' open the mail database in Notes
set oCurrentMailDb = oSession.CurrentDatabase
wscript.echo("fileName:" & oCurrentMailDb.fileName)
wscript.echo("filePath:" & oCurrentMailDb.filePath)
wscript.echo("server:" & oCurrentMailDb.server)
wscript.echo("Title:" & oCurrentMailDb.Title)
If oCurrentMailDb.IsOpen = True Then
' Already open for mail
wscript.echo "## Lotus Notes mail database is already open !"
Else
wscript.echo "## Opening Lotus Notes mail database..."
oCurrentMailDb.OPENMAIL
End If
' Create a document in the back end
Set oMailDoc = oCurrentMailDb.CREATEDOCUMENT
' Set the form name to memo
OMailDoc.form = "Memo"
with oMailDoc
.SendTo = "migreen@westpac.com.au"
.BlindCopyTo = "mgreen@ozemail.com.au"
.CopyTo = "migreen@westpac.com.au"
.Subject = "This is a test of VB scripting driving Lotus Notes 7 "
end with
set ortItem = oMaildoc.CREATERICHTEXTITEM("Body")
with ortItem
.AppendText("Test of RTF Item append")
.AddNewLine(2)
.AppendText("Signature")
End With
' Create additional Rich Text item and attach it
If blAttachment Then
Set ortAttacment = oMailDoc.CREATERICHTEXTITEM("Attachment")
' Function EMBEDOBJECT(ByVal TYPE As Short, ByVal CLASS As String, ByVal SOURCE As String, Optional ByVal OBJECTNAME As Object = Nothing) As Object
' Member of lotus.NOTESRICHTEXTITEM
Set oEmbedObject = ortAttacment.EMBEDOBJECT(1454, "", cstrAttachment, "Attachment")
End If
wscript.echo "## Sending email..."
with oMailDoc
.PostedDate = Now()
.SAVEMESSAGEONSEND = "True"
.send(false)
end with
wscript.echo "## Sent !"
' close objects
set oMailDoc = nothing
set oCurrentMailDb = nothing
set oSession = nothing
只需替换这些行(完全是废话,但我在另一个post中告诉过你):
strMailDbName = Left(strUserName, 1) & Right(strUserName, (Len(strUserName) - InStr(1, strUserName, "")))&".nsf"
wscript.echo("MailDbName :" & strMailDbName)
wscript.echo "## Getting current Notes database..."
' open the mail database in Notes
set oCurrentMailDb = oSession.CurrentDatabase
wscript.echo("fileName:" & oCurrentMailDb.fileName)
wscript.echo("filePath:" & oCurrentMailDb.filePath)
wscript.echo("server:" & oCurrentMailDb.server)
wscript.echo("Title:" & oCurrentMailDb.Title)
If oCurrentMailDb.IsOpen = True Then
' Already open for mail
wscript.echo "## Lotus Notes mail database is already open !"
Else
wscript.echo "## Opening Lotus Notes mail database..."
oCurrentMailDb.OPENMAIL
End If
与
strServer = "ServerNameWhereMailboxIs"
strMailDbName = "mail\nameofotherdatabase.nsf"
set oCurrentMailDb = oSession.GetDatabase( strServer, strMailDbName )
这样就可以了。
由于您的问题在我回答后发生了变化,为了将来有人发现这个问题,我会为 "sending an email in the name of another sender" 添加一些代码:
在 Lotus Notes 中,"send" 一封邮件不可能不留下真正发件人的痕迹:
当您收到这样一封由其他人发送的邮件时,您会看到该邮件来自其他邮箱,但其中包含 "Sent by" 的信息以及 [=40] 的邮件地址=]发件人。
为了至少让 "visual" 发件人看起来正确,您需要添加不同情况下需要的不同字段:这些字段是 Principal
、InetPrincipal
、From
和 InetFrom
.
但是:在正确配置的 Domino 服务器上,这无济于事:它将从 "real" 发件人计算这些字段并忽略您给他的内容。
但是有一个技巧可以让路由器单独保留这些字段:您必须将 NotesDomain 添加到地址。如果将以下行添加到代码中,路由器将忽略这些并保持字段不变:
MailDoc.principal = "noreply@company.com@NotesDomain"
MailDoc.inetprincipal = "noreply@company.com@NotesDomain"
MailDoc.from = "noreply@company.com@NotesDomain"
MailDoc.inetfrom = "noreply@company.com@NotesDomain"
如果你真的需要"hide"完全从收件人那里得到真正的发件人,那么你不能在邮件数据库中创建邮件,而是直接在服务器的"mail.box"中创建它,然后就可以了"Save" 它而不是 "Send" 它。但这还有其他缺点,这里不再讨论。
关于"send from/reply to"我只想多留一个答案,因为这个问题是我在求助时发现的:
我发现只有我自己的邮件地址会显示给外部收件人或不使用 IBM Notes 的人。即使我通过不同的邮件文件(邮寄)发送邮件,也只会显示我自己的邮寄地址,而且我也是收件人可以回复的人。所以我尝试了一些东西,它奏效了。
经过一些测试,这条线帮助我解决了内部和外部问题:
sender = """John Doe""" & "<support@domain.de>"
MailDoc.ReplyTo = sender
MailDoc.SMTPOriginator = sender
MailDoc.sender = sender
MailDoc.principal = sender
MailDoc.inetprincipal = sender
MailDoc.from = sender
MailDoc.inetfrom = sender
MailDoc.displayfrom = sender