#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    3
    Rep Power
    0

    Inconsistent email formatting with inline css created using Javamail


    Okay, so I have a program that sends an email when it is finished running. I use inline css to format the email. This was working up until yesterday however now I am seeing different formats depending on which email account I view the email in. It coincides with an upgrade from Selenium 2.35.0 to 2.37.0 however I don't think this is my issue since I rolled back to 2.35.0 and it still happens.

    Code:
    package tests;
    
    import java.util.Properties;
    
    import javax.mail.Message;
    import javax.mail.Session;
    import javax.mail.Transport;
    import javax.mail.internet.InternetAddress;
    import javax.mail.internet.MimeMessage;
    
    public class TESTTEST {
    	
    	public static void main(String[] args) throws Exception
    	{
    		Properties props = new Properties();		
    		props.put("mail.smtp.host","xxx.xxx.xxx.xxx");		
    		Session session = Session.getInstance(props);	
    
    		String emailFrom="xxx@xxx.com";
    		String emailTo1="xxx@xxx.com";
         
    	      
    		MimeMessage message = new MimeMessage(session);
    		message.setSubject("Testing HTML Email");
    		message.setFrom(new InternetAddress(emailFrom));
    	      
    		String htmlBody = "<STYLE>body {font-family:sans-serif,arial,helvetica,sans-serif;font-size:9pt;}"
    	        	 +"TABLE {border-collapse:collapse;border:1px solid black;}"
    	        	 +"TH {background-color:grey;color:white;padding:5px;border:1px solid black;font-size:9pt;}"
    	        	 +"TD {padding:5px;border:1px solid black;font-size:9pt;}"
    	        	 +"H3 {font-size:12pt;}"
    	        	 +".PASSED {background-color:#00FF00}"
    	        	 +".FAILED {background-color:#FF0000}"
    	        	 +".SKIPPED {background-color:#DEDEDE}"
    	        	 +".ITALIC {font-style:italic}"
    	        	 +"</STYLE>"
    	      		 + "<TABLE><TR><TD CLASS=PASSED>FAIL</TD><TD STYLE=background-color:#FF0000>FAIL</TD></TR></TABLE>";
    	      
    	      message.setContent(htmlBody, "text/html; charset=ISO-8859-1");
    	      
    	      message.addRecipient(Message.RecipientType.TO,new InternetAddress(emailTo1));
    
    	      Transport.send(message,message.getRecipients(Message.RecipientType.TO));
    	      
    	      System.out.println(htmlBody);
    	      System.out.println("Email Sent");
    	 }	
    }
    When I view the email in hotmail, it looks fine http://imageshack.us/photo/my-images/820/i59s.png/

    In gmail http://imageshack.us/photo/my-images/823/11t0.png/

    In Lotus Notes http://imageshack.us/photo/my-images/401/it38.png/


    Anybody able to help?
  2. #2
  3. Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    May 2004
    Location
    Superior, CO, USA
    Posts
    2,418
    Rep Power
    1713
    This isn't really a Java question - it is about HTML/CSS and the wierd ways that each mail provider handles it.

    I've gone through this too. I didn't think that Lotus Notes even still existed but the only way I could get GMail to display the way I wanted was to put the CSS directly on the element, i.e.:

    html4strict Code:
    <table style="background-color:grey;color:white;">


    and so on.

    Also, remember that tags for HTML 5 are lower case - depending on the browser that you're using to view the code that may be important.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    3
    Rep Power
    0
    Originally Posted by stdunbar
    This isn't really a Java question - it is about HTML/CSS and the wierd ways that each mail provider handles it.

    I've gone through this too. I didn't think that Lotus Notes even still existed but the only way I could get GMail to display the way I wanted was to put the CSS directly on the element, i.e.:

    html4strict Code:
    <table style="background-color:grey;color:white;">
    Cheers, when I put the css on each element, it does work however it doesn't work when I put it in the <style> tags

    Originally Posted by stdunbar
    and so on.

    Also, remember that tags for HTML 5 are lower case - depending on the browser that you're using to view the code that may be important.
    I did wonder if that was the problem and set all the tags to lowercase but it made no difference
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    3
    Rep Power
    0
    This is now fixed. It was an issue with internal email relay stripping the html content from the email. Apologies

IMN logo majestic logo threadwatch logo seochat tools logo