简体   繁体   中英

how can we sent html content by java gwt mail api

i peek in many mail api like gmail etc. they send html content by mail api ,almost a form with some widgets. I am also trying to do that but whenever in try this with html content , its giving me error

  String to="xyz@gmail.com";//change accordingly


  Properties props = new Properties();
  props.put("mail.smtp.host", "smtp.gmail.com");
  props.put("mail.smtp.socketFactory.port", "465");
  props.put("mail.smtp.socketFactory.class",
            "javax.net.ssl.SSLSocketFactory");
  props.put("mail.smtp.auth", "true");
  props.put("mail.smtp.port", "465");

  Session session = Session.getDefaultInstance(props,
   new javax.mail.Authenticator() {
   protected PasswordAuthentication getPasswordAuthentication() {
   return new PasswordAuthentication("xyz.com","xyz");
   }
  });


  try {
   MimeMessage message = new MimeMessage(session);
   message.setFrom(new InternetAddress("hellofacebook180@gmail.com"));
   message.addRecipient(Message.RecipientType.TO,new InternetAddress(to));
   message.setSubject(input);
   message.setContent("<h1>sending html mail check</h1>","text/html" );;


   Transport.send(message);

   System.out.println("message sent successfully");

  } catch (MessagingException e) {throw new RuntimeException(e);}

  return "massage sent";

please help how can I sent Html content with mail api

Email clients (Gmail, etc.) do not allow external CSS files. There is nothing you can do about it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM