Here is an example of sending an HTML message via javaMail :

  Properties props = new Properties();
  props.put("mail.smtp.host", SMTPHost);
  Session session = Session.getDefaultInstance(props,
   new Authenticator() {
    protected PasswordAuthentication getPasswordAuthentication() {
     return new PasswordAuthentication(SMTPLogin, SMTPPassword);
    }
   }
  );

  MimeMessage message = new MimeMessage(session);

  message.setFrom(eMailThis);
  message.addRecipient(Message.RecipientType.TO, eMailMarseille);
  message.addRecipient(Message.RecipientType.CC, eMailMarketing);
  message.setSubject("[contactez-nous]");
  StringBuffer htmlText = new StringBuffer();
  htmlText.append("<html><body bgcolor='#FFFFFF' text='#4F177F'>\n");
  htmlText.append("<table border='0' cellspacing='1' cellpading='2'>\n");

  htmlText.append("<tr><td bgcolor='#00A9BC'
align='right'><b>&nbsp;nom&nbsp;:&nbsp;</b></td>\n");
  htmlText.append("<td bgcolor='#FFFFFF'>&nbsp;\n");
  htmlText.append(user.getNom());
  htmlText.append("</td></tr>\n");

  htmlText.append("<tr><td bgcolor='#00A9BC'
align='right'><b>&nbsp;e-Mail&nbsp;:&nbsp;</b></td>\n");
  htmlText.append("<td bgcolor='#FFFFFF'>&nbsp;\n");
  htmlText.append("<a href='mailto:";);
  htmlText.append(user.geteMail());
  htmlText.append("'>");
  htmlText.append(user.geteMail());
  htmlText.append("</a>");
  htmlText.append("</td></tr>\n");

  htmlText.append("<tr><td colspan='2'>&nbsp;");
  htmlText.append("</td></tr>");
  htmlText.append("<tr><td colspan='2' bgcolor='#FFFFFF'>");
  htmlText.append(remarque);
  htmlText.append("</td></tr>");
  htmlText.append("</table><br>\n");
  htmlText.append("</body></html>");

  message.setContent(htmlText.toString(), "text/html");

  Transport.send(message);
 }
 catch (MessagingException me) {
 }

Nico

----- Original Message -----
From: "Struts Newsgroup" <@[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, July 04, 2002 12:55 AM
Subject: [Off Topic] Sending HTML e-mail via servlet


> Subject: [Off Topic] Sending HTML e-mail via servlet
> From: "Matt Raible" <[EMAIL PROTECTED]>
>  ===
> Does any have any links, examples, or tips for sending an HTML-based
message
> in a servlet?
>
> Thanks,
>
> Matt
>
>
>
> --
> To unsubscribe, e-mail:
<mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail:
<mailto:[EMAIL PROTECTED]>


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to