send (NotesDocument - JavaScript)

Mails a document.

Defined in

NotesDocument

Syntax

send() : void

send(recipient:string) : void

send(recipients:java.util.Vector) : void

send(attachform:boolean) : void

send(attachform:boolean, recipient:string) : void

send(attachform:boolean, recipients:java.util.Vector) : void

Parameter Description
recipient The recipient of the document. See below.
recipients Vector of String elements. The recipients of the document. See below.
attachform If true, the form is stored and sent with the document. If false (default), it isn't. Do not attach a form that uses computed subforms.

Usage

The following rules apply to specification of the recipient or recipients:
  • Ignored if the document contains a SendTo item, in which case the document is mailed to recipients listed in SendTo.
  • Required if the document does not contain a SendTo item.
  • May include people, groups, or mail-in databases.

If you have only Reader access to a database, you can run an agent that creates and sends a document, but the agent will not work if you attach a file to that document.

Two kinds of items can affect the mailing of the document when you use send:
  • If the document contains additional recipient items, such as CopyTo or BlindCopyTo, the documents are mailed to those recipients.
  • If the document contains items to control the routing of mail, such as DeliveryPriority, DeliveryReport, or ReturnReceipt, they are used when sending the document.

The IsSaveMessageOnSend property controls whether the sent document is saved in the database. If IsSaveMessageOnSend property is true and you attach the form to the document, the form is saved with the document.

Sending the form increases the size of the document, but ensures that the recipient can see all of the items on the document.

If a program runs on a workstation, the mailed document contains the current user's name in the From item. If a program runs as an agent on a server, the mailed document contains the server's name in the From item.

Examples

