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

Vbscript 如何在VB脚本中添加多个CC地址发送邮件,vbscript,lotus-notes,sendmail,lotusscript,Vbscript,Lotus Notes,Sendmail,Lotusscript,如何在VB脚本发送邮件的抄送列表中添加多个电子邮件地址 option explicit ' -------------------------------------------------------------------------- ' -- Create Lotus Notes email (and add attachment) using VB Script ' -- ' -- Version 1.01 ' -- ' -- Created by : Michael

如何在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 
只需使用数组来设置值

使用oMailDoc的

.SendTo=数组(“migreen@westpac.com.au", "mgreen@westpac.com.au", "green@westpac.com.au" )
.BlindCopyTo=”mgreen@ozemail.com.au"  
.CopyTo=”migreen@westpac.com.au" 
.Subject=“这是对驱动Lotus Notes 7的VB脚本的测试”
以
最初,我根本不想对复制的代码的质量发表评论。但与兰克马特的讨论让我想,最好对此发表评论

Set oSession=CreateObject(“Notes.notession”)
这一行创建了一个到运行Notes客户端的OLE接口。如果客户端未运行,则将启动它。如果您使用了
setosession=CreateObject(“Lotus.NotesSession”)
,那么您将得到一个COM对象。请注意,有些OLE方法在COM中不起作用,反之亦然。e、 g.
oCurrentMailDb.OPENMAIL
是OLE,而COM中的相同内容是
oCurrentMailDb.OpenMailDatabase()

“例如,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中抛出一个错误,并且如果数据库打开,我们将永远无法到达它检查的下一行

这一行的问题是:可以从LotusNotes中的任何数据库发送邮件。如果打开的数据库(例如)是个人通讯簿,则邮件将保存并从那里发送(并且您永远不会在邮件文件的“发送”视图中找到它)

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


其余的代码似乎没有问题。

尝试传递数组或逗号分隔的字符串。如果我传递的是列表中只有第一个收件人正在接收邮件,则不会。根据文档和COM应使用
.OpenMailDatabase
,这使我认为此脚本是一个奇怪的组合。这两种语言都是基本语言,所以将会有相似之处。你能在问题中展示一些你的输出吗?注意这里有很多应该输出的
WScript.Echo
语句,如果能看到它落在哪里就好了。根据文档,当你试图在VBScript中使用COM组件做这件事时,你应该使用方法。
as String
?不是在VBScript中,所有的东西都是
变量
没有强类型的东西。放弃数组,使用Split,比如.sendTo=Split(“addr1,addr2,addr3”,”)@D.Bugger或
。sendTo=array(“…”,“…”,“)
谢谢大家,如果我按照上面的注释定义的话,效果很好。谢谢大家的解释。