如何在VB脚本中添加多个CC地址发送邮件

时间:2015-12-09 11:17:19

标签: vbscript lotus-notes sendmail lotusscript

如何在CC列表中为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

2 个答案:

答案 0 :(得分:3)

只需使用数组来设置值

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") 

此行为正在运行的Notes客户端创建一个OLE接口。如果客户端未运行,则将启动它。如果您使用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" 

吸引用户' mailfile完全是胡说八道,代码将获得除正确文件名之外的所有内容。由于变量根本没有使用 - 可以忘记

set oCurrentMailDb = oSession.CurrentDatabase 

只获取当前在客户端中打开的数据库。如果没有打开数据库,则会在下一个wscript.echo行中抛出错误,如果数据库打开,我们将永远不会到达检查的下一行......

此行的问题:可以从Lotus Notes中的任何数据库发送邮件。如果数据库是打开的,例如是个人地址簿,然后邮件将被保存并从那里发送(你永远不会在邮件文件的发送视图中找到它。

我建议首先使用OPENMAIL,如果失败则只回退到当前打开的数据库。

其余代码似乎没问题。

答案 1 :(得分:0)

创建一个电子邮件地址字符串数组并将CopyTo设置为该数组:

UNIQUE