setContentFromText (NotesMIMEEntity - JavaScript™)
Sets the content of a MIME entity from text.
Defined in
NotesMIMEEntitySyntax
setContentFromText(stream:NotesStream, contentType:string, encoding:int) : void | Parameter | Description |
|---|---|
stream |
The text input. This input replaces any existing content. If the stream is empty, any current content is removed. |
contentType |
Content type/subtype of the
input stream. This parameter generates a Content-Type header. |
encoding |
The MIME transfer encoding, which should reflect
the encoding of the input stream. This parameter generates a Content-Transfer-Encoding header.
See encodeContent.
|
Usage
If the NotesStream input is the result of NotesStream.WriteText, translation of the internal Unicode defaults toUS-ASCII.
To translate characters other than US-ASCII, append
a charset parameter such as charset=UTF-8 or charset=Unicode-1-1 to
the type/subtype.If Content-Type specifies text and
the charset parameter specifies a known Internet
encoding, and encoding is ENC_IDENTITY_8BIT or ENC_IDENTITY_BINARY,
content storage is with the specified character set. Otherwise, content
storage is attempted with UUS-ASCII.
This method sets the stream Position at end of stream.
Examples
This button mails a document in MIME format. Also see send.var stream:NotesStream = session.createStream();
session.setConvertMime(false); // do not convert mime to rich text
var doc:NotesDocument = database.createDocument();
doc.appendItemValue("Form", "Memo");
var body:NotesMIMEEntity = doc.createMIMEEntity();
var header:NotesMIMEHeader = body.createHeader("Subject");
if (!header.setHeaderVal("MIME message")) {
requestScope.status = "Cannot set header val for Subject";
return;
}
header = body.createHeader("To");
if (!header.setHeaderVal(requestScope.query)) { // address of mail recipient
requestScope.status = "Cannot set header val for To";
return;
}
stream.writeText("This is the text of the message.");
body.setContentFromText(stream, "text/plain;charset=UTF-8", NotesMIMEEntity.ENC_NONE);
doc.send();
session.setConvertMime(true); // restore coversionThe
following button creates a document from content on the current XPage.
var doc:NotesDocument = database.createDocument();
doc.replaceItemValue("Form", "main");
doc.replaceItemValue("subject", requestScope.subject);
if (requestScope.body != null) {
//requestScope.body is bound to an inputRichText control
var body:com.ibm.xsp.http.MimeMultipart = requestScope.body;
var stream:NotesStream = session.createStream();
stream.writeText(body.getHTML());
var entity:NotesMIMEEntity = doc.createMIMEEntity("body");
entity.setContentFromText(stream,"text/html;charset=UTF-8", 1725);
stream.close();
} else {
requestScope.status = "no content";
}
doc.save();