Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Lotus notes cannot auto-reply emails that are sent by this code

Posted on 2009-04-16
28
Medium Priority
?
1,757 Views
Last Modified: 2013-12-18
I have created a simple auto-reply action agent in account B.
But when I use account A to send email to account B using the attached codes, no auto-reply to account A.


Any help is appreciated. Thanks~

Public Sub sendNotes()
 
 
        Dim recep As String() = ssMailTo
        Dim ccRecipient As String() = New String() {}
        Dim subj As String = sSubjectSend
        Dim mailbody As String = "" '"hi" + ControlChars.NewLine + "bye"
 
        Dim savemsg As Boolean
 
        open()
 
        Dim domNotesDocumentMemo As NOTESDOCUMENT
        Dim DomNotesItem As NOTESITEM
        Dim sUser As String
        Dim objNotesRichTextItem As NOTESRICHTEXTITEM
 
 
        ' Create a new memo document.
        domNotesDocumentMemo = domDB.CreateDocument
        'Call domNotesDocumentMemo.AppendItemValue("Form", "Memo")
        'Call domNotesDocumentMemo.AppendItemValue("Form", "Mail")
        Call domNotesDocumentMemo.AppendItemValue("From", domS.CommonUserName)
 
 
        Call domNotesDocumentMemo.AppendItemValue("SendTo", "")
        'Now get a handle on the item
        DomNotesItem = domNotesDocumentMemo.GetFirstItem("SendTo")
        'Now pass your array
        For Each r As String In recep
            If r <> "" Then
                Call DomNotesItem.AppendToTextList(r)
            End If
        Next
 
        'create or instantiate the item
        Call domNotesDocumentMemo.AppendItemValue("CopyTo", "")
        'Now get a handle on the item
        DomNotesItem = domNotesDocumentMemo.GetFirstItem("CopyTo")
        'Now pass your array
        For Each s As String In ccRecipient
            If s <> "" Then
                Call DomNotesItem.AppendToTextList(s)
            End If
        Next
 
        Call domNotesDocumentMemo.AppendItemValue("Subject", subj)
        objNotesRichTextItem = domNotesDocumentMemo.CreateRichTextItem("Body")
        Call objNotesRichTextItem.AppendText(mailbody)
 
        If Trim(LCase(savemsg)) = "yes" Then
            domNotesDocumentMemo.SaveMessageOnSend = True
        Else
            domNotesDocumentMemo.SaveMessageOnSend = False
        End If
        domNotesDocumentMemo.Send(False)
        domNotesDocumentMemo = Nothing
 
        close()
 
    End Sub
 
 
    Function open() As Boolean
 
        IO.File.Copy(IO.Path.Combine(IO.Directory.GetCurrentDirectory, sIDfilePath), IO.Path.Combine(notesDataPath, sIDfilePath), True)
        IO.File.Copy(IO.Path.Combine(IO.Directory.GetCurrentDirectory, "notes.ini"), IO.Path.Combine(notesPath, "notes.ini"), True)
        WritePrivateProfileString("Notes", "KeyFilename", IO.Path.Combine(notesDataPath, sIDfilePath), IO.Path.Combine(notesPath, "notes.ini"))
        WritePrivateProfileString("Notes", "MailFile", sPfile, IO.Path.Combine(notesPath, "notes.ini"))
 
        domS = New NOTESSESSION
        'domS = CreateObject("lotus.NotesSession")
        'domS = GetObject("", "Notes.Notesession")
        
 
        Call domS.Initialize(sPpassword)
        'System.Threading.Thread.Sleep(2000)
        domDB = domS.GetDatabase(sPserver, sPfile)
        'System.Threading.Thread.Sleep(2000)
 
 
        Return True
 
    End Function
 
    Sub close()
 
        domDB = Nothing
        domS = Nothing
 
        GC.Collect()
        GC.WaitForPendingFinalizers()
 
    End Sub

Open in new window

0
Comment
Question by:Hoboly
  • 11
  • 7
  • 6
  • +1
28 Comments
 

Author Comment

by:Hoboly
ID: 24155552
I have tried added domDB.Openmail
before
   domNotesDocumentMemo = domDB.CreateDocument
but Openmail is not found
0
 
LVL 5

Expert Comment

