HTML table loses border when mail is forwarded - java

I am trying to include HTML tables with Outlook emails. It is able to render and provide the content when the mail is sent initially. But, the table loses it's border whenever the mail is forwarded. But, the structure is preserved.
Is there anyway to embed some css so that the content is rendered whenever the mail is forwarded ?
EDIT : I am using outlook to send the mails and the tables are already inline styled. Also the code is written for generation of email using apache velocity engine.

it's wired as each email client treats forwarded messages, so if gmail adds some classes to restyle the forwarded tables I don't think there's much you can do about that. I would suggest trying to use some divs inside table cells and give a border to those.
and there's a tool that will help you so much when writing email templates, called emogrefier. basically you write css and it automatically applies that style as inline. you can even use scss and set the exported file to be included as inline style.

Related

How to embed an image in email?

I am trying to write a Java program where I need to send an image to Gmail. I am sending the image as an embedded object.
<img src="data:image/jpg;base64,iVBORw0KGgoAAAANSUhEUgAAACcAAAAsCAYAAADmZKH2AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAABISURBVFhH7c4hAQAgEAAxEhGGZN8YOkwhTsxvnT33V+VUOVVOlVPlVDlVTpVT5VQ5VU6VU+VUOVVOlVPlVDlVTpVT5dTHubkPuMrNUFKjQWUAAAAASUVORK5CYII=">
Other mail service providers are showing it fine, but Gmail specifically is removing it, so it is not visible in the message.
How can I make it visible in Gmail as well as the other mail service providers?
Place the image in a publicly accessible server and give the url for src attribute instead of dataUrl.
It is not possible in Gmail, outlook etc. They ignore base64 images.
For further information follow the link at below.
https://www.campaignmonitor.com/blog/email-marketing/2013/02/embedded-images-in-html-email/
There is an alternative way for doing this. Embed images in the email using the cid method. (Basically including the image as an attachment, and then embedding it).
https://www.campaignmonitor.com/blog/how-to/2008/08/embedding-images-revisited/

How to control the life cycle of eclipse browser and monitor its HTML content change

The scenario is that when I would like to launch the browswer pointing to some web pages in Eclipse Plugin and I would like to monitor the content change in the HTTP/S message and do some corresponding operations.
The corresponding operations may looks like fetch the raw field of HTTP/S message from browser.
For example, when users do some operations (AJAX) call and then the title or other fields of HTML page change, I would like to know this is happpening and fetch the "raw" content from the body field of HTTP/S message.
I found some ways to launch the browser here. The first one is that I could use SWT browser (org.eclipse.swt.browser.Browser) here. However, I do not see it expose any listener API to monitor this change, let alone fetch raw content of HTTP/S message.
The second one is about org.eclipse.ui.browser.IWebBrowser. I also do not see any API expose by IWebBrowser.
Does anyone kwno how to do achieve this? Thank for your help.
This are no APIs for this.
The Browser class does have listeners for changes to the Location (addLocationListener) and the page title (addTitleListener) but these are fairly limited.

How can I preserve HTML/CSS formatting between email client and HTML web page?

I have a client that uses Google Mail's IMAP library to read HTML email from a Gmail inbox, then uploads said email to a database for retrieval and display on a web page. The idea is to have all company-wide emails available in a centralized location for reference by employees.
I have all the code working to grab the emails from Gmail, insert into the database, and display on the internet.
The problem I am having is that when displaying the HTML emails on the website, the HTML inherits all sorts of CSS class, et al. definitions in place on the page and ruins the formatting of the original email. For example, a simple bulleted list from the email takes on a background color and specialized font. I have experimented with wkhtmltopdf to preserve formatting fidelity, but the customer wants the raw email on the page in it's original formatting rather than a linked PDF.
Is there a way I can discard all inherited formatting and display the HTML email to the web page in it's original formatting?
You can display the email in an iframe.
The iframe doesn't inherit the CSS from the calling parent, so your email is displayed with a clean css sheet.

Advice with crawling web site content

I was trying to crawl some of website content, using jsoup and java combination. Save the relevant details to my database and doing the same activity daily.
But here is the deal, when I open the website in browser I get rendered html (with all element tags out there). The javascript part when I test it, it works just fine (the one which I'm supposed to use to extract the correct data).
But when I do a parse/get with jsoup(from Java class), only the initial website is downloaded for parsing. Meaning there are some dynamic parts of a website and I want to get that data but since they're rendered post get, asynchronously on the website I'm unable to capture it with jsoup.
Does anybody knows a way around this? Am I using the right toolset? more experienced people, I bid your advice.
You need to check before if the website you're crawling demands some of this list to show all contents:
Authentication with Login/Password
Some sort of session validation on HTTP headers
Cookies
Some sort of time delay to load all the contents (sites profuse on Javascript libraries, CSS and asyncronous data may need of this).
An specific User-Agent browser
A proxy password if, by example, you're inside a corporative network security configuration.
If anything on this list is needed, you can manage that data providing the parameters in your jsoup.connect(). Please refer the official doc.
http://jsoup.org/cookbook/input/load-document-from-url

Send HTML email with an pdf attachment by using Java

I am trying to send an email with Java, I am using apache commons email library.
I cannot achieve to send an email with a body as HTML and an attachment as PDF (or any file type)
If I use EmailAttachment() and add it to an HtmlEmail object, my mail looks like with two attachment. First one is for HTML, second is for PDF.
Is there any way to do that?
Thank you very much!
It sounds like relatively normal behaviour for a message that's being sent as both text and HTML, and/or a mail client (at the receiving end) that prefers text emails. I suspect that this is due to the behaviour of the client, which you won't be able to change (but on the plus side all HTML emails would appear like this).
The thing is, an HTML email (with a textual component) really is a multipart message, with the HTML content as one of the "extra" parts. All you're actually sending in the email from the server side is a bunch of text, and it's up to the receiving mail client to decide how to display it. In that respect, it is not wrong for the client to display your HTML as an attachment - just like it is not wrong for a smart client to infer that the HTML isn't a "real" attachment and activate some kind of toggle between text and HTML (rather than displaying it as an attachment).
If you're convinced that the client would normally treat HTML in this smart way, then:
You'll have to mention which client you're using to check, because this isn't really an issue with the sending per se; and
You might want to take a look at the raw source of email that "works", and your email that doesn't, in order to determine what the critical differences are that trigger the different rendering modes. Depending on the client software, this could be just about anything - but I'd pay particular attention to part MIME types and charsets.
I tried apache commons mail v1.2 instead of 1.1.
It works!?
Andrej, by the way many thanks for your kindly help.

Categories