This button creates and mails a document collecting recipients, subject, and options from scoped variables on the current XPage.
try {

// requestScope.sendto is a list box allowing multiple entries - returns java.util.ArrayList
// stop processing if sendto is empty
if (requestScope.sendto.isEmpty()) {
	requestScope.status = "No sender(s) specified";
	return;
}
var sendto = new java.util.Vector(requestScope.sendto);
var memo:NotesDocument = database.createDocument();
memo.appendItemValue("Form", "Memo");
// requestScope.subject is an edit box - returns string
memo.appendItemValue("Subject", requestScope.subject);
// requestScope.body is rich text - returns com.ibm.xsp.http.MimeMultipart
// do not create mime entity if body is null
if (requestScope.body != null) {
	// stream html from body to mime entity
	session.setConvertMime(false);
	var stream = session.createStream();
	stream.writeText(requestScope.body.getHTML());
	var body = memo.createMIMEEntity("Body");
	body.setContentFromText(stream,"text/html;charset=UTF-8", 1725);
	stream.close();
	memo.closeMIMEEntities(true);
	session.setConvertMime(true);
}

// set mail options
var items = memo.getItems(); // hack: encrypted and signed memo fails without this
memo.setEncryptOnSend(sessionScope.encrypt); // sessionScope.encrypt set by button
memo.setSignOnSend(sessionScope.sign); // sessionScope.sign set by button
memo.setSaveMessageOnSend(sessionScope.sos); // sessionScope.sos set by button

// send memo and report status
memo.send(false, sendto); // same as memo.send(sendto);
requestScope.status = "Message sent\n";
requestScope.status += 
	"Memo is " + (memo.isSaveMessageOnSend() ? "saved\n" : "not saved\n");
requestScope.status += 
	"Memo is " + (memo.isEncryptOnSend() ? "encrypted\n" : "not encrypted\n");
requestScope.status += 
	"Memo is " + (memo.isSignOnSend() ? "signed\n" : "not signed");

} catch(e) {
	requestScope.status = e.toString();
}
Here is the XML for the entire XPage.
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">
	<xp:this.afterPageLoad><![CDATA[#{javascript:sessionScope.sos = false;
sessionScope.encrypt = false;
sessionScope.sign = false}]]></xp:this.afterPageLoad>
	<xp:listBox id="listBox1" multiple="true" value="#{requestScope.sendto}">
		<xp:selectItem itemLabel="Roberta Person/Acme"></xp:selectItem>
		<xp:selectItem itemLabel="John Smith/Acme"></xp:selectItem>
		<xp:selectItem itemLabel="Jane Brown/Acme"></xp:selectItem>
	</xp:listBox>
	<xp:br></xp:br>
	<xp:inputText id="inputText1" value="#{requestScope.subject}"></xp:inputText>
	<=subject
	<xp:button id="button1" value="send">
		<xp:eventHandler event="onclick" submit="true"
			refreshMode="complete">
			<xp:this.action><![CDATA[#{javascript:try {

// requestScope.sendto is a list box allowing multiple entries - returns java.util.ArrayList
// stop processing if sendto is empty
if (requestScope.sendto.isEmpty()) {
	requestScope.status = "No sender(s) specified";
	return;
}
var sendto = new java.util.Vector(requestScope.sendto);
var memo:NotesDocument = database.createDocument();
memo.appendItemValue("Form", "Memo");
// requestScope.subject is an edit box - returns string
memo.appendItemValue("Subject", requestScope.subject);
// requestScope.body is rich text - returns com.ibm.xsp.http.MimeMultipart
// do not create mime entity if body is null
if (requestScope.body != null) {
	// stream html from body to mime entity
	session.setConvertMime(false);
	var stream = session.createStream();
	stream.writeText(requestScope.body.getHTML());
	var body = memo.createMIMEEntity("Body");
	body.setContentFromText(stream,"text/html;charset=UTF-8", 1725);
	stream.close();
	memo.closeMIMEEntities(true);
	session.setConvertMime(true);
}

// set mail options
var items = memo.getItems(); // hack: encrypted and signed memo fails without this
memo.setEncryptOnSend(sessionScope.encrypt); // sessionScope.encrypt set by button
memo.setSignOnSend(sessionScope.sign); // sessionScope.sign set by button
memo.setSaveMessageOnSend(sessionScope.sos); // sessionScope.sos set by button

// send memo and report status
memo.send(false, sendto); // same as memo.send(sendto);
requestScope.status = "Message sent\n";
requestScope.status += 
	"Memo is " + (memo.isSaveMessageOnSend() ? "saved\n" : "not saved\n");
requestScope.status += 
	"Memo is " + (memo.isEncryptOnSend() ? "encrypted\n" : "not encrypted\n");
requestScope.status += 
	"Memo is " + (memo.isSignOnSend() ? "signed\n" : "not signed");

} catch(e) {
	requestScope.status = e.toString();
}}]]></xp:this.action>
		</xp:eventHandler></xp:button>

	<xp:br></xp:br>
	
	<xp:br></xp:br>
	<xp:button id="button2"><xp:this.value><![CDATA[#{javascript:if (sessionScope.sos) {
	return "Save on send"
} else {
	return "Do not save on send"
}}]]></xp:this.value>
		<xp:eventHandler event="onclick" submit="true"
			refreshMode="partial" refreshId="button2">
			<xp:this.action><![CDATA[#{javascript:if (sessionScope.sos) {
	sessionScope.sos = false;
} else {
	sessionScope.sos = true;
}}]]></xp:this.action>
		</xp:eventHandler></xp:button>
	<xp:button id="button3"><xp:this.value><![CDATA[#{javascript:if (sessionScope.encrypt) {
	return "Encrypt on send"
} else {
	return "Do not encrypt on send"
}}]]></xp:this.value>
		<xp:eventHandler event="onclick" submit="true"
			refreshMode="partial" refreshId="button3">
			<xp:this.action><![CDATA[#{javascript:if (sessionScope.encrypt) {
	sessionScope.encrypt = false;
} else {
	sessionScope.encrypt = true;
}}]]></xp:this.action>
		</xp:eventHandler></xp:button><xp:button id="button4"><xp:this.value><![CDATA[#{javascript:if (sessionScope.sign) {
	return "Sign on send"
} else {
	return "Do not sign on send"
}}]]></xp:this.value>
		<xp:eventHandler event="onclick" submit="true"
			refreshMode="partial" refreshId="button4">
			<xp:this.action><![CDATA[#{javascript:if (sessionScope.sign) {
	sessionScope.sign = false;
} else {
	sessionScope.sign = true;
}}]]></xp:this.action>
		</xp:eventHandler></xp:button><xp:br></xp:br>
	<xp:br></xp:br>
	
	<xp:br></xp:br>
	<xp:inputRichText id="inputRichText1" value="#{requestScope.body}"
		style="height:148.0px;width:456.0px">
	</xp:inputRichText>
	<xp:br></xp:br>
	<xp:br></xp:br>
	<xp:inputTextarea id="inputTextarea1" style="width:456.0px" value="#{requestScope.status}"></xp:inputTextarea><xp:br></xp:br>
	</xp:view>