by:daj_uk
ID: 24155584
What is this written in?  Visual Basic within MS Office?

It's not valid code as a LotusScript agent or action within Lotus Notes
0
 

Author Comment

by:Hoboly
ID: 24155659
I am sorry.
This is vb.net 2003
running on windows xp with lotus notes client 6.5.4 installed
0
Restore individual SQL databases with ease

Veeam Explorer for Microsoft SQL Server delivers an easy-to-use, wizard-driven interface for restoring your databases from a backup. No expert SQL background required. Web interface provides a complete view of all available SQL databases to simplify the recovery of lost database

 
LVL 5

Accepted Solution

by:
daj_uk earned 351 total points
ID: 24155752
The very first problem seems to be that the session is not being created.

Your code has a few statements, with two remarked out...

    domS = New NOTESSESSION
    'domS = CreateObject("lotus.NotesSession")
    'domS = GetObject("", "Notes.Notesession")

I would expect this to be
     Set domS = CreateObject("Notes.Notessession")

Also, some of the initial work is being done within the Open sub, however I assume the variables are being declared somewhere else, and are global.  For example domS should be declared as

       Dim domS as Object

but more importantly it needs to be global otherwise it's context will be lost after execution of the Open() sub is complete.


0
 

Author Comment

by:Hoboly
ID: 24155929
Thanks very much.

It can send email now but still cannot auto-reply by simple action.

I have sent 2 email to account B
one is sent by UI manually and it can be auto replied
one is sent by the above code which cannot auto reply.

Attached the properties windows of 2 emails
how to modify the above code to send email that has the former mail property?

2009-04-16-mail1.jpg
2009-04-16-mail-cannot-auto-repl.jpg
0
 
LVL 5

Assisted Solution

by:daj_uk
daj_uk earned 351 total points
ID: 24155981
Running through this in my head, as I do not have access to VB at the moment, I would suggest this line needs to be in

Call domNotesDocumentMemo.AppendItemValue("Form", "Memo")

You have it commented out.

So the message is arriving in your mailbox, however the email system has no idea what kind of form it is.

0
 

Author Comment

by:Hoboly
ID: 24156118
What other form can I send?
Can I send by not using Memo?
0
 
LVL 5

Assisted Solution

by:daj_uk
daj_uk earned 351 total points
ID: 24156284
You are not sending the form, you are only telling the email system what form to use to open it.  The usual ones for mail are Memo or Reply.  If you want to use another one, put a copy of the other form in the mail file design and then

Call domNotesDocumentMemo.AppendItemValue("Form", "TheOtherForm")

Or, another way would be to attach the form as part of the email.  You would normally do that by changing the Send option to Ture, but I am not sure how that works in VB as it does not really have the form

0
 
LVL 22

Assisted Solution

by:mbonaci
mbonaci earned 693 total points
ID: 24156803
It doesn't matter where it's triggered from because he's using OLE, which is only an interface to domino classes.
To store form in document use:

Call notesDocument.Send( True )

but keep in mind that this dramatically increases the e-mail size.
Why do you want to do that?

Another thing, this whole part here:

        'create or instantiate the item
        Call domNotesDocumentMemo.AppendItemValue("CopyTo", "")
        'Now get a handle on the item
        DomNotesItem = domNotesDocumentMemo.GetFirstItem("CopyTo")
        'Now pass your array
        For Each s As String In ccRecipient
            If s <> "" Then
                Call DomNotesItem.AppendToTextList(s)
            End If
        Next


You can do like this:
Call domNotesDocumentMemo.ReplaceItemValue( "CopyTo", ccRecipient )


Here's the working example that creates mail and instead of sending it, it opens it for editing:
Private Sub ComposeNotesMail()
	Dim oSess As Object
	Dim oMailDB As Object
	Dim oMailDoc As Object
	Dim oBody As Object
 
	Dim ws As Object
	Dim uidoc
 
	Dim mailsvr
	Dim mailfile
 
	Set oSess = CreateObject("Notes.NotesSession")
 
	mailsvr = oSess.GetEnvironmentString("MailServer", True)
	mailfile = LCase(oSess.GetEnvironmentString("MailFile", True))
 
	Set oMailDB = oSess.GETDATABASE("", "")
	Call oMailDB.open(mailsvr, mailfile)
 
	If oMailDB.isopen Then
		Set oMailDoc = oMailDB.CREATEDOCUMENT
	Else
		MsgBox "Could not open Notes", 32
	End If
 
	oMailDoc.subject = "Test mail"
	oMailDoc.Form = "Memo"
 
	Set oBody = oMailDoc.CREATERICHTEXTITEM("BODY")
 
	Call oBody.Embedobject(1454, "", "c:\Testattachment.htm")
 
	Set ws = CreateObject("Notes.NotesUIWorkspace")
	Set uidoc = ws.editdocument(True, oMailDoc, False)
 
	Set oSess = Nothing
	Set oMailDB = Nothing
	Set oMailDoc = Nothing
	Set ws = Nothing
	Set uidoc = Nothing
