MailPro + Inline images for HTML

Questions and answers on designing your Servoy solutions, database modelling and other 'how do I do this' that don't fit in any of the other categories

Re: MailPro + Inline images for HTML

Postby patrick » Thu Jul 28, 2016 2:00 pm

So two questions here:

1. why do you have the same file attached twice?
2. why isn't the disposition set to INLINE?

Can you post the relevant code you use to get to this kind of message?
Patrick Ruhsert
Servoy DACH
patrick
 
Posts: 3703
Joined: Wed Jun 11, 2003 10:33 am
Location: Munich, Germany

Re: MailPro + Inline images for HTML

Postby jeffrey.vandenhondel » Thu Jul 28, 2016 2:09 pm

Code: Select all
         for (var a = 0; a < this.headerLogo.length; a++) {
            var headerLogo = this.headerLogo[a];
            if (headerLogo) {
               message['addAttachment'](plugins.MailPro.Attachment(headerLogo[0], headerLogo[1]));
               message['embedAllImages'](true);
            }
         }


Content from my headerLogo:

[0] Filename
[1] Data
jeffrey.vandenhondel
 
Posts: 36
Joined: Thu Jul 28, 2016 9:05 am

Re: MailPro + Inline images for HTML

Postby patrick » Thu Jul 28, 2016 2:24 pm

That code looks strange for a number of reasons:

1. Why are you using these associative method calls? Why not just do

Code: Select all
message.addAttachment(...)


I think the MailPro plugin gives all kinds of warnings due to the fact that it is still compatible with a version of Servoy from 2005 or so. There will be an update soon. But I think if you type message as @type {plugins.MailPro.MailMessage} many of these warnings should be gone... Anyway, I would say coding this way is worse than getting warnings.

2. you seem to have an array with two entries, filename and data (why you have it this way I don't fully get). Then you iterate of the array and add an attachment with name and data in each iteration. That means you add the same attachment twice. But maybe I am just confused with the same naming of the private and public variable headerLogo? What is in this.headerLogo? One logo? Two logos?

3. You didn't pay attention to my suggestion to set the attachment's embedded property.

So try this and make sure you only add one logo:

Code: Select all
var attachmentToAdd = plugins.MailPro.Attachment(headerLogo[0], headerLogo[1]);
attachmentToAdd.embedded = true;
message.addAttachment(attachmentToAdd);
Patrick Ruhsert
Servoy DACH
patrick
 
Posts: 3703
Joined: Wed Jun 11, 2003 10:33 am
Location: Munich, Germany

Re: MailPro + Inline images for HTML

Postby jeffrey.vandenhondel » Mon Aug 08, 2016 1:37 pm

Thanks Patrick.
I got it working :)

Code: Select all
         if (this.images) {
            message['embedAllImages'](true);
            for (var a = 0; a < this.images.length; a++) {
               var image = this.images[a];
               if (image) {
                  message['addAttachment'](plugins.MailPro.Attachment(image[0], image[1]));
               }
            }

            var mailAttachemts = message.getAttachments();
            for (var iAttachment = 0; iAttachment < mailAttachemts.length; iAttachment++) {
               var currentAttachment = mailAttachemts[iAttachment];
               if (currentAttachment.getMimeType().indexOf('image') >-1) {
                  currentAttachment['embedded'] = true;
               }
            }
         }
jeffrey.vandenhondel
 
Posts: 36
Joined: Thu Jul 28, 2016 9:05 am

Previous

Return to Programming with Servoy

Who is online

Users browsing this forum: Bing [Bot] and 16 guests

cron