Overview
The MailMessage
object acts as a container for email messages, providing methods to retrieve various components of an email. These include attachments, sender and recipient addresses, email headers, plain text or HTML content, and metadata like the sent date and subject.
Functionality
MailMessage
provides a range of methods to interact with email components. First, getAttachments()
returns an array of attachments in the email. Second, address-related methods such as getFromAddresses()
, getRecipientAddresses()
, getCCAddresses()
, and getReplyAddresses()
retrieve sender, recipient, CC, and reply-to addresses respectively. Third, message content is accessible via getPlainMsg()
for plain text and getHtmlMsg()
for HTML content. Finally, metadata such as the subject, sent date, and headers can be fetched using getSubject()
, getSentDate()
, and getHeaders()
.
These methods facilitate comprehensive handling of email messages, including parsing, processing, and saving data like attachments and content. References to Date and String types in the methods ensure consistent data handling.
Methods Summarized
Returns an array of Attachment instances corresponding to the attachments of this message.
Returns a String with all addresses present in the CC field of this message.
Returns a String with all addresses present in the From field of this message.
Returns a String with all headers of this message.
Returns a String with the HTML content of this message.
Returns a String with the plain content of this message.
Returns a String with all addresses in the To field of this message.
Returns a String with all addresses in the Reply-To field of this message.
Returns a Date instance corresponding to the moment when this message was sent.
Returns a String with the subject of this message.
Methods Detailed
getAttachments()
Returns an array of Attachment instances corresponding to the attachments of this message.
Returns: Array
Sample
Copy var msgs = plugins . mail .receiveMail (username , password , true , 0 , null , properties);
if (msgs != null )
{
for ( var i = 0 ; i < msgs . length ; i ++ )
{
var msg = msgs[i];
var str = '' ;
str += 'From: ' + msg .getFromAddresses () + '\n' ;
str += 'To: ' + msg .getRecipientAddresses () + '\n' ;
str += 'CC: ' + msg .getCCAddresses () + '\n' ;
str += 'Reply to: ' + msg .getReplyAddresses () + '\n' ;
str += 'Received on: ' + msg .getReceivedDate () + '\n' ;
str += 'Sent on: ' + msg .getSentDate () + '\n\n' ;
str += 'Subject: ' + msg .getSubject () + '\n\n' ;
str += 'Plain message: ' + msg .getPlainMsg () + '\n\n' ;
str += 'HTML message: ' + msg .getHtmlMsg () + '\n\n' ;
str += 'Headers: ' + msg .getHeaders () + '\n\n' ;
var attachments = msg .getAttachments ();
if (attachments != null ) {
str += 'Number of attachments: ' + attachments . length + '\n\n' ;
for ( var j = 0 ; j < attachments . length ; j ++ )
{
var attachment = attachments[j];
str += 'Attachment ' + j + '\n' ;
str += ' Name: ' + attachment .getName () + '\n' ;
str += ' Size: ' + attachment .getData (). length + '\n\n' ;
}
}
plugins . file .writeTXTFile ( 'msg' + i + '.txt' , str);
application .output ( 'Message ' + i + ' retrieved.' );
}
}
else
{
application .output ( "Failed to retrieve messages." );
}
getCCAddresses()
Returns a String with all addresses present in the CC field of this message.
Returns: String
Sample
Copy var msgs = plugins . mail .receiveMail (username , password , true , 0 , null , properties);
if (msgs != null )
{
for ( var i = 0 ; i < msgs . length ; i ++ )
{
var msg = msgs[i];
var str = '' ;
str += 'From: ' + msg .getFromAddresses () + '\n' ;
str += 'To: ' + msg .getRecipientAddresses () + '\n' ;
str += 'CC: ' + msg .getCCAddresses () + '\n' ;
str += 'Reply to: ' + msg .getReplyAddresses () + '\n' ;
str += 'Received on: ' + msg .getReceivedDate () + '\n' ;
str += 'Sent on: ' + msg .getSentDate () + '\n\n' ;
str += 'Subject: ' + msg .getSubject () + '\n\n' ;
str += 'Plain message: ' + msg .getPlainMsg () + '\n\n' ;
str += 'HTML message: ' + msg .getHtmlMsg () + '\n\n' ;
str += 'Headers: ' + msg .getHeaders () + '\n\n' ;
var attachments = msg .getAttachments ();
if (attachments != null ) {
str += 'Number of attachments: ' + attachments . length + '\n\n' ;
for ( var j = 0 ; j < attachments . length ; j ++ )
{
var attachment = attachments[j];
str += 'Attachment ' + j + '\n' ;
str += ' Name: ' + attachment .getName () + '\n' ;
str += ' Size: ' + attachment .getData (). length + '\n\n' ;
}
}
plugins . file .writeTXTFile ( 'msg' + i + '.txt' , str);
application .output ( 'Message ' + i + ' retrieved.' );
}
}
else
{
application .output ( "Failed to retrieve messages." );
}
getFromAddresses()
Returns a String with all addresses present in the From field of this message.
Returns: String
Sample
Copy var msgs = plugins . mail .receiveMail (username , password , true , 0 , null , properties);
if (msgs != null )
{
for ( var i = 0 ; i < msgs . length ; i ++ )
{
var msg = msgs[i];
var str = '' ;
str += 'From: ' + msg .getFromAddresses () + '\n' ;
str += 'To: ' + msg .getRecipientAddresses () + '\n' ;
str += 'CC: ' + msg .getCCAddresses () + '\n' ;
str += 'Reply to: ' + msg .getReplyAddresses () + '\n' ;
str += 'Received on: ' + msg .getReceivedDate () + '\n' ;
str += 'Sent on: ' + msg .getSentDate () + '\n\n' ;
str += 'Subject: ' + msg .getSubject () + '\n\n' ;
str += 'Plain message: ' + msg .getPlainMsg () + '\n\n' ;
str += 'HTML message: ' + msg .getHtmlMsg () + '\n\n' ;
str += 'Headers: ' + msg .getHeaders () + '\n\n' ;
var attachments = msg .getAttachments ();
if (attachments != null ) {
str += 'Number of attachments: ' + attachments . length + '\n\n' ;
for ( var j = 0 ; j < attachments . length ; j ++ )
{
var attachment = attachments[j];
str += 'Attachment ' + j + '\n' ;
str += ' Name: ' + attachment .getName () + '\n' ;
str += ' Size: ' + attachment .getData (). length + '\n\n' ;
}
}
plugins . file .writeTXTFile ( 'msg' + i + '.txt' , str);
application .output ( 'Message ' + i + ' retrieved.' );
}
}
else
{
application .output ( "Failed to retrieve messages." );
}
Returns a String with all headers of this message.
Returns: String
Sample
Copy var msgs = plugins . mail .receiveMail (username , password , true , 0 , null , properties);
if (msgs != null )
{
for ( var i = 0 ; i < msgs . length ; i ++ )
{
var msg = msgs[i];
var str = '' ;
str += 'From: ' + msg .getFromAddresses () + '\n' ;
str += 'To: ' + msg .getRecipientAddresses () + '\n' ;
str += 'CC: ' + msg .getCCAddresses () + '\n' ;
str += 'Reply to: ' + msg .getReplyAddresses () + '\n' ;
str += 'Received on: ' + msg .getReceivedDate () + '\n' ;
str += 'Sent on: ' + msg .getSentDate () + '\n\n' ;
str += 'Subject: ' + msg .getSubject () + '\n\n' ;
str += 'Plain message: ' + msg .getPlainMsg () + '\n\n' ;
str += 'HTML message: ' + msg .getHtmlMsg () + '\n\n' ;
str += 'Headers: ' + msg .getHeaders () + '\n\n' ;
var attachments = msg .getAttachments ();
if (attachments != null ) {
str += 'Number of attachments: ' + attachments . length + '\n\n' ;
for ( var j = 0 ; j < attachments . length ; j ++ )
{
var attachment = attachments[j];
str += 'Attachment ' + j + '\n' ;
str += ' Name: ' + attachment .getName () + '\n' ;
str += ' Size: ' + attachment .getData (). length + '\n\n' ;
}
}
plugins . file .writeTXTFile ( 'msg' + i + '.txt' , str);
application .output ( 'Message ' + i + ' retrieved.' );
}
}
else
{
application .output ( "Failed to retrieve messages." );
}
getHtmlMsg()
Returns a String with the HTML content of this message.
Returns: String
Sample
Copy var msgs = plugins . mail .receiveMail (username , password , true , 0 , null , properties);
if (msgs != null )
{
for ( var i = 0 ; i < msgs . length ; i ++ )
{
var msg = msgs[i];
var str = '' ;
str += 'From: ' + msg .getFromAddresses () + '\n' ;
str += 'To: ' + msg .getRecipientAddresses () + '\n' ;
str += 'CC: ' + msg .getCCAddresses () + '\n' ;
str += 'Reply to: ' + msg .getReplyAddresses () + '\n' ;
str += 'Received on: ' + msg .getReceivedDate () + '\n' ;
str += 'Sent on: ' + msg .getSentDate () + '\n\n' ;
str += 'Subject: ' + msg .getSubject () + '\n\n' ;
str += 'Plain message: ' + msg .getPlainMsg () + '\n\n' ;
str += 'HTML message: ' + msg .getHtmlMsg () + '\n\n' ;
str += 'Headers: ' + msg .getHeaders () + '\n\n' ;
var attachments = msg .getAttachments ();
if (attachments != null ) {
str += 'Number of attachments: ' + attachments . length + '\n\n' ;
for ( var j = 0 ; j < attachments . length ; j ++ )
{
var attachment = attachments[j];
str += 'Attachment ' + j + '\n' ;
str += ' Name: ' + attachment .getName () + '\n' ;
str += ' Size: ' + attachment .getData (). length + '\n\n' ;
}
}
plugins . file .writeTXTFile ( 'msg' + i + '.txt' , str);
application .output ( 'Message ' + i + ' retrieved.' );
}
}
else
{
application .output ( "Failed to retrieve messages." );
}
getPlainMsg()
Returns a String with the plain content of this message.
Returns: String
Sample
Copy var msgs = plugins . mail .receiveMail (username , password , true , 0 , null , properties);
if (msgs != null )
{
for ( var i = 0 ; i < msgs . length ; i ++ )
{
var msg = msgs[i];
var str = '' ;
str += 'From: ' + msg .getFromAddresses () + '\n' ;
str += 'To: ' + msg .getRecipientAddresses () + '\n' ;
str += 'CC: ' + msg .getCCAddresses () + '\n' ;
str += 'Reply to: ' + msg .getReplyAddresses () + '\n' ;
str += 'Received on: ' + msg .getReceivedDate () + '\n' ;
str += 'Sent on: ' + msg .getSentDate () + '\n\n' ;
str += 'Subject: ' + msg .getSubject () + '\n\n' ;
str += 'Plain message: ' + msg .getPlainMsg () + '\n\n' ;
str += 'HTML message: ' + msg .getHtmlMsg () + '\n\n' ;
str += 'Headers: ' + msg .getHeaders () + '\n\n' ;
var attachments = msg .getAttachments ();
if (attachments != null ) {
str += 'Number of attachments: ' + attachments . length + '\n\n' ;
for ( var j = 0 ; j < attachments . length ; j ++ )
{
var attachment = attachments[j];
str += 'Attachment ' + j + '\n' ;
str += ' Name: ' + attachment .getName () + '\n' ;
str += ' Size: ' + attachment .getData (). length + '\n\n' ;
}
}
plugins . file .writeTXTFile ( 'msg' + i + '.txt' , str);
application .output ( 'Message ' + i + ' retrieved.' );
}
}
else
{
application .output ( "Failed to retrieve messages." );
}
getRecipientAddresses()
Returns a String with all addresses in the To field of this message.
Returns: String
Sample
Copy var msgs = plugins . mail .receiveMail (username , password , true , 0 , null , properties);
if (msgs != null )
{
for ( var i = 0 ; i < msgs . length ; i ++ )
{
var msg = msgs[i];
var str = '' ;
str += 'From: ' + msg .getFromAddresses () + '\n' ;
str += 'To: ' + msg .getRecipientAddresses () + '\n' ;
str += 'CC: ' + msg .getCCAddresses () + '\n' ;
str += 'Reply to: ' + msg .getReplyAddresses () + '\n' ;
str += 'Received on: ' + msg .getReceivedDate () + '\n' ;
str += 'Sent on: ' + msg .getSentDate () + '\n\n' ;
str += 'Subject: ' + msg .getSubject () + '\n\n' ;
str += 'Plain message: ' + msg .getPlainMsg () + '\n\n' ;
str += 'HTML message: ' + msg .getHtmlMsg () + '\n\n' ;
str += 'Headers: ' + msg .getHeaders () + '\n\n' ;
var attachments = msg .getAttachments ();
if (attachments != null ) {
str += 'Number of attachments: ' + attachments . length + '\n\n' ;
for ( var j = 0 ; j < attachments . length ; j ++ )
{
var attachment = attachments[j];
str += 'Attachment ' + j + '\n' ;
str += ' Name: ' + attachment .getName () + '\n' ;
str += ' Size: ' + attachment .getData (). length + '\n\n' ;
}
}
plugins . file .writeTXTFile ( 'msg' + i + '.txt' , str);
application .output ( 'Message ' + i + ' retrieved.' );
}
}
else
{
application .output ( "Failed to retrieve messages." );
}
getReplyAddresses()
Returns a String with all addresses in the Reply-To field of this message.
Returns: String
Sample
Copy var msgs = plugins . mail .receiveMail (username , password , true , 0 , null , properties);
if (msgs != null )
{
for ( var i = 0 ; i < msgs . length ; i ++ )
{
var msg = msgs[i];
var str = '' ;
str += 'From: ' + msg .getFromAddresses () + '\n' ;
str += 'To: ' + msg .getRecipientAddresses () + '\n' ;
str += 'CC: ' + msg .getCCAddresses () + '\n' ;
str += 'Reply to: ' + msg .getReplyAddresses () + '\n' ;
str += 'Received on: ' + msg .getReceivedDate () + '\n' ;
str += 'Sent on: ' + msg .getSentDate () + '\n\n' ;
str += 'Subject: ' + msg .getSubject () + '\n\n' ;
str += 'Plain message: ' + msg .getPlainMsg () + '\n\n' ;
str += 'HTML message: ' + msg .getHtmlMsg () + '\n\n' ;
str += 'Headers: ' + msg .getHeaders () + '\n\n' ;
var attachments = msg .getAttachments ();
if (attachments != null ) {
str += 'Number of attachments: ' + attachments . length + '\n\n' ;
for ( var j = 0 ; j < attachments . length ; j ++ )
{
var attachment = attachments[j];
str += 'Attachment ' + j + '\n' ;
str += ' Name: ' + attachment .getName () + '\n' ;
str += ' Size: ' + attachment .getData (). length + '\n\n' ;
}
}
plugins . file .writeTXTFile ( 'msg' + i + '.txt' , str);
application .output ( 'Message ' + i + ' retrieved.' );
}
}
else
{
application .output ( "Failed to retrieve messages." );
}
getSentDate()
Returns a Date instance corresponding to the moment when this message was sent.
Returns: Date
Sample
Copy var msgs = plugins . mail .receiveMail (username , password , true , 0 , null , properties);
if (msgs != null )
{
for ( var i = 0 ; i < msgs . length ; i ++ )
{
var msg = msgs[i];
var str = '' ;
str += 'From: ' + msg .getFromAddresses () + '\n' ;
str += 'To: ' + msg .getRecipientAddresses () + '\n' ;
str += 'CC: ' + msg .getCCAddresses () + '\n' ;
str += 'Reply to: ' + msg .getReplyAddresses () + '\n' ;
str += 'Received on: ' + msg .getReceivedDate () + '\n' ;
str += 'Sent on: ' + msg .getSentDate () + '\n\n' ;
str += 'Subject: ' + msg .getSubject () + '\n\n' ;
str += 'Plain message: ' + msg .getPlainMsg () + '\n\n' ;
str += 'HTML message: ' + msg .getHtmlMsg () + '\n\n' ;
str += 'Headers: ' + msg .getHeaders () + '\n\n' ;
var attachments = msg .getAttachments ();
if (attachments != null ) {
str += 'Number of attachments: ' + attachments . length + '\n\n' ;
for ( var j = 0 ; j < attachments . length ; j ++ )
{
var attachment = attachments[j];
str += 'Attachment ' + j + '\n' ;
str += ' Name: ' + attachment .getName () + '\n' ;
str += ' Size: ' + attachment .getData (). length + '\n\n' ;
}
}
plugins . file .writeTXTFile ( 'msg' + i + '.txt' , str);
application .output ( 'Message ' + i + ' retrieved.' );
}
}
else
{
application .output ( "Failed to retrieve messages." );
}
getSubject()
Returns a String with the subject of this message.
Returns: String
Sample
Copy var msgs = plugins . mail .receiveMail (username , password , true , 0 , null , properties);
if (msgs != null )
{
for ( var i = 0 ; i < msgs . length ; i ++ )
{
var msg = msgs[i];
var str = '' ;
str += 'From: ' + msg .getFromAddresses () + '\n' ;
str += 'To: ' + msg .getRecipientAddresses () + '\n' ;
str += 'CC: ' + msg .getCCAddresses () + '\n' ;
str += 'Reply to: ' + msg .getReplyAddresses () + '\n' ;
str += 'Received on: ' + msg .getReceivedDate () + '\n' ;
str += 'Sent on: ' + msg .getSentDate () + '\n\n' ;
str += 'Subject: ' + msg .getSubject () + '\n\n' ;
str += 'Plain message: ' + msg .getPlainMsg () + '\n\n' ;
str += 'HTML message: ' + msg .getHtmlMsg () + '\n\n' ;
str += 'Headers: ' + msg .getHeaders () + '\n\n' ;
var attachments = msg .getAttachments ();
if (attachments != null ) {
str += 'Number of attachments: ' + attachments . length + '\n\n' ;
for ( var j = 0 ; j < attachments . length ; j ++ )
{
var attachment = attachments[j];
str += 'Attachment ' + j + '\n' ;
str += ' Name: ' + attachment .getName () + '\n' ;
str += ' Size: ' + attachment .getData (). length + '\n\n' ;
}
}
plugins . file .writeTXTFile ( 'msg' + i + '.txt' , str);
application .output ( 'Message ' + i + ' retrieved.' );
}
}
else
{
application .output ( "Failed to retrieve messages." );
}