End Sub

Open in new window

0
 
LVL 22

Assisted Solution

by:mbonaci
mbonaci earned 693 total points
ID: 24156893
If you still cannot reply to e-mail add:

Call domNotesDocumentMemo.ReplaceItemValue( "ReplyTo", domS.UserName )
0
 

Author Comment

by:Hoboly
ID: 24164840
Could I ComposeNotesMail as background insteading of calling UI to do so?
because it's a auto batch program
many emails are needed to send from different accounts to different accounts
0
 

Author Comment

by:Hoboly
ID: 24164845
I have tried uncommented
Call domNotesDocumentMemo.AppendItemValue("Form", "Memo")

still cannot autoreply
0
 
LVL 22

Assisted Solution

by:mbonaci
mbonaci earned 693 total points
ID: 24165647
I just posted the code as an example. Use your code.
Have you added ReplyTo field?

Use ReplaceItemValue instead of AppendItemValue, cuz' append, if item with that name already exists, creates another item with the same name.
Although you're creating a new doc, and the problem shouldn't be an issue, I suggest you forget about append and use replace from now on...

Post your code after all these changes for me, to look at.
0
 
LVL 46

Assisted Solution

by:Sjef Bosman
Sjef Bosman earned 456 total points
ID: 24165675
Key questions being:
- what mail client is used to reply?
- what is the reply address?

If you want to force a reply address, create a field Principal in the mail and set it to a reasonable value.
0
 
LVL 22

Assisted Solution

by:mbonaci
mbonaci earned 693 total points
ID: 24167357
To cover all the bases add also this line:

Call domNotesDocumentMemo.ReplaceItemValue( "$INETReplyTo", domS.UserNameObject.Addr821 )

and then try replying...
0
 

Author Comment

