如何在VB脚本发送邮件中添加多个抄送地址
How to add multiple CC addresses in VB script send mail
如何在抄送列表中为 VB 脚本发送邮件添加多个电子邮件地址。
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
创建电子邮件地址字符串数组并将 CopyTo 设置为该数组:
Dim addresses (2)
addresses(0) = "EMAIL"
addresses(1) = "EMAIL"
addresses(2) = "EMAIL"
with oMailDoc
.SendTo = "migreen@westpac.com.au"
.BlindCopyTo = "mgreen@ozemail.com.au"
.CopyTo = addresses
.Subject = "This is a test of VB scripting driving Lotus Notes 7 "
end with
只需使用数组设置值
with oMailDoc
.SendTo = Array( "migreen@westpac.com.au", "mgreen@westpac.com.au", "green@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
本来我根本不想评论复制代码的质量。但是和Lankymart的讨论让我觉得,评论一下就好了。
Set oSession = CreateObject("Notes.NotesSession")
此行创建一个 OLE 接口到 运行ning Notes-Client。如果客户端没有运行,那么它将被启动。如果您使用 Set oSession = CreateObject("Lotus.NotesSession")
那么您得到的将是一个 COM 对象。请注意,某些 OLE 方法在 COM 中不起作用,反之亦然。例如oCurrentMailDb.OPENMAIL
是 OLE,而在 COM 中同样是 oCurrentMailDb.OpenMailDatabase()
' 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"
获取用户的邮件文件完全是无稽之谈,除了正确的文件名外,代码将获取所有内容。由于变量根本没有被使用——可以被遗忘
set oCurrentMailDb = oSession.CurrentDatabase
只是获取客户端当前打开的数据库。如果没有打开的数据库,将在下一个 wscript.echo- 行抛出一个错误,并且我们将永远不会到达它检查的下一行,如果一个数据库是打开的...
此行的问题:可以从 Lotus Notes 中的任何数据库发送邮件。如果打开的数据库,例如是个人地址簿,那么邮件将被保存并从那里发送(你永远不会在邮件文件的已发送视图中找到它。
我建议首先使用 OPENMAIL,如果失败则只回退到当前打开的数据库。
其余代码似乎没问题。
如何在抄送列表中为 VB 脚本发送邮件添加多个电子邮件地址。
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
创建电子邮件地址字符串数组并将 CopyTo 设置为该数组:
Dim addresses (2)
addresses(0) = "EMAIL"
addresses(1) = "EMAIL"
addresses(2) = "EMAIL"
with oMailDoc
.SendTo = "migreen@westpac.com.au"
.BlindCopyTo = "mgreen@ozemail.com.au"
.CopyTo = addresses
.Subject = "This is a test of VB scripting driving Lotus Notes 7 "
end with
只需使用数组设置值
with oMailDoc
.SendTo = Array( "migreen@westpac.com.au", "mgreen@westpac.com.au", "green@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
本来我根本不想评论复制代码的质量。但是和Lankymart的讨论让我觉得,评论一下就好了。
Set oSession = CreateObject("Notes.NotesSession")
此行创建一个 OLE 接口到 运行ning Notes-Client。如果客户端没有运行,那么它将被启动。如果您使用 Set oSession = CreateObject("Lotus.NotesSession")
那么您得到的将是一个 COM 对象。请注意,某些 OLE 方法在 COM 中不起作用,反之亦然。例如oCurrentMailDb.OPENMAIL
是 OLE,而在 COM 中同样是 oCurrentMailDb.OpenMailDatabase()
' 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"
获取用户的邮件文件完全是无稽之谈,除了正确的文件名外,代码将获取所有内容。由于变量根本没有被使用——可以被遗忘
set oCurrentMailDb = oSession.CurrentDatabase
只是获取客户端当前打开的数据库。如果没有打开的数据库,将在下一个 wscript.echo- 行抛出一个错误,并且我们将永远不会到达它检查的下一行,如果一个数据库是打开的...
此行的问题:可以从 Lotus Notes 中的任何数据库发送邮件。如果打开的数据库,例如是个人地址簿,那么邮件将被保存并从那里发送(你永远不会在邮件文件的已发送视图中找到它。
我建议首先使用 OPENMAIL,如果失败则只回退到当前打开的数据库。
其余代码似乎没问题。