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

MailPro + Inline images for HTML

Postby jeffrey.vandenhondel » Thu Jul 28, 2016 9:10 am

Hi,

I have create a newsletter with HTML in servoy and sending this out with the MailPro plugin.
Now i want to send a company logo with it tried to use Base64 but most of the popular mail clients block these kind of images.

After some research i came across Inline images with the use of Content ID's now the problems is that there is no to little documentation from the MailPro plugin so i can't get this to work can someone help me with this problem.

Kind regards,
Jeffrey
jeffrey.vandenhondel
 
Posts: 36
Joined: Thu Jul 28, 2016 9:05 am

Re: MailPro + Inline images for HTML

Postby patrick » Thu Jul 28, 2016 9:15 am

I think MailMessage.embedAllImages(true) should help. In your html you set the src to your image's name (like src="logo.png"), then you attach the logo and give the attachment the name "logo.png". Then MailPro should try to find the image sources in html and properly exchange the src attribute with the content-id of the corresponding attachment.
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 9:20 am

patrick wrote:I think MailMessage.embedAllImages(true) should help. In your html you set the src to your image's name (like src="logo.png"), then you attach the logo and give the attachment the name "logo.png". Then MailPro should try to find the image sources in html and properly exchange the src attribute with the content-id of the corresponding attachment.


Thank you for the answer, is it possible to use Base64 because we save this in our database tables.
jeffrey.vandenhondel
 
Posts: 36
Joined: Thu Jul 28, 2016 9:05 am

Re: MailPro + Inline images for HTML

Postby patrick » Thu Jul 28, 2016 9:24 am

No, I don't think so. Creating attachments expects a byte[] or a file reference. Why do you store base64 encoded data? That's storing more than needed and always leads to troubles like now.
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 10:56 am

Hi Patrick,

Thanks for your reply,

If i get it right i should create a attachment with the logo, then add the attachment and use embedAllImages(true) to get them embedded?
I tried to find the embedAllImages but can't find it.

Tia
jeffrey.vandenhondel
 
Posts: 36
Joined: Thu Jul 28, 2016 9:05 am

Re: MailPro + Inline images for HTML

Postby patrick » Thu Jul 28, 2016 10:59 am

it should be a method in the MailMessage object you have when you create a new 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 11:01 am

Hmm,

I use this:
var vSmtp = plugins.MailPro.SMTPAccount();
var message = vSmtp.createMessage(this.sendTo, fromAdress, this.mailSubject, this.mailText);

Then I should expect to find it in the message but it isn't there....
jeffrey.vandenhondel
 
Posts: 36
Joined: Thu Jul 28, 2016 9:05 am

Re: MailPro + Inline images for HTML

Postby patrick » Thu Jul 28, 2016 11:03 am

maybe it's a property? message.embedAllImages = true?
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 11:06 am

I tried to give that property.
It give me this error.
Java method "embedAllImages" cannot be assigned to.
jeffrey.vandenhondel
 
Posts: 36
Joined: Thu Jul 28, 2016 9:05 am

Re: MailPro + Inline images for HTML

Postby patrick » Thu Jul 28, 2016 11:12 am

I see this
mail_message.png
mail_message.png (16.61 KiB) Viewed 7334 times
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 11:20 am

Tried to use this:
plugins.MailPro.MailMessage.embedAllImages(true);