by:Hoboly
ID: 24181756
still cannot auto-reply :(

 
    Public Sub sendEmail()
 
 
        Dim recep As String() = ssMailTo
        Dim ccRecipient As String() = New String() {}
        Dim subj As String = sSubjectSend
        Dim mailbody As String = "" '"hi" + ControlChars.NewLine + "bye"
 
        Dim savemsg As Boolean
 
        open()
 
 
        Dim domNotesDocumentMemo As NotesDocument
        Dim DomNotesItem As NotesItem
        Dim sUser As String
        Dim objNotesRichTextItem As NotesRichTextItem
 
 
 
        'Dim mail_server As String = domS.GetEnvironmentString("MailServer", True)
        'Dim mail_file As String = domS.GetEnvironmentString("MailFile", True)
 
        'domDir = domS.GetDbDirectory(sPserver)
        'domDB = domDir.OpenMailDatabase()
 
        ' Create a new memo document.
        domNotesDocumentMemo = domDB.CreateDocument
        Call domNotesDocumentMemo.ReplaceItemValue("Form", "Memo")
        'Call domNotesDocumentMemo.AppendItemValue("Form", "Mail")
        Call domNotesDocumentMemo.ReplaceItemValue("From", domS.CommonUserName)
        'Call domNotesDocumentMemo.ReplaceItemValue("$INETReplyTo", domS.UserNameObject.Addr821)
        'Call domNotesDocumentMemo.ReplaceItemValue("$INETReplyTo", domS.UserName)
        Call domNotesDocumentMemo.ReplaceItemValue("ReplyTo", domS.UserName)
        Call domNotesDocumentMemo.ReplaceItemValue("Principal", domS.UserName)
        Call domNotesDocumentMemo.ReplaceItemValue("$AssistMail", Nothing)
        Call domNotesDocumentMemo.ReplaceItemValue("$TITLE", Nothing)
        Call domNotesDocumentMemo.ReplaceItemValue("InetSendTo", recep)
        'Call domNotesDocumentMemo.ReplaceItemValue("Form", "Memo")
        Call domNotesDocumentMemo.ReplaceItemValue("useApplet", True)
        Call domNotesDocumentMemo.ReplaceItemValue("DefaultMailSaveOptions", "1")
 
        'Call domNotesDocumentMemo.AppendItemValue("SendTo", "")
        ''Now get a handle on the item
        'DomNotesItem = domNotesDocumentMemo.GetFirstItem("SendTo")
        ''Now pass your array
        'For Each r As String In recep
        '    If r <> "" Then
        '        Call DomNotesItem.AppendToTextList(r)
        '    End If
        'Next
 
        Call domNotesDocumentMemo.ReplaceItemValue("SendTo", recep)
        Call domNotesDocumentMemo.ReplaceItemValue("CopyTo", ccRecipient)
 
        Call domNotesDocumentMemo.AppendItemValue("Subject", subj)
        objNotesRichTextItem = domNotesDocumentMemo.CreateRichTextItem("Body")
        Call objNotesRichTextItem.AppendText(mailbody)
 
        If Trim(LCase(savemsg)) = "yes" Then
            domNotesDocumentMemo.SaveMessageOnSend = True
        Else
            domNotesDocumentMemo.SaveMessageOnSend = False
        End If
        domNotesDocumentMemo.Send(True)
        domNotesDocumentMemo = Nothing
 
        close()
 
    End Sub

Open in new window

cannot-reply.jpg
0
 
LVL 22

Assisted Solution

by:mbonaci
mbonaci earned 693 total points
ID: 24182609
Where do you log the line "Replied to 0 documents" to the agent log?
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 24182613
Er, forgive me if I don't understand. The Agent Log you show above is clearly of a Notes Agent. The line "Replied to 0 document(s)" seems to have been generated by that agent in the code, but that is not your code. What exactly IS your code? Where does it get executed? What are we looking at? AFAIK, a Notes client is not capable of executing VB.NET code, but you might have found a way.

Can you clear this up for me??
0
 
LVL 22

Expert Comment

by:mbonaci
ID: 24182621
:)
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 24182634
Two great minds...  :-P
0
 
LVL 22

Assisted Solution

by:mbonaci
mbonaci earned 693 total points
ID: 24182657
I always thought you want to be able to Reply to e-mail (to another person, not to one who sent it) that's being sent by your agent.
And now it seems that you want your agent to reply to e-mail.

If I'm right, to which mail doc the agent should reply?
Give us the whole story...
0
 

Author Comment

by:Hoboly
ID: 24182809
Sorry for mis-understanding...

>>I have created a simple auto-reply action agent in account B.
>>But when I use account A to send email to account B using the attached codes, no auto-reply to account A.

vb.net code is to send email from account A to account B
the latest "Replied to 0 document(s)"  screen capture is auto-reply simple action agent in account B when I right click the agent and click run
cannot-reply2.jpg
0
 
LVL 46

Assisted Solution

by:Sjef Bosman
Sjef Bosman earned 456 total points
ID: 24182875
IMHO, the Send(True) isn't useful, better set that to Send(False). There's no point in sending the Memo-form to a Notes client that already has the identical form in the mail.

Can you eliminate one step? I suspect the simple reply agent. I'd like to know what happens if a person tries to reply (manually) to the mail he received. Is everything correct then? Maybe we're trying to find the fault in your code where there is none...
0
 

Author Comment

by:Hoboly
ID: 24196581
I have tried the following situations:
1. when I send email manually from a/c A to B, simply reply agent can reply automatically.
2. when I send email by the above code from a/c A to B, simply reply agent cannot reply.
3. manually reply the email in above 2 items, no problems
0
 
LVL 46

Assisted Solution

by:Sjef Bosman
Sjef Bosman earned 456 total points
ID: 24199875
Ok, so if we would develop a non-simple agent that sends a reply, it might work?

I assume that you see both incoming mails, i.e. the manual and the automatic one, in your Inbox. Can you please look at the differences in those mails? I'll explain: go to the Inbox, click ONCE on the manual mail, then type Alt-Enter (or click File/Document/Properties) to show the Document Properties window. Walk through the names of the fields and write them down. Do the same for the automatic mail. What fields are missing in the automatic mail?
0
 

