How do I send an HTML email?












108















I have successfully sent email in my web application using JMS, but the result only displays in plain text. I want the content to be able to display html. How do I do it? Here is roughly what I have:



Message msg = new MimeMessage(mailSession);
try{
msg.setSubject("Test Notification");
msg.setRecipient(Message.RecipientType.TO, new InternetAddress(sentTo, false));
String message = "<div style="color:red;">BRIDGEYE</div>";
msg.setContent(message, "text/html; charset=utf-8");
msg.setSentDate(new Date());
Transport.send(msg);
}catch(MessagingException me){
logger.log(Level.SEVERE, "sendEmailNotification: {0}", me.getMessage());
}









share|improve this question





























    108















    I have successfully sent email in my web application using JMS, but the result only displays in plain text. I want the content to be able to display html. How do I do it? Here is roughly what I have:



    Message msg = new MimeMessage(mailSession);
    try{
    msg.setSubject("Test Notification");
    msg.setRecipient(Message.RecipientType.TO, new InternetAddress(sentTo, false));
    String message = "<div style="color:red;">BRIDGEYE</div>";
    msg.setContent(message, "text/html; charset=utf-8");
    msg.setSentDate(new Date());
    Transport.send(msg);
    }catch(MessagingException me){
    logger.log(Level.SEVERE, "sendEmailNotification: {0}", me.getMessage());
    }









    share|improve this question



























      108












      108








      108


      22






      I have successfully sent email in my web application using JMS, but the result only displays in plain text. I want the content to be able to display html. How do I do it? Here is roughly what I have:



      Message msg = new MimeMessage(mailSession);
      try{
      msg.setSubject("Test Notification");
      msg.setRecipient(Message.RecipientType.TO, new InternetAddress(sentTo, false));
      String message = "<div style="color:red;">BRIDGEYE</div>";
      msg.setContent(message, "text/html; charset=utf-8");
      msg.setSentDate(new Date());
      Transport.send(msg);
      }catch(MessagingException me){
      logger.log(Level.SEVERE, "sendEmailNotification: {0}", me.getMessage());
      }









      share|improve this question
















      I have successfully sent email in my web application using JMS, but the result only displays in plain text. I want the content to be able to display html. How do I do it? Here is roughly what I have:



      Message msg = new MimeMessage(mailSession);
      try{
      msg.setSubject("Test Notification");
      msg.setRecipient(Message.RecipientType.TO, new InternetAddress(sentTo, false));
      String message = "<div style="color:red;">BRIDGEYE</div>";
      msg.setContent(message, "text/html; charset=utf-8");
      msg.setSentDate(new Date());
      Transport.send(msg);
      }catch(MessagingException me){
      logger.log(Level.SEVERE, "sendEmailNotification: {0}", me.getMessage());
      }






      java email javamail






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jun 4 '16 at 20:00









      Dave Jarvis

      21k30132256




      21k30132256










      asked Feb 21 '11 at 16:58









      Thang PhamThang Pham

      14.8k69180275




      14.8k69180275
























          9 Answers
          9






          active

          oldest

          votes


















          247














          As per the Javadoc, the MimeMessage#setText() sets a default mime type of text/plain, while you need text/html. Rather use MimeMessage#setContent() instead.



          message.setContent(someHtmlMessage, "text/html; charset=utf-8");


          For additional details, see:




          • GMail Media Queries

          • GMail CSS Design

          • CSS support in mail clients






          share|improve this answer


























          • Thanks, at first I did not read carefully, I have setText and setContent together, so it does not work, but now after taking out setText(), it work now. Thank you.

            – Thang Pham
            Feb 21 '11 at 17:47



















          19














          Set content type. Look at this method.



          message.setContent("<h1>Hello</h1>", "text/html");





          share|improve this answer


























          • For Groovy. Don't forget to convert GString to java.lang.String.

            – it3xl
            Mar 6 '18 at 8:29



















          12














          If you are using Google app engine/Java, then use the following...



          MimeMessage msg = new MimeMessage(session);
          msg.setFrom(new InternetAddress(SENDER_EMAIL_ADDRESS, "Admin"));
          msg.addRecipient(Message.RecipientType.TO,
          new InternetAddress(toAddress, "user");

          msg.setSubject(subject,"UTF-8");

          Multipart mp = new MimeMultipart();
          MimeBodyPart htmlPart = new MimeBodyPart();
          htmlPart.setContent(message, "text/html");
          mp.addBodyPart(htmlPart);
          msg.setContent(mp);
          Transport.send(msg);





          share|improve this answer


























          • msg.setSubject(subject,"UTF-8"); does not work. It should be msg.setSubject(subject);

            – Fizer Khan
            Sep 9 '14 at 17:08











          • @FizerKhan - really? docs.oracle.com/javaee/6/api/javax/mail/internet/…

            – Nick Grealy
            Mar 31 '15 at 3:49





















          3














          Take a look at http://commons.apache.org/email/ they have an HtmlEmail class that probably does exactly what you need.






          share|improve this answer
























          • commons.apache.org/proper/commons-email/apidocs/org/apache/…

            – Anand Rockzz
            Apr 30 '17 at 22:31



















          3














          you have to call



          msg.saveChanges();


          after setting content type.






          share|improve this answer

































            3














            Since JavaMail version 1.4, there is an overload of setText method that accepts the subtype.



            // Passing null for second argument in order for the method to determine
            // the actual charset on-the fly.
            // If you know the charset, pass it. "utf-8" should be fine
            msg.setText( message, null, "html" );





            share|improve this answer

































              0














              You can find a complete and very simple java class for sending emails using Google(gmail) account here,
              Send email message using java application



              It uses following properties



              Properties props = new Properties();
              props.put("mail.smtp.auth", "true");
              props.put("mail.smtp.starttls.enable", "true");
              props.put("mail.smtp.host", "smtp.gmail.com");
              props.put("mail.smtp.port", "587");





              share|improve this answer



















              • 2





                This doesn't at all address the question. The OP was asking to send specifically HTML emails.

                – Bassinator
                Nov 10 '17 at 2:33



















              0














              The "loginVo.htmlBody(messageBodyPart);" will contain the html formatted designed information, but in mail does not receive it.



              JAVA - STRUTS2



              package com.action;
              import javax.mail.Multipart;
              import javax.mail.Session;
              import javax.mail.Transport;
              import javax.mail.internet.MimeMessage;
              import javax.mail.internet.MimeMultipart;
              import com.opensymphony.xwork2.Action;
              import com.bo.LoginBo;
              import com.manager.AttendanceManager;
              import com.manager.LoginManager;
              import com.manager.SSLEmail;
              import com.vo.AttendanceManagementVo;
              import com.vo.LeaveManagementVo;
              import com.vo.LoginVo;
              import com.sun.corba.se.impl.protocol.giopmsgheaders.Message;
              import com.sun.xml.internal.messaging.saaj.packaging.mime.internet.MimeBodyPart;

              public class InsertApplyLeaveAction implements Action {
              private AttendanceManagementVo attendanceManagementVo;

              public AttendanceManagementVo getAttendanceManagementVo() {
              return attendanceManagementVo;
              }

              public void setAttendanceManagementVo(
              AttendanceManagementVo attendanceManagementVo) {
              this.attendanceManagementVo = attendanceManagementVo;
              }

              @Override
              public String execute() throws Exception {
              String empId=attendanceManagementVo.getEmpId();
              String leaveType=attendanceManagementVo.getLeaveType();
              String leaveStartDate=attendanceManagementVo.getLeaveStartDate();
              String leaveEndDate=attendanceManagementVo.getLeaveEndDate();
              String reason=attendanceManagementVo.getReason();
              String employeeName=attendanceManagementVo.getEmployeeName();
              String manageEmployeeId=empId;
              float totalLeave=attendanceManagementVo.getTotalLeave();
              String leaveStatus=attendanceManagementVo.getLeaveStatus();
              // String approverId=attendanceManagementVo.getApproverId();
              attendanceManagementVo.setEmpId(empId);
              attendanceManagementVo.setLeaveType(leaveType);
              attendanceManagementVo.setLeaveStartDate(leaveStartDate);
              attendanceManagementVo.setLeaveEndDate(leaveEndDate);
              attendanceManagementVo.setReason(reason);
              attendanceManagementVo.setManageEmployeeId(manageEmployeeId);
              attendanceManagementVo.setTotalLeave(totalLeave);
              attendanceManagementVo.setLeaveStatus(leaveStatus);
              attendanceManagementVo.setEmployeeName(employeeName);

              AttendanceManagementVo attendanceManagementVo1=new AttendanceManagementVo();
              AttendanceManager attendanceManager=new AttendanceManager();
              attendanceManagementVo1=attendanceManager.insertLeaveData(attendanceManagementVo);
              attendanceManagementVo1=attendanceManager.getApproverId(attendanceManagementVo);
              String approverId=attendanceManagementVo1.getApproverId();
              String approverEmployeeName=attendanceManagementVo1.getApproverEmployeeName();
              LoginVo loginVo=new LoginVo();
              LoginManager loginManager=new LoginManager();
              loginVo.setEmpId(approverId);
              loginVo=loginManager.getEmailAddress(loginVo);
              String emailAddress=loginVo.getEmailAddress();
              String subject="LEAVE IS SUBMITTED FOR AN APPROVAL BY THE - " +employeeName;
              // String body = "Hi "+approverEmployeeName+" ," + "n" + "n" +
              // leaveType+" is Applied for "+totalLeave+" days by the " +employeeName+ "n" + "n" +
              // " Employee Name: " + employeeName +"n" +
              // " Applied Leave Type: " + leaveType +"n" +
              // " Total Days: " + totalLeave +"n" + "n" +
              // " To view Leave History, Please visit the employee poratal or copy and paste the below link in your browser: " + "n" +

              // " NOTE : This is an automated message. Please do not reply."+ "n" + "n" +

              Session session = null;

              MimeBodyPart messageBodyPart = new MimeBodyPart();
              MimeMessage message = new MimeMessage(session);
              Multipart multipart = new MimeMultipart();

              String htmlText = ("<div style="color:red;">BRIDGEYE</div>");
              messageBodyPart.setContent(htmlText, "text/html");

              loginVo.setHtmlBody(messageBodyPart);

              message.setContent(multipart);
              Transport.send(message);


              loginVo.setSubject(subject);
              // loginVo.setBody(body);
              loginVo.setEmailAddress(emailAddress);
              SSLEmail sSSEmail=new SSLEmail();
              sSSEmail.sendEmail(loginVo);
              return "success";
              }

              }





              share|improve this answer































                0














                I found this way not sure it works for all the CSS primitives



                By setting the header property "Content-Type" to "text/html"



                mimeMessage.setHeader("Content-Type", "text/html");


                now I can do stuff like



                mimeMessage.setHeader("Content-Type", "text/html");

                mimeMessage.setText ("`<html><body><h1 style ="color:blue;">My first Header<h1></body></html>`")


                Regards






                share|improve this answer

























                  Your Answer






                  StackExchange.ifUsing("editor", function () {
                  StackExchange.using("externalEditor", function () {
                  StackExchange.using("snippets", function () {
                  StackExchange.snippets.init();
                  });
                  });
                  }, "code-snippets");

                  StackExchange.ready(function() {
                  var channelOptions = {
                  tags: "".split(" "),
                  id: "1"
                  };
                  initTagRenderer("".split(" "), "".split(" "), channelOptions);

                  StackExchange.using("externalEditor", function() {
                  // Have to fire editor after snippets, if snippets enabled
                  if (StackExchange.settings.snippets.snippetsEnabled) {
                  StackExchange.using("snippets", function() {
                  createEditor();
                  });
                  }
                  else {
                  createEditor();
                  }
                  });

                  function createEditor() {
                  StackExchange.prepareEditor({
                  heartbeatType: 'answer',
                  autoActivateHeartbeat: false,
                  convertImagesToLinks: true,
                  noModals: true,
                  showLowRepImageUploadWarning: true,
                  reputationToPostImages: 10,
                  bindNavPrevention: true,
                  postfix: "",
                  imageUploader: {
                  brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                  contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                  allowUrls: true
                  },
                  onDemand: true,
                  discardSelector: ".discard-answer"
                  ,immediatelyShowMarkdownHelp:true
                  });


                  }
                  });














                  draft saved

                  draft discarded


















                  StackExchange.ready(
                  function () {
                  StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f5068827%2fhow-do-i-send-an-html-email%23new-answer', 'question_page');
                  }
                  );

                  Post as a guest















                  Required, but never shown

























                  9 Answers
                  9






                  active

                  oldest

                  votes








                  9 Answers
                  9






                  active

                  oldest

                  votes









                  active

                  oldest

                  votes






                  active

                  oldest

                  votes









                  247














                  As per the Javadoc, the MimeMessage#setText() sets a default mime type of text/plain, while you need text/html. Rather use MimeMessage#setContent() instead.



                  message.setContent(someHtmlMessage, "text/html; charset=utf-8");


                  For additional details, see:




                  • GMail Media Queries

                  • GMail CSS Design

                  • CSS support in mail clients






                  share|improve this answer


























                  • Thanks, at first I did not read carefully, I have setText and setContent together, so it does not work, but now after taking out setText(), it work now. Thank you.

                    – Thang Pham
                    Feb 21 '11 at 17:47
















                  247














                  As per the Javadoc, the MimeMessage#setText() sets a default mime type of text/plain, while you need text/html. Rather use MimeMessage#setContent() instead.



                  message.setContent(someHtmlMessage, "text/html; charset=utf-8");


                  For additional details, see:




                  • GMail Media Queries

                  • GMail CSS Design

                  • CSS support in mail clients






                  share|improve this answer


























                  • Thanks, at first I did not read carefully, I have setText and setContent together, so it does not work, but now after taking out setText(), it work now. Thank you.

                    – Thang Pham
                    Feb 21 '11 at 17:47














                  247












                  247








                  247







                  As per the Javadoc, the MimeMessage#setText() sets a default mime type of text/plain, while you need text/html. Rather use MimeMessage#setContent() instead.



                  message.setContent(someHtmlMessage, "text/html; charset=utf-8");


                  For additional details, see:




                  • GMail Media Queries

                  • GMail CSS Design

                  • CSS support in mail clients






                  share|improve this answer















                  As per the Javadoc, the MimeMessage#setText() sets a default mime type of text/plain, while you need text/html. Rather use MimeMessage#setContent() instead.



                  message.setContent(someHtmlMessage, "text/html; charset=utf-8");


                  For additional details, see:




                  • GMail Media Queries

                  • GMail CSS Design

                  • CSS support in mail clients







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Sep 13 '18 at 19:57









                  Dave Jarvis

                  21k30132256




                  21k30132256










                  answered Feb 21 '11 at 17:06









                  BalusCBalusC

                  850k29831503222




                  850k29831503222













                  • Thanks, at first I did not read carefully, I have setText and setContent together, so it does not work, but now after taking out setText(), it work now. Thank you.

                    – Thang Pham
                    Feb 21 '11 at 17:47



















                  • Thanks, at first I did not read carefully, I have setText and setContent together, so it does not work, but now after taking out setText(), it work now. Thank you.

                    – Thang Pham
                    Feb 21 '11 at 17:47

















                  Thanks, at first I did not read carefully, I have setText and setContent together, so it does not work, but now after taking out setText(), it work now. Thank you.

                  – Thang Pham
                  Feb 21 '11 at 17:47





                  Thanks, at first I did not read carefully, I have setText and setContent together, so it does not work, but now after taking out setText(), it work now. Thank you.

                  – Thang Pham
                  Feb 21 '11 at 17:47













                  19














                  Set content type. Look at this method.



                  message.setContent("<h1>Hello</h1>", "text/html");





                  share|improve this answer


























                  • For Groovy. Don't forget to convert GString to java.lang.String.

                    – it3xl
                    Mar 6 '18 at 8:29
















                  19














                  Set content type. Look at this method.



                  message.setContent("<h1>Hello</h1>", "text/html");





                  share|improve this answer


























                  • For Groovy. Don't forget to convert GString to java.lang.String.

                    – it3xl
                    Mar 6 '18 at 8:29














                  19












                  19








                  19







                  Set content type. Look at this method.



                  message.setContent("<h1>Hello</h1>", "text/html");





                  share|improve this answer















                  Set content type. Look at this method.



                  message.setContent("<h1>Hello</h1>", "text/html");






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited May 6 '13 at 14:40









                  Doug Porter

                  6,78843253




                  6,78843253










                  answered Feb 21 '11 at 17:05









                  CoolBeansCoolBeans

                  18.3k107094




                  18.3k107094













                  • For Groovy. Don't forget to convert GString to java.lang.String.

                    – it3xl
                    Mar 6 '18 at 8:29



















                  • For Groovy. Don't forget to convert GString to java.lang.String.

                    – it3xl
                    Mar 6 '18 at 8:29

















                  For Groovy. Don't forget to convert GString to java.lang.String.

                  – it3xl
                  Mar 6 '18 at 8:29





                  For Groovy. Don't forget to convert GString to java.lang.String.

                  – it3xl
                  Mar 6 '18 at 8:29











                  12














                  If you are using Google app engine/Java, then use the following...



                  MimeMessage msg = new MimeMessage(session);
                  msg.setFrom(new InternetAddress(SENDER_EMAIL_ADDRESS, "Admin"));
                  msg.addRecipient(Message.RecipientType.TO,
                  new InternetAddress(toAddress, "user");

                  msg.setSubject(subject,"UTF-8");

                  Multipart mp = new MimeMultipart();
                  MimeBodyPart htmlPart = new MimeBodyPart();
                  htmlPart.setContent(message, "text/html");
                  mp.addBodyPart(htmlPart);
                  msg.setContent(mp);
                  Transport.send(msg);





                  share|improve this answer


























                  • msg.setSubject(subject,"UTF-8"); does not work. It should be msg.setSubject(subject);

                    – Fizer Khan
                    Sep 9 '14 at 17:08











                  • @FizerKhan - really? docs.oracle.com/javaee/6/api/javax/mail/internet/…

                    – Nick Grealy
                    Mar 31 '15 at 3:49


















                  12














                  If you are using Google app engine/Java, then use the following...



                  MimeMessage msg = new MimeMessage(session);
                  msg.setFrom(new InternetAddress(SENDER_EMAIL_ADDRESS, "Admin"));
                  msg.addRecipient(Message.RecipientType.TO,
                  new InternetAddress(toAddress, "user");

                  msg.setSubject(subject,"UTF-8");

                  Multipart mp = new MimeMultipart();
                  MimeBodyPart htmlPart = new MimeBodyPart();
                  htmlPart.setContent(message, "text/html");
                  mp.addBodyPart(htmlPart);
                  msg.setContent(mp);
                  Transport.send(msg);





                  share|improve this answer


























                  • msg.setSubject(subject,"UTF-8"); does not work. It should be msg.setSubject(subject);

                    – Fizer Khan
                    Sep 9 '14 at 17:08











                  • @FizerKhan - really? docs.oracle.com/javaee/6/api/javax/mail/internet/…

                    – Nick Grealy
                    Mar 31 '15 at 3:49
















                  12












                  12








                  12







                  If you are using Google app engine/Java, then use the following...



                  MimeMessage msg = new MimeMessage(session);
                  msg.setFrom(new InternetAddress(SENDER_EMAIL_ADDRESS, "Admin"));
                  msg.addRecipient(Message.RecipientType.TO,
                  new InternetAddress(toAddress, "user");

                  msg.setSubject(subject,"UTF-8");

                  Multipart mp = new MimeMultipart();
                  MimeBodyPart htmlPart = new MimeBodyPart();
                  htmlPart.setContent(message, "text/html");
                  mp.addBodyPart(htmlPart);
                  msg.setContent(mp);
                  Transport.send(msg);





                  share|improve this answer















                  If you are using Google app engine/Java, then use the following...



                  MimeMessage msg = new MimeMessage(session);
                  msg.setFrom(new InternetAddress(SENDER_EMAIL_ADDRESS, "Admin"));
                  msg.addRecipient(Message.RecipientType.TO,
                  new InternetAddress(toAddress, "user");

                  msg.setSubject(subject,"UTF-8");

                  Multipart mp = new MimeMultipart();
                  MimeBodyPart htmlPart = new MimeBodyPart();
                  htmlPart.setContent(message, "text/html");
                  mp.addBodyPart(htmlPart);
                  msg.setContent(mp);
                  Transport.send(msg);






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited May 6 '13 at 14:27









                  Doug Porter

                  6,78843253




                  6,78843253










                  answered Nov 26 '12 at 12:44









                  Knowledge ServeKnowledge Serve

                  51858




                  51858













                  • msg.setSubject(subject,"UTF-8"); does not work. It should be msg.setSubject(subject);

                    – Fizer Khan
                    Sep 9 '14 at 17:08











                  • @FizerKhan - really? docs.oracle.com/javaee/6/api/javax/mail/internet/…

                    – Nick Grealy
                    Mar 31 '15 at 3:49





















                  • msg.setSubject(subject,"UTF-8"); does not work. It should be msg.setSubject(subject);

                    – Fizer Khan
                    Sep 9 '14 at 17:08











                  • @FizerKhan - really? docs.oracle.com/javaee/6/api/javax/mail/internet/…

                    – Nick Grealy
                    Mar 31 '15 at 3:49



















                  msg.setSubject(subject,"UTF-8"); does not work. It should be msg.setSubject(subject);

                  – Fizer Khan
                  Sep 9 '14 at 17:08





                  msg.setSubject(subject,"UTF-8"); does not work. It should be msg.setSubject(subject);

                  – Fizer Khan
                  Sep 9 '14 at 17:08













                  @FizerKhan - really? docs.oracle.com/javaee/6/api/javax/mail/internet/…

                  – Nick Grealy
                  Mar 31 '15 at 3:49







                  @FizerKhan - really? docs.oracle.com/javaee/6/api/javax/mail/internet/…

                  – Nick Grealy
                  Mar 31 '15 at 3:49













                  3














                  Take a look at http://commons.apache.org/email/ they have an HtmlEmail class that probably does exactly what you need.






                  share|improve this answer
























                  • commons.apache.org/proper/commons-email/apidocs/org/apache/…

                    – Anand Rockzz
                    Apr 30 '17 at 22:31
















                  3














                  Take a look at http://commons.apache.org/email/ they have an HtmlEmail class that probably does exactly what you need.






                  share|improve this answer
























                  • commons.apache.org/proper/commons-email/apidocs/org/apache/…

                    – Anand Rockzz
                    Apr 30 '17 at 22:31














                  3












                  3








                  3







                  Take a look at http://commons.apache.org/email/ they have an HtmlEmail class that probably does exactly what you need.






                  share|improve this answer













                  Take a look at http://commons.apache.org/email/ they have an HtmlEmail class that probably does exactly what you need.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Feb 21 '11 at 17:05









                  CarlosZCarlosZ

                  5,58111615




                  5,58111615













                  • commons.apache.org/proper/commons-email/apidocs/org/apache/…

                    – Anand Rockzz
                    Apr 30 '17 at 22:31



















                  • commons.apache.org/proper/commons-email/apidocs/org/apache/…

                    – Anand Rockzz
                    Apr 30 '17 at 22:31

















                  commons.apache.org/proper/commons-email/apidocs/org/apache/…

                  – Anand Rockzz
                  Apr 30 '17 at 22:31





                  commons.apache.org/proper/commons-email/apidocs/org/apache/…

                  – Anand Rockzz
                  Apr 30 '17 at 22:31











                  3














                  you have to call



                  msg.saveChanges();


                  after setting content type.






                  share|improve this answer






























                    3














                    you have to call



                    msg.saveChanges();


                    after setting content type.






                    share|improve this answer




























                      3












                      3








                      3







                      you have to call



                      msg.saveChanges();


                      after setting content type.






                      share|improve this answer















                      you have to call



                      msg.saveChanges();


                      after setting content type.







                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited Nov 17 '13 at 18:20









                      rolfl

                      15.7k63168




                      15.7k63168










                      answered Nov 17 '13 at 17:58









                      Afodunrinbi LanreAfodunrinbi Lanre

                      311




                      311























                          3














                          Since JavaMail version 1.4, there is an overload of setText method that accepts the subtype.



                          // Passing null for second argument in order for the method to determine
                          // the actual charset on-the fly.
                          // If you know the charset, pass it. "utf-8" should be fine
                          msg.setText( message, null, "html" );





                          share|improve this answer






























                            3














                            Since JavaMail version 1.4, there is an overload of setText method that accepts the subtype.



                            // Passing null for second argument in order for the method to determine
                            // the actual charset on-the fly.
                            // If you know the charset, pass it. "utf-8" should be fine
                            msg.setText( message, null, "html" );





                            share|improve this answer




























                              3












                              3








                              3







                              Since JavaMail version 1.4, there is an overload of setText method that accepts the subtype.



                              // Passing null for second argument in order for the method to determine
                              // the actual charset on-the fly.
                              // If you know the charset, pass it. "utf-8" should be fine
                              msg.setText( message, null, "html" );





                              share|improve this answer















                              Since JavaMail version 1.4, there is an overload of setText method that accepts the subtype.



                              // Passing null for second argument in order for the method to determine
                              // the actual charset on-the fly.
                              // If you know the charset, pass it. "utf-8" should be fine
                              msg.setText( message, null, "html" );






                              share|improve this answer














                              share|improve this answer



                              share|improve this answer








                              edited Feb 1 '18 at 22:18









                              Dave Moten

                              10.2k12836




                              10.2k12836










                              answered Mar 30 '17 at 17:38









                              Alexander PogrebnyakAlexander Pogrebnyak

                              38.1k885113




                              38.1k885113























                                  0














                                  You can find a complete and very simple java class for sending emails using Google(gmail) account here,
                                  Send email message using java application



                                  It uses following properties



                                  Properties props = new Properties();
                                  props.put("mail.smtp.auth", "true");
                                  props.put("mail.smtp.starttls.enable", "true");
                                  props.put("mail.smtp.host", "smtp.gmail.com");
                                  props.put("mail.smtp.port", "587");





                                  share|improve this answer



















                                  • 2





                                    This doesn't at all address the question. The OP was asking to send specifically HTML emails.

                                    – Bassinator
                                    Nov 10 '17 at 2:33
















                                  0














                                  You can find a complete and very simple java class for sending emails using Google(gmail) account here,
                                  Send email message using java application



                                  It uses following properties



                                  Properties props = new Properties();
                                  props.put("mail.smtp.auth", "true");
                                  props.put("mail.smtp.starttls.enable", "true");
                                  props.put("mail.smtp.host", "smtp.gmail.com");
                                  props.put("mail.smtp.port", "587");





                                  share|improve this answer



















                                  • 2





                                    This doesn't at all address the question. The OP was asking to send specifically HTML emails.

                                    – Bassinator
                                    Nov 10 '17 at 2:33














                                  0












                                  0








                                  0







                                  You can find a complete and very simple java class for sending emails using Google(gmail) account here,
                                  Send email message using java application



                                  It uses following properties



                                  Properties props = new Properties();
                                  props.put("mail.smtp.auth", "true");
                                  props.put("mail.smtp.starttls.enable", "true");
                                  props.put("mail.smtp.host", "smtp.gmail.com");
                                  props.put("mail.smtp.port", "587");





                                  share|improve this answer













                                  You can find a complete and very simple java class for sending emails using Google(gmail) account here,
                                  Send email message using java application



                                  It uses following properties



                                  Properties props = new Properties();
                                  props.put("mail.smtp.auth", "true");
                                  props.put("mail.smtp.starttls.enable", "true");
                                  props.put("mail.smtp.host", "smtp.gmail.com");
                                  props.put("mail.smtp.port", "587");






                                  share|improve this answer












                                  share|improve this answer



                                  share|improve this answer










                                  answered Sep 16 '13 at 10:00









                                  LasaLasa

                                  52




                                  52








                                  • 2





                                    This doesn't at all address the question. The OP was asking to send specifically HTML emails.

                                    – Bassinator
                                    Nov 10 '17 at 2:33














                                  • 2





                                    This doesn't at all address the question. The OP was asking to send specifically HTML emails.

                                    – Bassinator
                                    Nov 10 '17 at 2:33








                                  2




                                  2





                                  This doesn't at all address the question. The OP was asking to send specifically HTML emails.

                                  – Bassinator
                                  Nov 10 '17 at 2:33





                                  This doesn't at all address the question. The OP was asking to send specifically HTML emails.

                                  – Bassinator
                                  Nov 10 '17 at 2:33











                                  0














                                  The "loginVo.htmlBody(messageBodyPart);" will contain the html formatted designed information, but in mail does not receive it.



                                  JAVA - STRUTS2



                                  package com.action;
                                  import javax.mail.Multipart;
                                  import javax.mail.Session;
                                  import javax.mail.Transport;
                                  import javax.mail.internet.MimeMessage;
                                  import javax.mail.internet.MimeMultipart;
                                  import com.opensymphony.xwork2.Action;
                                  import com.bo.LoginBo;
                                  import com.manager.AttendanceManager;
                                  import com.manager.LoginManager;
                                  import com.manager.SSLEmail;
                                  import com.vo.AttendanceManagementVo;
                                  import com.vo.LeaveManagementVo;
                                  import com.vo.LoginVo;
                                  import com.sun.corba.se.impl.protocol.giopmsgheaders.Message;
                                  import com.sun.xml.internal.messaging.saaj.packaging.mime.internet.MimeBodyPart;

                                  public class InsertApplyLeaveAction implements Action {
                                  private AttendanceManagementVo attendanceManagementVo;

                                  public AttendanceManagementVo getAttendanceManagementVo() {
                                  return attendanceManagementVo;
                                  }

                                  public void setAttendanceManagementVo(
                                  AttendanceManagementVo attendanceManagementVo) {
                                  this.attendanceManagementVo = attendanceManagementVo;
                                  }

                                  @Override
                                  public String execute() throws Exception {
                                  String empId=attendanceManagementVo.getEmpId();
                                  String leaveType=attendanceManagementVo.getLeaveType();
                                  String leaveStartDate=attendanceManagementVo.getLeaveStartDate();
                                  String leaveEndDate=attendanceManagementVo.getLeaveEndDate();
                                  String reason=attendanceManagementVo.getReason();
                                  String employeeName=attendanceManagementVo.getEmployeeName();
                                  String manageEmployeeId=empId;
                                  float totalLeave=attendanceManagementVo.getTotalLeave();
                                  String leaveStatus=attendanceManagementVo.getLeaveStatus();
                                  // String approverId=attendanceManagementVo.getApproverId();
                                  attendanceManagementVo.setEmpId(empId);
                                  attendanceManagementVo.setLeaveType(leaveType);
                                  attendanceManagementVo.setLeaveStartDate(leaveStartDate);
                                  attendanceManagementVo.setLeaveEndDate(leaveEndDate);
                                  attendanceManagementVo.setReason(reason);
                                  attendanceManagementVo.setManageEmployeeId(manageEmployeeId);
                                  attendanceManagementVo.setTotalLeave(totalLeave);
                                  attendanceManagementVo.setLeaveStatus(leaveStatus);
                                  attendanceManagementVo.setEmployeeName(employeeName);

                                  AttendanceManagementVo attendanceManagementVo1=new AttendanceManagementVo();
                                  AttendanceManager attendanceManager=new AttendanceManager();
                                  attendanceManagementVo1=attendanceManager.insertLeaveData(attendanceManagementVo);
                                  attendanceManagementVo1=attendanceManager.getApproverId(attendanceManagementVo);
                                  String approverId=attendanceManagementVo1.getApproverId();
                                  String approverEmployeeName=attendanceManagementVo1.getApproverEmployeeName();
                                  LoginVo loginVo=new LoginVo();
                                  LoginManager loginManager=new LoginManager();
                                  loginVo.setEmpId(approverId);
                                  loginVo=loginManager.getEmailAddress(loginVo);
                                  String emailAddress=loginVo.getEmailAddress();
                                  String subject="LEAVE IS SUBMITTED FOR AN APPROVAL BY THE - " +employeeName;
                                  // String body = "Hi "+approverEmployeeName+" ," + "n" + "n" +
                                  // leaveType+" is Applied for "+totalLeave+" days by the " +employeeName+ "n" + "n" +
                                  // " Employee Name: " + employeeName +"n" +
                                  // " Applied Leave Type: " + leaveType +"n" +
                                  // " Total Days: " + totalLeave +"n" + "n" +
                                  // " To view Leave History, Please visit the employee poratal or copy and paste the below link in your browser: " + "n" +

                                  // " NOTE : This is an automated message. Please do not reply."+ "n" + "n" +

                                  Session session = null;

                                  MimeBodyPart messageBodyPart = new MimeBodyPart();
                                  MimeMessage message = new MimeMessage(session);
                                  Multipart multipart = new MimeMultipart();

                                  String htmlText = ("<div style="color:red;">BRIDGEYE</div>");
                                  messageBodyPart.setContent(htmlText, "text/html");

                                  loginVo.setHtmlBody(messageBodyPart);

                                  message.setContent(multipart);
                                  Transport.send(message);


                                  loginVo.setSubject(subject);
                                  // loginVo.setBody(body);
                                  loginVo.setEmailAddress(emailAddress);
                                  SSLEmail sSSEmail=new SSLEmail();
                                  sSSEmail.sendEmail(loginVo);
                                  return "success";
                                  }

                                  }





                                  share|improve this answer




























                                    0














                                    The "loginVo.htmlBody(messageBodyPart);" will contain the html formatted designed information, but in mail does not receive it.



                                    JAVA - STRUTS2



                                    package com.action;
                                    import javax.mail.Multipart;
                                    import javax.mail.Session;
                                    import javax.mail.Transport;
                                    import javax.mail.internet.MimeMessage;
                                    import javax.mail.internet.MimeMultipart;
                                    import com.opensymphony.xwork2.Action;
                                    import com.bo.LoginBo;
                                    import com.manager.AttendanceManager;
                                    import com.manager.LoginManager;
                                    import com.manager.SSLEmail;
                                    import com.vo.AttendanceManagementVo;
                                    import com.vo.LeaveManagementVo;
                                    import com.vo.LoginVo;
                                    import com.sun.corba.se.impl.protocol.giopmsgheaders.Message;
                                    import com.sun.xml.internal.messaging.saaj.packaging.mime.internet.MimeBodyPart;

                                    public class InsertApplyLeaveAction implements Action {
                                    private AttendanceManagementVo attendanceManagementVo;

                                    public AttendanceManagementVo getAttendanceManagementVo() {
                                    return attendanceManagementVo;
                                    }

                                    public void setAttendanceManagementVo(
                                    AttendanceManagementVo attendanceManagementVo) {
                                    this.attendanceManagementVo = attendanceManagementVo;
                                    }

                                    @Override
                                    public String execute() throws Exception {
                                    String empId=attendanceManagementVo.getEmpId();
                                    String leaveType=attendanceManagementVo.getLeaveType();
                                    String leaveStartDate=attendanceManagementVo.getLeaveStartDate();
                                    String leaveEndDate=attendanceManagementVo.getLeaveEndDate();
                                    String reason=attendanceManagementVo.getReason();
                                    String employeeName=attendanceManagementVo.getEmployeeName();
                                    String manageEmployeeId=empId;
                                    float totalLeave=attendanceManagementVo.getTotalLeave();
                                    String leaveStatus=attendanceManagementVo.getLeaveStatus();
                                    // String approverId=attendanceManagementVo.getApproverId();
                                    attendanceManagementVo.setEmpId(empId);
                                    attendanceManagementVo.setLeaveType(leaveType);
                                    attendanceManagementVo.setLeaveStartDate(leaveStartDate);
                                    attendanceManagementVo.setLeaveEndDate(leaveEndDate);
                                    attendanceManagementVo.setReason(reason);
                                    attendanceManagementVo.setManageEmployeeId(manageEmployeeId);
                                    attendanceManagementVo.setTotalLeave(totalLeave);
                                    attendanceManagementVo.setLeaveStatus(leaveStatus);
                                    attendanceManagementVo.setEmployeeName(employeeName);

                                    AttendanceManagementVo attendanceManagementVo1=new AttendanceManagementVo();
                                    AttendanceManager attendanceManager=new AttendanceManager();
                                    attendanceManagementVo1=attendanceManager.insertLeaveData(attendanceManagementVo);
                                    attendanceManagementVo1=attendanceManager.getApproverId(attendanceManagementVo);
                                    String approverId=attendanceManagementVo1.getApproverId();
                                    String approverEmployeeName=attendanceManagementVo1.getApproverEmployeeName();
                                    LoginVo loginVo=new LoginVo();
                                    LoginManager loginManager=new LoginManager();
                                    loginVo.setEmpId(approverId);
                                    loginVo=loginManager.getEmailAddress(loginVo);
                                    String emailAddress=loginVo.getEmailAddress();
                                    String subject="LEAVE IS SUBMITTED FOR AN APPROVAL BY THE - " +employeeName;
                                    // String body = "Hi "+approverEmployeeName+" ," + "n" + "n" +
                                    // leaveType+" is Applied for "+totalLeave+" days by the " +employeeName+ "n" + "n" +
                                    // " Employee Name: " + employeeName +"n" +
                                    // " Applied Leave Type: " + leaveType +"n" +
                                    // " Total Days: " + totalLeave +"n" + "n" +
                                    // " To view Leave History, Please visit the employee poratal or copy and paste the below link in your browser: " + "n" +

                                    // " NOTE : This is an automated message. Please do not reply."+ "n" + "n" +

                                    Session session = null;

                                    MimeBodyPart messageBodyPart = new MimeBodyPart();
                                    MimeMessage message = new MimeMessage(session);
                                    Multipart multipart = new MimeMultipart();

                                    String htmlText = ("<div style="color:red;">BRIDGEYE</div>");
                                    messageBodyPart.setContent(htmlText, "text/html");

                                    loginVo.setHtmlBody(messageBodyPart);

                                    message.setContent(multipart);
                                    Transport.send(message);


                                    loginVo.setSubject(subject);
                                    // loginVo.setBody(body);
                                    loginVo.setEmailAddress(emailAddress);
                                    SSLEmail sSSEmail=new SSLEmail();
                                    sSSEmail.sendEmail(loginVo);
                                    return "success";
                                    }

                                    }





                                    share|improve this answer


























                                      0












                                      0








                                      0







                                      The "loginVo.htmlBody(messageBodyPart);" will contain the html formatted designed information, but in mail does not receive it.



                                      JAVA - STRUTS2



                                      package com.action;
                                      import javax.mail.Multipart;
                                      import javax.mail.Session;
                                      import javax.mail.Transport;
                                      import javax.mail.internet.MimeMessage;
                                      import javax.mail.internet.MimeMultipart;
                                      import com.opensymphony.xwork2.Action;
                                      import com.bo.LoginBo;
                                      import com.manager.AttendanceManager;
                                      import com.manager.LoginManager;
                                      import com.manager.SSLEmail;
                                      import com.vo.AttendanceManagementVo;
                                      import com.vo.LeaveManagementVo;
                                      import com.vo.LoginVo;
                                      import com.sun.corba.se.impl.protocol.giopmsgheaders.Message;
                                      import com.sun.xml.internal.messaging.saaj.packaging.mime.internet.MimeBodyPart;

                                      public class InsertApplyLeaveAction implements Action {
                                      private AttendanceManagementVo attendanceManagementVo;

                                      public AttendanceManagementVo getAttendanceManagementVo() {
                                      return attendanceManagementVo;
                                      }

                                      public void setAttendanceManagementVo(
                                      AttendanceManagementVo attendanceManagementVo) {
                                      this.attendanceManagementVo = attendanceManagementVo;
                                      }

                                      @Override
                                      public String execute() throws Exception {
                                      String empId=attendanceManagementVo.getEmpId();
                                      String leaveType=attendanceManagementVo.getLeaveType();
                                      String leaveStartDate=attendanceManagementVo.getLeaveStartDate();
                                      String leaveEndDate=attendanceManagementVo.getLeaveEndDate();
                                      String reason=attendanceManagementVo.getReason();
                                      String employeeName=attendanceManagementVo.getEmployeeName();
                                      String manageEmployeeId=empId;
                                      float totalLeave=attendanceManagementVo.getTotalLeave();
                                      String leaveStatus=attendanceManagementVo.getLeaveStatus();
                                      // String approverId=attendanceManagementVo.getApproverId();
                                      attendanceManagementVo.setEmpId(empId);
                                      attendanceManagementVo.setLeaveType(leaveType);
                                      attendanceManagementVo.setLeaveStartDate(leaveStartDate);
                                      attendanceManagementVo.setLeaveEndDate(leaveEndDate);
                                      attendanceManagementVo.setReason(reason);
                                      attendanceManagementVo.setManageEmployeeId(manageEmployeeId);
                                      attendanceManagementVo.setTotalLeave(totalLeave);
                                      attendanceManagementVo.setLeaveStatus(leaveStatus);
                                      attendanceManagementVo.setEmployeeName(employeeName);

                                      AttendanceManagementVo attendanceManagementVo1=new AttendanceManagementVo();
                                      AttendanceManager attendanceManager=new AttendanceManager();
                                      attendanceManagementVo1=attendanceManager.insertLeaveData(attendanceManagementVo);
                                      attendanceManagementVo1=attendanceManager.getApproverId(attendanceManagementVo);
                                      String approverId=attendanceManagementVo1.getApproverId();
                                      String approverEmployeeName=attendanceManagementVo1.getApproverEmployeeName();
                                      LoginVo loginVo=new LoginVo();
                                      LoginManager loginManager=new LoginManager();
                                      loginVo.setEmpId(approverId);
                                      loginVo=loginManager.getEmailAddress(loginVo);
                                      String emailAddress=loginVo.getEmailAddress();
                                      String subject="LEAVE IS SUBMITTED FOR AN APPROVAL BY THE - " +employeeName;
                                      // String body = "Hi "+approverEmployeeName+" ," + "n" + "n" +
                                      // leaveType+" is Applied for "+totalLeave+" days by the " +employeeName+ "n" + "n" +
                                      // " Employee Name: " + employeeName +"n" +
                                      // " Applied Leave Type: " + leaveType +"n" +
                                      // " Total Days: " + totalLeave +"n" + "n" +
                                      // " To view Leave History, Please visit the employee poratal or copy and paste the below link in your browser: " + "n" +

                                      // " NOTE : This is an automated message. Please do not reply."+ "n" + "n" +

                                      Session session = null;

                                      MimeBodyPart messageBodyPart = new MimeBodyPart();
                                      MimeMessage message = new MimeMessage(session);
                                      Multipart multipart = new MimeMultipart();

                                      String htmlText = ("<div style="color:red;">BRIDGEYE</div>");
                                      messageBodyPart.setContent(htmlText, "text/html");

                                      loginVo.setHtmlBody(messageBodyPart);

                                      message.setContent(multipart);
                                      Transport.send(message);


                                      loginVo.setSubject(subject);
                                      // loginVo.setBody(body);
                                      loginVo.setEmailAddress(emailAddress);
                                      SSLEmail sSSEmail=new SSLEmail();
                                      sSSEmail.sendEmail(loginVo);
                                      return "success";
                                      }

                                      }





                                      share|improve this answer













                                      The "loginVo.htmlBody(messageBodyPart);" will contain the html formatted designed information, but in mail does not receive it.



                                      JAVA - STRUTS2



                                      package com.action;
                                      import javax.mail.Multipart;
                                      import javax.mail.Session;
                                      import javax.mail.Transport;
                                      import javax.mail.internet.MimeMessage;
                                      import javax.mail.internet.MimeMultipart;
                                      import com.opensymphony.xwork2.Action;
                                      import com.bo.LoginBo;
                                      import com.manager.AttendanceManager;
                                      import com.manager.LoginManager;
                                      import com.manager.SSLEmail;
                                      import com.vo.AttendanceManagementVo;
                                      import com.vo.LeaveManagementVo;
                                      import com.vo.LoginVo;
                                      import com.sun.corba.se.impl.protocol.giopmsgheaders.Message;
                                      import com.sun.xml.internal.messaging.saaj.packaging.mime.internet.MimeBodyPart;

                                      public class InsertApplyLeaveAction implements Action {
                                      private AttendanceManagementVo attendanceManagementVo;

                                      public AttendanceManagementVo getAttendanceManagementVo() {
                                      return attendanceManagementVo;
                                      }

                                      public void setAttendanceManagementVo(
                                      AttendanceManagementVo attendanceManagementVo) {
                                      this.attendanceManagementVo = attendanceManagementVo;
                                      }

                                      @Override
                                      public String execute() throws Exception {
                                      String empId=attendanceManagementVo.getEmpId();
                                      String leaveType=attendanceManagementVo.getLeaveType();
                                      String leaveStartDate=attendanceManagementVo.getLeaveStartDate();
                                      String leaveEndDate=attendanceManagementVo.getLeaveEndDate();
                                      String reason=attendanceManagementVo.getReason();
                                      String employeeName=attendanceManagementVo.getEmployeeName();
                                      String manageEmployeeId=empId;
                                      float totalLeave=attendanceManagementVo.getTotalLeave();
                                      String leaveStatus=attendanceManagementVo.getLeaveStatus();
                                      // String approverId=attendanceManagementVo.getApproverId();
                                      attendanceManagementVo.setEmpId(empId);
                                      attendanceManagementVo.setLeaveType(leaveType);
                                      attendanceManagementVo.setLeaveStartDate(leaveStartDate);
                                      attendanceManagementVo.setLeaveEndDate(leaveEndDate);
                                      attendanceManagementVo.setReason(reason);
                                      attendanceManagementVo.setManageEmployeeId(manageEmployeeId);
                                      attendanceManagementVo.setTotalLeave(totalLeave);
                                      attendanceManagementVo.setLeaveStatus(leaveStatus);
                                      attendanceManagementVo.setEmployeeName(employeeName);

                                      AttendanceManagementVo attendanceManagementVo1=new AttendanceManagementVo();
                                      AttendanceManager attendanceManager=new AttendanceManager();
                                      attendanceManagementVo1=attendanceManager.insertLeaveData(attendanceManagementVo);
                                      attendanceManagementVo1=attendanceManager.getApproverId(attendanceManagementVo);
                                      String approverId=attendanceManagementVo1.getApproverId();
                                      String approverEmployeeName=attendanceManagementVo1.getApproverEmployeeName();
                                      LoginVo loginVo=new LoginVo();
                                      LoginManager loginManager=new LoginManager();
                                      loginVo.setEmpId(approverId);
                                      loginVo=loginManager.getEmailAddress(loginVo);
                                      String emailAddress=loginVo.getEmailAddress();
                                      String subject="LEAVE IS SUBMITTED FOR AN APPROVAL BY THE - " +employeeName;
                                      // String body = "Hi "+approverEmployeeName+" ," + "n" + "n" +
                                      // leaveType+" is Applied for "+totalLeave+" days by the " +employeeName+ "n" + "n" +
                                      // " Employee Name: " + employeeName +"n" +
                                      // " Applied Leave Type: " + leaveType +"n" +
                                      // " Total Days: " + totalLeave +"n" + "n" +
                                      // " To view Leave History, Please visit the employee poratal or copy and paste the below link in your browser: " + "n" +

                                      // " NOTE : This is an automated message. Please do not reply."+ "n" + "n" +

                                      Session session = null;

                                      MimeBodyPart messageBodyPart = new MimeBodyPart();
                                      MimeMessage message = new MimeMessage(session);
                                      Multipart multipart = new MimeMultipart();

                                      String htmlText = ("<div style="color:red;">BRIDGEYE</div>");
                                      messageBodyPart.setContent(htmlText, "text/html");

                                      loginVo.setHtmlBody(messageBodyPart);

                                      message.setContent(multipart);
                                      Transport.send(message);


                                      loginVo.setSubject(subject);
                                      // loginVo.setBody(body);
                                      loginVo.setEmailAddress(emailAddress);
                                      SSLEmail sSSEmail=new SSLEmail();
                                      sSSEmail.sendEmail(loginVo);
                                      return "success";
                                      }

                                      }






                                      share|improve this answer












                                      share|improve this answer



                                      share|improve this answer










                                      answered Jul 9 '14 at 11:33









                                      Pradap Adwani APradap Adwani A

                                      12




                                      12























                                          0














                                          I found this way not sure it works for all the CSS primitives



                                          By setting the header property "Content-Type" to "text/html"



                                          mimeMessage.setHeader("Content-Type", "text/html");


                                          now I can do stuff like



                                          mimeMessage.setHeader("Content-Type", "text/html");

                                          mimeMessage.setText ("`<html><body><h1 style ="color:blue;">My first Header<h1></body></html>`")


                                          Regards






                                          share|improve this answer






























                                            0














                                            I found this way not sure it works for all the CSS primitives



                                            By setting the header property "Content-Type" to "text/html"



                                            mimeMessage.setHeader("Content-Type", "text/html");


                                            now I can do stuff like



                                            mimeMessage.setHeader("Content-Type", "text/html");

                                            mimeMessage.setText ("`<html><body><h1 style ="color:blue;">My first Header<h1></body></html>`")


                                            Regards






                                            share|improve this answer




























                                              0












                                              0








                                              0







                                              I found this way not sure it works for all the CSS primitives



                                              By setting the header property "Content-Type" to "text/html"



                                              mimeMessage.setHeader("Content-Type", "text/html");


                                              now I can do stuff like



                                              mimeMessage.setHeader("Content-Type", "text/html");

                                              mimeMessage.setText ("`<html><body><h1 style ="color:blue;">My first Header<h1></body></html>`")


                                              Regards






                                              share|improve this answer















                                              I found this way not sure it works for all the CSS primitives



                                              By setting the header property "Content-Type" to "text/html"



                                              mimeMessage.setHeader("Content-Type", "text/html");


                                              now I can do stuff like



                                              mimeMessage.setHeader("Content-Type", "text/html");

                                              mimeMessage.setText ("`<html><body><h1 style ="color:blue;">My first Header<h1></body></html>`")


                                              Regards







                                              share|improve this answer














                                              share|improve this answer



                                              share|improve this answer








                                              edited Sep 4 '17 at 20:53









                                              luk2302

                                              33.5k176893




                                              33.5k176893










                                              answered Sep 4 '17 at 20:35









                                              BalintBalint

                                              10114




                                              10114






























                                                  draft saved

                                                  draft discarded




















































                                                  Thanks for contributing an answer to Stack Overflow!


                                                  • Please be sure to answer the question. Provide details and share your research!

                                                  But avoid



                                                  • Asking for help, clarification, or responding to other answers.

                                                  • Making statements based on opinion; back them up with references or personal experience.


                                                  To learn more, see our tips on writing great answers.




                                                  draft saved


                                                  draft discarded














                                                  StackExchange.ready(
                                                  function () {
                                                  StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f5068827%2fhow-do-i-send-an-html-email%23new-answer', 'question_page');
                                                  }
                                                  );

                                                  Post as a guest















                                                  Required, but never shown





















































                                                  Required, but never shown














                                                  Required, but never shown












                                                  Required, but never shown







                                                  Required, but never shown

































                                                  Required, but never shown














                                                  Required, but never shown












                                                  Required, but never shown







                                                  Required, but never shown







                                                  Popular posts from this blog

                                                  If I really need a card on my start hand, how many mulligans make sense? [duplicate]

                                                  Alcedinidae

                                                  Can an atomic nucleus contain both particles and antiparticles? [duplicate]