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.");
} |