Sending html email: limitations?

I have a webapp on a Ubuntu server which converts PDF files to HTML, using pdf2htmlEX from a Shell.

You can look at samples here: PDF file and HTML file
The generated html opens fine in any browser I could test so far (latest versions of Safari on OSX and iOS, Firefox and the new browser on Windows 10)

But when I try to send the html file by email, then what is shown in Mail no longer looks ok:

To send the email I have been using examples from Xojo as well as MBS plugins code. Both ended up like in the screenshot above.

It looks like Email cannot display correctly the file produced by pdf2htmlEX, only browsers can.

Any ideas or tips for sending html emails from a webapp?

MBS sample code:

[code]Sub Action()
dim e as new EmailMessage
dim html as string

e.AddRecipient EditField4.text
e.Subject = “test email”
e.FromAddress = “oliver@osswald.com

if TargetWin32 then
html = HTMLViewer1.IEHTMLTextMBS
else
html = HTMLViewer1.mainFrameMBS.dataSource.data
end if

e.BodyPlainText = “see html content in this email”

e.BodyHTML = html

sock.Messages.Append e
sock.Address = EditField1.text
sock.Username = EditField2.text
sock.Password = EditField3.text
sock.port = 25
sock.SendMail
End Sub
[/code]

The way I usually debug problems like this one is by looking at the source of the email. Apple Mail allows you to do that conveniently (alt-command-U). See what happened to your HTML section. Christians Plugin also contains the new MimeEmailMBS which is certainly worth looking at.

Those images… Make sure the urls are absolute (including the http part).

Thanks Maximilian and Greg! I found out that cURLMBS of Monkeybread is working for me. I found an example made by Christian (“Send email”) which uses cURLMBS and cURLEmailMBS. This works great while the EmailMessage class of Xojo is not doing the job (see above).

pdf2htmlEX is actually creating an HTML file which includes everything, also fonts and pictures and then cURLMBS is correctly sending this out.

I do a TextInputStream.ReadAll of that html file and then set the cURLEmailMBS.HTMLText property with it. And the result in OSX Mail looks exactly like the PDF:

I see Maximilian and Greg and ofcourse Christian won a free seminar… :smiley:

Hmm, I just noticed that Outlook 2011 is not capable to display the graphics included in the html code, generated by pdf2htmlEX. However, it does respect the fonts and text positions.

Apple Mail on the other hand is displaying correctly all elements (screenshot above)

Outlook and HTML mails are a nightmare :-/ in any version…
How do you embed the pictures?

  • static linking against a web address
  • relative linking against picture in attachments
  • inline with EncodeBase64

[quote=222213:@Alex von Siebenthal]Outlook and HTML mails are a nightmare :-/ in any version…
How do you embed the pictures?

  • static linking against a web address
  • relative linking against picture in attachments
  • inline with EncodeBase64[/quote]

inline with EncodeBase64. In fact I’m not coding this myself but just make use of the output created by pdf2htmlEX on the Ubuntu Server.

What I do is to create a PDF invoice with DynaPDF and then I open a shell and pass that pdf file to pdf2htmlEX, which creates an HTML file with inline code.

Then I take the generated html file and send it as an email, using cURLSMBS. I also attach the pdf file to the email.

Appart from Outlook display hicks, this works fine.

Curious why you wouldn’t just send the pdf ?

When I noticed how well this pdf2htmlEX creates HTML from PDF, I thought I get a cheap way to mail out the invoice, which I already had formatted for pdf. Especially because it does inline graphics and fonts.

The main reason why I create pdf-files is for later download in the users login area.

Initially I wanted to avoid sending any attached file because then there is a higher chance for the email to end up in spam folders.

I will test more and see what beta testers say and maybe I step back to plain text emails.

BTW, if anyone is interested in PDF to HTML conversion, then this is how I installed it on a Linux Ubuntu Server:

Open a ssh session and then execute the following commands:

sudo apt-get install software-properties-common sudo add-apt-repository ppa:coolwanglu/pdf2htmlex sudo apt-get update sudo apt-get install fontforge

(This may fail, when we called (sudo aptitude install poppler-utils) before)

sudo apt-get install poppler

Finally install pdf2htmlex:

sudo apt-get install pdf2htmlex

To create a html from pdf, type for example:

pdf2htmlEX ./test.pdf

or

pdf2htmlEX ../test.pdf ../t/hallo.html

pdf2htmlEX is opensource on github:
https://github.com/coolwanglu/pdf2htmlEX

[quote=222224:@Oliver Osswald]When I noticed how well this pdf2htmlEX creates HTML from PDF, I thought I get a cheap way to mail out the invoice, which I already had formatted for pdf. Especially because it does inline graphics and fonts.

The main reason why I create pdf-files is for later download in the users login area.

Initially I wanted to avoid sending any attached file because then there is a higher chance for the email to end up in spam folders.

I will test more and see what beta testers say and maybe I step back to plain text emails.[/quote]
Fair enough
Like I said it was just a curiosity since you obviously spent a lot of time getting the PDF just right but dont send it

[quote=222216:@Oliver Osswald]inline with EncodeBase64. In fact I’m not coding this myself but just make use of the output created by pdf2htmlEX on the Ubuntu Server.

What I do is to create a PDF invoice with DynaPDF and then I open a shell and pass that pdf file to pdf2htmlEX, which creates an HTML file with inline code.

Then I take the generated html file and send it as an email, using cURLSMBS. I also attach the pdf file to the email.

Appart from Outlook display hicks, this works fine.[/quote]

Yeah, images as Enc64 rarely work well in Outlook… :frowning: been there. Can you share the raw HTML of the email? Either here or in a file to download?

One thing is a generated html file, which can be looked at from here:
http://osswald.com/xojo/issues/email/test.html

The other thing I have is part from the email log file, downloadable here:
http://osswald.com/xojo/issues/email/email.log

Well, I can suggest everyone uses the CURLSEmailMBS class which can help building the email with less pain.

I put a lot of work into this class:
http://www.monkeybreadsoftware.net/class-curlemailmbs.shtml

[quote=222240:@Christian Schmitz]Well, I can suggest everyone uses the CURLSEmailMBS class which can help building the email with less pain.

I put a lot of work into this class:
http://www.monkeybreadsoftware.net/class-curlemailmbs.shtml[/quote]

That could actually be your solution, Oliver. Outlook supports the embedding Enc64 images through inline CID: http://www.monkeybreadsoftware.net/curl-curlemailmbs-method.shtml#1

My suggestion:

  • Replace the Enc64 part with src="cid:your-cid-here" either through .ReplaceAll or RegEx
  • Use the MBS method to attach the picture (make sure to match the cid): http://www.monkeybreadsoftware.net/curl-curlemailmbs-method.shtml#1 => the method, however, expects a MemoryBlock and doesn’t accept direct Enc64 data, so you’ll need to convert it back through DecodeBase64
  • make sure to set type to “image/png”, name to “your-cid-here.png” and InlineID to “your-cid-here”

I could of course add a method which takes already Base64 encoded text. But normally people don’t have that.