-1

Hi I am sending lotus notes mail with VB script . Now I want to send mail with other mail box which is opened in my lotus notes instead of my mail box. I tried different options but no luck. I am using below code to send mail.

You can find the code in below 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
  • Please learn that you should post CODE and not LINKS!!! Nobody wants to read the code on the other page just to answer the question here and switch forward and backward between code and answer... – Tode Dec 17 '15 at 10:57
  • What do you mean by "send mail with other mail box"? Do you mean you want a message to be sent with the From address set to someone else's address rather than your own? – Richard Schwartz Dec 17 '15 at 15:37
  • 2
    Possible duplicate of [Set 'From' email address in Lotus Notes when sending via VBA](http://stackoverflow.com/questions/23696426/set-from-email-address-in-lotus-notes-when-sending-via-vba) – Richard Schwartz Dec 17 '15 at 21:18

2 Answers2

1

Just replace the lines (that are complete nonsense, but I told you in the other 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 

with

strServer = "ServerNameWhereMailboxIs"
strMailDbName = "mail\nameofotherdatabase.nsf"
set oCurrentMailDb = oSession.GetDatabase( strServer, strMailDbName )

That will do the trick.

As your question changed after my answer, I will -for the sake of anybody finding this question in the future- add some code for "sending an email in the name of another sender":

In Lotus Notes it is not possible to "send" a mail without leaving traces of the person who really sent it:

When you receive such a mail, that was sent by someone else you will see, that the mail comes from the other mailbox, but it will contain the information "Sent by" with the mailaddress of the "real" sender.

To at least make the "visual" sender look right, you need to add different fields that are needed in different cases: These fields are Principal, InetPrincipal, From and InetFrom.

However: On a Domino- Server that is configured right, this will not help: It will calculate these fields from the "real" sender and ignore what you gave him.

But there is a trick to make the router leave these fields alone: You have to add the NotesDomain to the adressen. If you add the following lines to your code, then the router will ignore these and keep the fields intact:

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

If you really need to "hide" the real sender completely from the recipient, then you cannot create the mail in the mail database, but create it directly in the "mail.box" of the server and just "Save" it instead of "Send" it. But this has other downsides and will not be discussed here.

Tode
  • 11,795
  • 18
  • 34
  • Hi Torsten thanks for prompt response. Even with those changes Mail is sending with primary mail name instead of added Mail db. It should go with the name of added Mail DB – Performance tester Dec 17 '15 at 12:29
  • Once again: Do you UNDERSTAND the code that you use? Try it... then you can answer that question yourself... – Tode Dec 17 '15 at 12:31
  • Ya Torsten am able to send mails but sender name is primary mail box name instead of added mail box name – Performance tester Dec 17 '15 at 12:34
  • @TorstenLink It's pointless trying to help this OP. They haven't taken onboard what you said last time doubt they will listen now. Fundamentally they don't understand the code in the first place. – user692942 Dec 17 '15 at 12:36
  • I suspect the OP wants to send email with a From address other than his own. Switching mail databases doesn't accomplish that. – Richard Schwartz Dec 17 '15 at 15:38
  • 2
    @Richard: I think you are absolutely right. But I will not put any more effort in answering this OPs questions than he does in writing his questions, and I will not start "reading minds"... – Tode Dec 17 '15 at 15:54
  • 1
    You may notice that I haven't offered an answer either. :-) I am, however, going to vote to close, because assuming I'm right about the interpretation, this is a duplicate of another stackoverflow quesiton. – Richard Schwartz Dec 17 '15 at 21:17
  • You are right, this question is a duplicate, but it is a duplicate of at least two different questions as it is written so ambigiously... – Tode Dec 17 '15 at 22:05
  • Hi @Richard Thanks for your help. I am not working on lotus note and VB script so I dont know the exact syntax's what I need to use to achieve this . With this just I want to automate my existing process. Any way thanks for the help . You guys helped me a lot. – Performance tester Dec 18 '15 at 05:58
0

I just want to leave one more answer about "send from/reply to" because this question here is what I found when I was searching for help:

I found out that only my own mailadress is shown to external recipients or people not using IBM notes. Even if I sent mails via a different mailfile (a Mail-In) only my own mailadress was shown and I also was the one the recipient could reply to. So I tried something, and it worked.

After some testing, this lines helped me out internal and external:

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