Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 306
  • Last Modified:

Sending mail via agent problem - 2 copies of email

Hi All,
I have created an agent that sends out a customised email to people registered on a web site. I use code i have used in other agents that do the same thing and they work perfectly, this one though is a bit different in that it doesn't send a single email like the others, instead it loops through a list of all web site members registered to receive the email and sends out a customises email to them. However some people get two copies of this email, one in their inbox and another in their "draft" folder, this ONLY happens to Lotus users, people with other email clients do not get this extra email.

Anyone have any ideas on how i can fix this?



0
HRT_HSV
Asked:
HRT_HSV
  • 7
  • 4
  • 3
  • +1
1 Solution
 
zvonkoCommented:
Look for this mails arriving into Draft view by accident.
Compare their document item values with the Draft view selection formula.
The regular Draft view selection formula is:
SELECT PostedDate = "" & $MessageType = "" & @IsNotMember("D";ExcludeFromView) & ISMAILSTATIONERY != 1 & Form != "Person"

That means, either is PostedDate and $MessageType empty in your mails, or somebody changed the view selection formula in your installation to something else.

Good luck,
zvonko

0
 
HRT_HSVAuthor Commented:
Thanks zvonko
How can i make sure that PostedDate and $MessageType are not empty?

Can i actually specify their values at the time i am creating the mails?

This is part of my code with error checking taken out, like i said it all works except for the draft copy thing. What do i do to fix the problem?:

Function testmail(_
sendTo As String, _
cc As String, _
bcc As String, _
subject As String, _
body As String, server As String) As String

Dim mailboxDb As New NotesDatabase(server, "mail.box")
     Dim mailDoc As NotesDocument
     Dim rtItem As NotesRichTextItem
     
     Set mailDoc = mailboxDb.CreateDocument
     mailDoc.Form = "Memo"
     mailDoc.From = "sender@anysite.com"
     mailDoc.SendTo = sendTo
     mailDoc.Recipients = sendTo
     mailDoc.CC = cc
     mailDoc.BCC = bcc
     mailDoc.Subject = subject
     Set rtItem = mailDoc.CreateRichTextItem("Body")
     Call rtItem.AppendText(body)
     If strAttach <> "none" Then
          rtItem.EmbedObject EMBED_ATTACHMENT,"",strAttach          
     End If
     
     Call mailDoc.Save(True,False,False)
End Function

0
 
zvonkoCommented:
You make jokes :-)

This is an absolutely unclean method to get mails sent!

Normal way is to create a document object in the database your agent is actually running and use this NotesDocument method afterwards:
Call doc.Send(True)

And only if you like a mail copy stay saved in this database where you initiated the male use the doc.Save() method.

In your function you have to exchange this line:
Dim mailboxDb As New NotesDatabase(server, "mail.box")

to something like this:
Dim session As New NotesSession
Dim mailboxDb As NotesDatabase
Set mailboxDb = session.CurrentDatabase

and the Save line like this:
Call mailDoc.Send(True)

Good luck,
zvonko

0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
HRT_HSVAuthor Commented:
oh ok, thanks for the info, new to this.

But will this work even if my Agent is not in the mail box database?

I thought to send mail you have to use the memo form? If this agent is not in the mail box database then the memo form isn't available to me and the line:
 mailDoc.Form = "Memo"

will produce an error won't it?

So the rest of the code will continue to work fine if i just change the lines you mention? Allowing me to customise who it is from,subject etc?

thanks again
0
 
Jean Marie GeeraertsApplication EngineerCommented:
Yes, you can send mail from anywhere. The memo form doesn't need to be available.
You can create a custom mail form if you want to use a standard layout for automated mails (I do this, to make it clear to users that this is an automated mail they should not respond to).

The send method has the following parameters syntax:

Call notesDocument.Send( attachForm [, recipients ] )

If you specify True for attachForm, the form you use to create the mail will be sent along with the mail, otherwise the default memo form is used.
If you do not specify recipients in SendTo field, you can specify an array of recipients as a second parameter.

Hope this helps,
JM
0
 
zvonkoCommented:
The only feature that will not work is the From field :-)

And this was the only reason for this unclean method to be used.

Instead of From you can use a surrogate field: Principal

The Memo form is in everyone's mail database as default form. That mean you need not to declare the Form item.

But when you set the first parameter of NotesDocument.Send method to True then you have to declare a form name in the Form field and have to have the declared Form existing in used database. It has to be there to be embedded.

Regards,
zvonko

0
 
Jean Marie GeeraertsApplication EngineerCommented:
I use the ReplyTo field to make sure replies are sent to the right person :-)
0
 
zvonkoCommented:
That's correct JM, but most programmer like to avoid to be visible/responsible as agent signer for mail sending. And this is only possible with mail.box method or with Principal field. They are still contained in sender field but Principal get visible sender content.

0
 
Jean Marie GeeraertsApplication EngineerCommented:
ReplyTo is never the programmer. It's always a responsible contact person, so it can be visible :-)
So, if you put the name to respond to in 'Principal' you can respond, but you don't see to who you respond?
0
 
HRT_HSVAuthor Commented:
I tried adding the following code to the database:

maildoc.Principal = "xxxxxx"
maildoc.ReplyTo = "me@whereva.com"

and the reply to works but i still get a sent by:"name of agent signer" withing the message header.

wasn't the Principal field meant to fix this problem?


As zvonko stated this 'unclean' method was used for that purpose. There must be a way to get rid of this problem using the clean method, after all one would think it is a basic functionality that all automated email processing functions should have.

great help so far by the way guys.


0
 
zvonkoCommented:
:)

This Principal is a little tricky.

Try this:
maildoc.Principal = "NotesCommonName@NotesDomain"

or this:
maildoc.Principal = "internetEmail@InternetDomain@NotesDomain"

In both cases is best choice to use a mailin database address.

Good luck,
zvonko



0
 
HRT_HSVAuthor Commented:
thanks i'll give that principal thing a try.
0
 
zvonkoCommented:
Thanks for the points :-)

0
 
ArunkumarCommented:
Good Shot Buddy!
0
 
zvonkoCommented:
Thanks :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 7
  • 4
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now