Link to home
Start Free TrialLog in
Avatar of shuboarder
shuboarderFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Annoying send mail problem

Second pair of eyes needed....

Can someone tell me why this won't send the email?
This code I have done in a button on a form.
The fields are populating ok, but the mail is not being sent.
Thanks.

FIELD request_status:= "Approved";
FIELD sendto:= @Text(requestee_lookup);
FIELD subject:= "Your request has been approved";
FIELD body:="The following request has been approved:" + @NewLine + " "
+ @NewLine + "Name" + ": " + requestee_name  + " "
+ @NewLine + "Site" + ": " + requestee_site  + " "
+ @NewLine + "Dept" + ": " + requestee_dept  + " "
+ @NewLine + "Book / Cancel" + ": " + bookorcancel  + " "
+ @NewLine + "Number of Days" + ": " + @Text(number_days)  + " "
+ @NewLine + "Between The Following Dates" + ": " + @Text(start_date) + " - " + @Text(end_date)  + " "
+ @NewLine + "Status" + ": " + request_status  + " "
+ @NewLine + "By" + ": " + Manager_CommonName  + " "
+ @NewLine + "Comments" + ": " + manager_comments  + " "
+ @NewLine + @NewLine +
"Please click the link below to view the document"
+ @NewLine + @NewLine;
@MailSend( SendTo; ""; ""; Subject; ""; Body; [IncludeDoclink] );
@Command([FileSave]);
@Command([CloseWindow])
Avatar of madheeswar
madheeswar
Flag of Singapore image

Write it in Lotus Script.

Sample code:

Dim session As New NotesSession
Dim db As NotesDatabase
Dim doc As NotesDocument
Dim newDoc As NotesDocument
Dim rtitem As NotesRichTextItem
Dim item As NotesItem
Dim item1 As notesitem
Dim object As NotesEmbeddedObject
Dim DummyObject As NotesEmbeddedObject
Dim richStyle As NotesRichTextStyle

Set richStyle = session.CreateRichTextStyle
Set db = session.CurrentDatabase
Set doc=session.documentContext
Set newDoc=New notesdocument(db)
Set rtitem=New notesrichtextitem(newDoc,"Body")
richStyle.NotesColor = COLOR_BLUE
richStyle.Bold = True
richStyle.Underline = True
Call rtitem.AppendStyle(richStyle)
Call rtitem.appendtext ( "Consumer Name and Address" )
richStyle.Bold = False
richStyle.underline = False
richStyle.NotesColor=False
Call rtitem.AppendStyle(richStyle)
Call rtitem.addnewline (1)

If (doc.MName(0)="") Then
Call rtitem.appendtext ( doc.FName(0) +" "+doc.LName(0))
Call rtitem.addnewline (1)
Else
Call rtitem.appendtext ( doc.FName(0) +" "+doc.MName(0)+" "+doc.LName(0))
Call rtitem.addnewline (1)
End If
Call rtitem.appendtext(doc.StreetAddress(0))
Call rtitem.addnewline (1 )
'Adds the Doc Attachment to the Mail
If doc.HasEmbedded And doc.HasItem("$File") Then
Set item = doc.GetFirstItem("$File")
Forall v In item.Values
Set object = doc.GetAttachment(v)
filename$ = item.Values(0)
FilePath$ = "c:\temp\" +filename$
Call object.ExtractFile(FilePath$)
Set DummyObject = rtitem.EmbedObject( EMBED_ATTACHMENT,"" , FilePath$)
End Forall
End If

Call newDoc.replaceItemValue("Form","Memo")
Call newDoc.replaceItemValue("Subject","Web--"+doc.FName(0) +" "+doc.LName(0)+".")
Call newDoc.replaceItemValue("SendTo","Kirankumar")
Call newDoc.replaceItemValue("ReplyTo",doc.EMail(0))
Call newDoc.send(False)

Avatar of Sjef Bosman
I think it's got to do with the IncludeDoclink, the funcion is likely not to work on an open document. Plus, you have to put the names of the fields in quotes, otherwise the field itself will be interpreted.

    @MailSend( SendTo; ""; ""; Subject; ""; "Body"; [IncludeDoclink] );
Avatar of shuboarder

ASKER

Maddy, thanks for the script, but I'd really like to keep it Formula, that way if I ever need to change it I'll understand it.

Sjef, the IncludeDocLink works when the form is submitted from a button, it's when the approver, approves using the second button that the mail does not send.

I tried putting all the field names in quotes, but when I clicked the approve button it said that the name could not be found in the address book.
Avatar of hong7cong
hong7cong

I tried to create the form with similar field names and I got the mail sent though still got an error message saying that "No name found to send  mail to" .

Note that I gave the sendto var static address of mine with full Notes Name. So, I think your problem is that in at "requestee_lookup". It might shorten the full email address to be the shortname so the email was not delivered.
It's only the fieldnames that should be in quotes:
    @MailSend( sendTo ; copyTo ; blindCopyTo ; subject ; remark ; bodyFields ; [ flags ] )

bodyFields
Text. The names of one or more fields from the current document that you want included in the mail memo. The fields must be of type text or text list, and are appended to the memo in the order in which you list them. (You can store @Text of a numeric field in a variable and use the variable name as a field name.) Enclose each field name in quotation marks. If you want to list multiple fields, use the list format: "description":"issues":"resolution."  If you store the name of the field in a variable, omit the quotation marks here.

