MailPro attachments.

Questions and answers on developing, deploying and using plugins and JavaBeans

MailPro attachments.

Postby alan.bourke » Mon Oct 20, 2014 12:47 pm

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
alan.bourke
 
Posts: 30
Joined: Thu Sep 05, 2013 2:08 pm

Re: MailPro attachments.

Postby alan.bourke » Mon Oct 20, 2014 3:27 pm

Working now, here it is for anyone else that needs it:

Code: Select all

   
   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());
   }

alan.bourke
 
Posts: 30
Joined: Thu Sep 05, 2013 2:08 pm


Return to Plugins and Beans

Who is online

Users browsing this forum: No registered users and 11 guests