Getting the following error:
Exception Object: org.mozilla.javascript.EcmaError: TypeError: Cannot call method "embedAllImages" of undefined (C:\Servoy\Workspace_Branch\afl_core\emails.js#239)
MSG: TypeError: Cannot call method "embedAllImages" of undefined
jeffrey.vandenhondel
 
Posts: 36
Joined: Thu Jul 28, 2016 9:05 am

Re: MailPro + Inline images for HTML

Postby patrick » Thu Jul 28, 2016 11:23 am

see my Screenshot. embedAllImages is a method of a MailMessage object. So in your case

Code: Select all
var vSmtp = plugins.MailPro.SMTPAccount();
var message = vSmtp.createMessage(this.sendTo, fromAdress, this.mailSubject, this.mailText);


SMTPAccount.createMessage returns a MailMessage object and that should have that method. So you should do this:

Code: Select all
var vSmtp = plugins.MailPro.SMTPAccount();
var message = vSmtp.createMessage(this.sendTo, fromAdress, this.mailSubject, this.mailText);
message.embeddAllImages(true)
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 12:33 pm

Hello Patrick,

I got it working with the Cid but now i get a attachment with the logo.jpg how do i discard this attachment.
jeffrey.vandenhondel
 
Posts: 36
Joined: Thu Jul 28, 2016 9:05 am

Re: MailPro + Inline images for HTML

Postby patrick » Thu Jul 28, 2016 12:44 pm

So the logo is now properly embedded in your html, but you still see it as an attachment? Have a look at the source of the message and find the attachment. Does it have a content-disposition? Which one (it should be INLINE)?

I think the plugin sets the disposition to INLINE if the attachment has the embedded property set to true. So on your attachment object do

Code: Select all
attachment.embedded = true


Please note that not all mail clients handle embedded images correctly and while they usually embed, they still show attachments.
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 1:32 pm

Yes it is embedded.

These 2 "files" are shown on one mail.
Code: Select all
------=_Part_151_2026793222.1469705409887
Content-Type: image/jpeg; name=logo.jpg
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename=logo.jpg
Content-Id: <mailpro-921DE2AD-3D1C-4FFA-B19B-A3B90B768E08>

/9j/4AAQSkZJRgABAAEBLAEsAAD//gAfTEVBRCBUZWNobm9sb2dpZXMgSW5jLiBWMS4wMQD/2wCE
AAgFBgcGBQgHBgcJCAgJDBQNDAsLDBgREg4UHRkeHhwZHBsgJC4nICIrIhscKDYoKy8xMzQzHyY4
PDgyPC4yMzEBCAkJDAoMFw0NFzEhHCExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTEx
MTExMTExMTExMTExMTExMf/EAaIAAAEFAQEBAQEBAAAAAAAAAAABAgMEBQYHCAkKCwEAAwEBAQEB
AQEBAQAAAAAAAAECAwQFBgcICQoLEAACAQMDAgQDBQUEBAAAAX0BAgMABBEFEiExQQYTUWEHInEU
MoGRoQgjQrHBFVLR8CQzYnKCCQoWFxgZGiUmJygpKjQ1Njc4OTpDREVGR0hJSlNUVVZXWFlaY2Rl
ZmdoaWpzdHV2d3h5eoOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK
0tPU1dbX2Nna4eLj5OXm5+jp6vHy8/T19vf4+foRAAIBAgQEAwQHBQQEAAECdwABAgMRBAUhMQYS
QVEHYXETIjKBCBRCkaGxwQkjM1LwFWJy0QoWJDThJfEXGBkaJicoKSo1Njc4OTpDREVGR0hJSlNU
VVZXWFlaY2RlZmdoaWpzdHV2d3h5eoKDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5


Code: Select all
------=_Part_153_1651970251.1469705409887
Content-Type: image/jpeg; name=logo.jpg
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename=logo.jpg

/9j/4AAQSkZJRgABAAEBLAEsAAD//gAfTEVBRCBUZWNobm9sb2dpZXMgSW5jLiBWMS4wMQD/2wCE
AAgFBgcGBQgHBgcJCAgJDBQNDAsLDBgREg4UHRkeHhwZHBsgJC4nICIrIhscKDYoKy8xMzQzHyY4
PDgyPC4yMzEBCAkJDAoMFw0NFzEhHCExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTEx
MTExMTExMTExMTExMTExMf/EAaIAAAEFAQEBAQEBAAAAAAAAAAABAgMEBQYHCAkKCwEAAwEBAQEB
AQEBAQAAAAAAAAECAwQFBgcICQoLEAACAQMDAgQDBQUEBAAAAX0BAgMABBEFEiExQQYTUWEHInEU
MoGRoQgjQrHBFVLR8CQzYnKCCQoWFxgZGiUmJygpKjQ1Njc4OTpDREVGR0hJSlNUVVZXWFlaY2Rl
ZmdoaWpzdHV2d3h5eoOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK
0tPU1dbX2Nna4eLj5OXm5+jp6vHy8/T19vf4+foRAAIBAgQEAwQHBQQEAAECdwABAgMRBAUhMQYS
QVEHYXETIjKBCBRCkaGxwQkjM1LwFWJy0QoWJDThJfEXGBkaJicoKSo1Njc4OTpDREVGR0hJSlNU
VVZXWFlaY2RlZmdoaWpzdHV2d3h5eoKDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5
jeffrey.vandenhondel
 
Posts: 36
Joined: Thu Jul 28, 2016 9:05 am

Next

Return to Programming with Servoy

Who is online

Users browsing this forum: No registered users and 16 guests

cron