All the rest of the code is similar to the code in the other button? Might there be some error in the Body-text, which could be solved with an @IsError()?
I've checked, and the requestee_lookup field is correct.
I have also tried replacing the SendTo with "user@domain.com" and the mail still does not send

I guess this means there is an error somewhere in the code?
I've also tried removing the bodytext and it still doesn't work!
Is there already a field named Body on the form? Could you then try to send a very simple mail, just with the bare necessities? By the way, if you use @MailSend, most parameters don't have to be fields. This should also work (skipping the status change and save part):

req_sendto:= @Text(requestee_lookup);
req_subject:= "Your request has been approved";
req_body:= " Just a test ";
@MailSend( req_sendto; ""; ""; req_subject; req_body; ""; [IncludeDoclink] )

If you don't have fields to include, use the remarks-parameter.






Hi Sjef,

there is a field named Body at the bottom of the form.
I have tried your simple code, now something strange...

If I click the button I will get an email from myself.
If my manager presses the button, it will not send the email to me.

Any more ideas?
Now breaks my clog... (poor duthicism)

In his ECL, he accepted your signature to run code? I suppose he did.

Did your manager send a mail, I mean, can you find both mails (yours and his( in the log database?
What's with my keyboard... The word is Dutchism of course :)
Yes, signature accepted....

Another piece of information....

If the accept button is pressed when the document is "new" then the email gets sent.
If the button is pressed after the first button, then no email is sent.
Do you have Author-fields in the document? Has the manager update-access on the document? Those are problems that you don't have in LotusScript, assuming there is no need to modify the opened document. Madheeswar's code could be a good start, but it needs a lot of modifications. IMHO it is far better to use LotusScript, you're making it yourself (and me) very difficult.
No author fields....
The button is only made visible to the manager through hide when formula.
Why would this formula only work one way!! it's soooooo annoying!
I wouldn't know, I'd need context and hands-on experience...

Suggestions: spice up your Formula-code with some prompts:
    @Prompt([Ok]; "Value of xxx set to " + @Text(xxx); "Debugging");

Make sure every statement is surrounded by @Prompts (in a reasonable way). That way, you can see progress and content. Try for yourself and for the manager.
Ok,

I've added @prompts,

All seemed ok, and no mail sent with temporary variables.

Reverted back to populating fields....

and it appears that when clicking the approve button, the fields are not updated before the mail is sent, but after the document has been saved.

No mail sent.

Tried using @setfield in place of FIELD

No mail sent.
What's the latest code?? Can you post it here?
Still having problems, I've tried all sorts, here is the latest....
(using Sjef's suggestion of temporary variables)

req_sendto:= @Text(requestee_lookup);
req_subject:= "Your request has been approved";
req_body:= "Your request has been approved" + @NewLine + @NewLine +
"Please click the link below to view the details"
+ @NewLine + @NewLine;
@If(!@IsValid;@Return("");"");
FIELD request_status:= "Approved";
@Command([ViewRefreshFields]);
@MailSend(req_sendto; ""; ""; req_subject; req_body; ""; [IncludeDoclink]);
@Command([FileSave]);
@Command([CloseWindow])
Lots of questions:
- there are no @Prompt-statements in your code?
- then how do you know @IsValid yields @True?
- did you try without the doclink?

And if you swap the lines with FileSave and @MailSend?
1. tried with @prompts... no luck, so removed them.
2. Using this with an input validation... which seems to work
3. Tried without the doclink - no difference.

I have tried lots of different versions of the code, and putting the save before the mailsend has also made no difference.
I've never had so much trouble with sending a mail!

Thanks for your reply again though.
This can't be true! Not logical, not explainable at all. Can you make some simple test database, with the code and sufficient other design elements to make it work, that behaves exactly the same? And can you send me a zipped copy of that database, so I can test it here? Please?

And what's your Notes/Domino version?
Sjef,

as much as I would like to do this, it will be difficult, as there are other databases involved...
I've tried copying various elements in to one database and it just throws up errors all over the place.
I can send you a copy of the form in question in a test database if that helps?

Notes/Domino is 6.5
I think just the one form will do, I'll try to isolate the problem and create the views that are required (if any). What amazes me completely is that you can send a (test)mail to yourself in a hard-coded button, but the manager can't. What's so essential in this process that prevent the manager to do the same??

Dobby bad elf...
Hi Sjef,

I've put the form in a new database and sent you it in an email to the address in your profile.
It is a bit messy, but it's a work in progress...

Upped the points on this one too

Cheers!
ASKER CERTIFIED SOLUTION
Avatar of Sjef Bosman
Sjef Bosman
Flag of France image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for looking at this Sjef,

are you saying that the only thing I need to do is make one of the views "Default when database is first opened"?
Well, what do you know....

I set a default view in the database and the mails are now flowing...
I want to SCREAM and kiss you at the same time!
It's sad, isn't it? I love these undocumented features ;-))
I still can't believe it....

I have to keep testing it to make sure it's true!
http://www-1.ibm.com/support/docview.wss?rs=0&uid=swg21090662
http:Q_20697221.html "Doclink database cannot be located"

When you know the solution it's easy to find other references...
Great , It worked, the issue was default view was declared.

Thanks a lot for you help sjef_bosman

Regards
Prashant
Got you some extra points there Sjef!

Thanks for your help as always!