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
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:
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.
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.
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
it should be a method in the MailMessage object you have when you create a new message…
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…
maybe it’s a property? message.embedAllImages = true?
I tried to give that property.
It give me this error.
Java method “embedAllImages” cannot be assigned to.
I see this [attachment=0]mail_message.png[/attachment]
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
see my Screenshot. embedAllImages is a method of a MailMessage object. So in your case
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:
var vSmtp = plugins.MailPro.SMTPAccount();
var message = vSmtp.createMessage(this.sendTo, fromAdress, this.mailSubject, this.mailText);
message.embeddAllImages(true)
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.
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
attachment.embedded = true
Please note that not all mail clients handle embedded images correctly and while they usually embed, they still show attachments.
Yes it is embedded.
These 2 “files” are shown on one mail.
------=_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
------=_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
So two questions here:
- why do you have the same file attached twice?
- why isn’t the disposition set to INLINE?
Can you post the relevant code you use to get to this kind of message?
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
That code looks strange for a number of reasons:
- Why are you using these associative method calls? Why not just do
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.
-
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?
-
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:
var attachmentToAdd = plugins.MailPro.Attachment(headerLogo[0], headerLogo[1]);
attachmentToAdd.embedded = true;
message.addAttachment(attachmentToAdd);
Thanks Patrick.
I got it working ![Smile :)]()
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;
}
}
}