Author Comment

by:Hoboly
ID: 24201350
>>Ok, so if we would develop a non-simple agent that sends a reply, it might work?
Yes but too slow. some times, 12-hours to run the agent.
another question was asked....
http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/Lotus_SmartSuite/Lotus_Notes/Q_24342201.html

>>I assume that you see both incoming mails, i.e. the manual and the automatic one, in your Inbox.
Yes.

>>Can you please look at the differences in those mails? I'll explain: go to the Inbox, click ONCE on the manual mail, then type Alt-Enter (or click File/Document/Properties) to show the Document Properties window. Walk through the names of the fields and write them down. Do the same for the automatic mail. What fields are missing in the automatic mail?

yes, attached in above: 16/04/09 02:58 AM, ID: 24155929
I added the following code for the different. still can't solve the problem :(

        Call domNotesDocumentMemo.ReplaceItemValue("Form", "Memo")
        'Call domNotesDocumentMemo.AppendItemValue("Form", "Mail")
        Call domNotesDocumentMemo.ReplaceItemValue("From", domS.CommonUserName)
        'Call domNotesDocumentMemo.ReplaceItemValue("$INETReplyTo", domS.UserNameObject.Addr821)
        'Call domNotesDocumentMemo.ReplaceItemValue("$INETReplyTo", domS.UserName)
        Call domNotesDocumentMemo.ReplaceItemValue("ReplyTo", domS.UserName)
        Call domNotesDocumentMemo.ReplaceItemValue("Principal", domS.UserName)
        Call domNotesDocumentMemo.ReplaceItemValue("$AssistMail", Nothing)
        Call domNotesDocumentMemo.ReplaceItemValue("$TITLE", Nothing)
        Call domNotesDocumentMemo.ReplaceItemValue("InetSendTo", recep)
        'Call domNotesDocumentMemo.ReplaceItemValue("Form", "Memo")
        Call domNotesDocumentMemo.ReplaceItemValue("useApplet", True)
        Call domNotesDocumentMemo.ReplaceItemValue("DefaultMailSaveOptions", "1")
 
0
 
LVL 46

Assisted Solution

by:Sjef Bosman
Sjef Bosman earned 456 total points
ID: 24202208
> Yes but too slow. some times, 12-hours to run the agent.
That is not a reply to my question. If an agent is slow, then any agent will be slow.
Would it help if we help you translate your simple agent into LotusScript? To have more control over what happens?

> yes, attached in above: 16/04/09 02:58 AM, ID: 24155929
Well, those are just images, and only of a part of the fields in the mails. I'd like you to compare ALL fields, one by one...

Required:
        Call domNotesDocumentMemo.ReplaceItemValue("Form", "Memo")

Please comment out:
        Call domNotesDocumentMemo.ReplaceItemValue("From", domS.CommonUserName)
        Call domNotesDocumentMemo.ReplaceItemValue("ReplyTo", domS.UserName)
        Call domNotesDocumentMemo.ReplaceItemValue("Principal", domS.UserName)
        Call domNotesDocumentMemo.ReplaceItemValue("$AssistMail", Nothing)
        Call domNotesDocumentMemo.ReplaceItemValue("$TITLE", Nothing)
        Call domNotesDocumentMemo.ReplaceItemValue("InetSendTo", recep)
        Call domNotesDocumentMemo.ReplaceItemValue("useApplet", True)

And check if a MANUAL reply still works when you send a mail with the modified code.

I still kindof suspect the simple reply agent... Maybe it doesn't work properly in some cases. If we don't eliminate that possibility we could continue to to ask "Why?" till kingdom come...
0
 

Author Closing Comment

by:Hoboly
ID: 31570871
There is still un-resolved but my company has got some work-around.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
The new Gmail Phishing Scam going around is surprising even the savviest of users with its sophisticated techniques.
In this video we show how to create a Contact in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Recipients >> Contact ta…
The basic steps you have just learned will be implemented in this video. The basic steps are shown to configure an Exchange DAG in a live working Exchange Server Environment and manage the same (Exchange Server 2010 Software is used in a Windows Ser…

581 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question