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
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.
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:
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)
[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.
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=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… been there. Can you share the raw HTML of the email? Either here or in a file to download?
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”