Would anyone have an example of how to create an SMTP message with an attachment for MailPro 3.0.4 ?
I can send a mail with no problem, just can’t figure out how to add an attachment to it.
Cannot find an example anywhere, or indeed work it out from what’s visible in autocomplete.
Thanks
Working now, here it is for anyone else that needs it:
var connected = false;
var sent = false;
var dateNow = new Date();
var fromAddress = 'from_me@myemail.com';
var toAddress = 't_you@youremail.com'
var attach = plugins.MailPro.Attachment('myfile.pdf');
var SMTP = plugins.MailPro.SMTPAccount();
SMTP.connectionTimeout = 5000; // 5 secs
SMTP.host = 'smtp.my_mailprovider.com';
SMTP.userName = 'username';
SMTP.password = 'password';
SMTP.port = 587;
SMTP.requiresAuthentication = true;
SMTP.useTLS = true;
try
{
connected = SMTP.connect();
var subjectText = 'Your requested document.';
var bodyText = '\n\nSent:' + dateNow.toLocaleDateString() + ' ' + dateNow.toLocaleTimeString();
if (connected)
{
{/** @type {MailMessage} */}
var newMessage = SMTP.createMessage(toAddress, fromAddress, subjectText, bodyText);
newMessage.addAttachment(attach); // -- Will throw Servoy developer warning but unavoidable .
sent = SMTP.sendMessage(newMessage);
SMTP.disconnect();
}
}
catch (e )
{
plugins.Log.error('SMTP error:' + SMTP.getLastErrorMessage());
}