Send HTML Email In JSP#

Paste the code below into a jsp, place mail.jar and activation.jar below into the lib folder of a war. Upload the war and run the jsp. the war is also included below for clarity.

<%@ page import="javax.mail.*,javax.mail.internet.*,javax.mail.internet.MimeMessage.RecipientType,java.io.*,java.util.Properties" %>

<%

Properties props = new Properties();
props.put("mail.smtp.host", "localhost");
Session mailsession = Session.getDefaultInstance(props, null);
Message msg = new MimeMessage(mailsession);
//set the from and to address
InternetAddress addressFrom;

try {
	addressFrom = new InternetAddress("xxx@hyve.com");
	msg.setFrom(addressFrom);
	InternetAddress addressTo = new InternetAddress("xxx@hyve.com");
	msg.setRecipient(RecipientType.TO,addressTo);
	msg.setSubject("subject");
	msg.setContent("<b>HELLO</a>", "text/html");
	Transport.send(msg);
} catch (Exception e) {
	e.printStackTrace();
}

%>

Back to JSP

Add new attachment

Only authorized users are allowed to upload new attachments.
« This page (revision-2) was last changed on 24-May-2017 15:30 by Hyve Support
G’day (anonymous guest) My Prefs
  • View Page Source
  • This clear IPSec security association,
    clear ipsec sa peer X.X.X.X
    

All Pages

Page views: 2414

Private Tomcat

Linux

MySQL

Email

SQL Server

ASP

JSP

C#

Web Mail

Windows Plesk

Linux Plesk

PHP

Gaming

ASP.NET

Persits ASPUpload

Wiki Help

Referring Pages:
...nobody

JSPWiki v2.8.1