如何用VB脚本和其他邮箱发送Lotus Notes邮件

时间:2015-12-17 05:59:18

标签: vbscript lotus-notes sendmail

您好我正在用VB脚本发送Lotus Notes邮件。现在我想用其他邮箱发送邮件,这个邮箱是在我的莲花笔记中打开的,而不是我的邮箱。我尝试了不同的选择,但没有运气。我使用下面的代码发送邮件。

您可以在以下网址找到代码:

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

2 个答案:

答案 0 :(得分:1)

只需更换一行(完全是胡说八道,但我在另一篇文章中告诉你):

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 )

这样就可以了。

在我的回答之后你的问题发生了变化,我将 - 为了将来找到这个问题的任何人 - 添加一些代码以及#34;以另一个发件人的名义发送电子邮件":

在Lotus Notes中,无法发送"发送"邮件没有留下真正发送邮件的人的痕迹:

当您收到这样的邮件时,您会看到该邮件来自其他邮箱,但邮件中包含的信息是"与#34;真实"的mailaddress发件人。

至少制作" visual"发件人看起来正确,您需要添加不同情况下所需的不同字段:这些字段为PrincipalInetPrincipalFromInetFrom

但是:在配置正确的Domino服务器上,这没有帮助:它将从" real"中计算这些字段。发件人并忽略你给他的东西。

但是有一个技巧可以让路由器单独留下这些字段:你必须将NotesDomain添加到adressen。如果您在代码中添加以下行,则路由器将忽略这些行并保持字段不变:

MailDoc.principal = "noreply@company.com@NotesDomain"
MailDoc.inetprincipal = "noreply@company.com@NotesDomain"
MailDoc.from = "noreply@company.com@NotesDomain"
MailDoc.inetfrom = "noreply@company.com@NotesDomain"

如果你真的需要"隐藏"真正的发件人完全来自收件人,那么你不能在邮件数据库中创建邮件,而是直接在" mail.box"中创建邮件。服务器,只是"保存"而不是"发送"它。但这有其他缺点,这里不再讨论。

答案 1 :(得分:0)

我只想留下一个有关“发送自/回复到”的答案,因为这个问题是我在寻求帮助时发现的:

我发现只有我自己的mailadress会显示给外部收件人或不使用IBM笔记的人。即使我通过其他邮件文件(“邮件”)发送邮件,也只会显示我自己的mailadress,而我也是收件人可以回复的邮件。因此,我尝试了一些方法,结果奏效。

经过一些测试,这些行帮助我了解了内部和外部:

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