Digital Developer Conference: a FREE half-day online conference focused on AI & Cloud – North America: Nov 2 – India: Nov 9 – Europe: Nov 14 – Asia Nov 23 Register now

Close outline
  • United States
IBM?
  • Site map
IBM?
  • Marketplace

  • Close
    Search
  • Sign in
    • Sign in
    • Register
  • IBM Navigation
IBM Developer Answers
  • Spaces
    • Blockchain
    • IBM Cloud platform
    • Internet of Things
    • Predictive Analytics
    • Watson
    • See all spaces
  • Tags
  • Users
  • Badges
  • FAQ
  • Help
Close

Name

Community

  • Learn
  • Develop
  • Connect

Discover IBM

  • ConnectMarketplace
  • Products
  • Services
  • Industries
  • Careers
  • Partners
  • Support
10.190.13.195

Refine your search by using the following advanced search options.

Criteria Usage
Questions with keyword1 or keyword2 keyword1 keyword2
Questions with a mandatory word, e.g. keyword2 keyword1 +keyword2
Questions excluding a word, e.g. keyword2 keyword1 -keyword2
Questions with keyword(s) and a specific tag keyword1 [tag1]
Questions with keyword(s) and either of two or more specific tags keyword1 [tag1] [tag2]
To search for all posts by a user or all posts with a specific tag, start typing and choose from the suggestion list. Do not use a plus or minus sign with a tag, e.g., +[tag1].
  • Ask a question

How to send plain text or HTML encoded email using a JSP with WCM?

2000002RXD gravatar image
Question by rickett  (14292) | Apr 16, 2015 at 02:52 PM portaldigexpwcmemailhtmljspencoded

How to send plain text or HTML-encoded email using a JSP with WCM?

People who like this

  0
Comment
10 |3000 characters needed characters left characters exceeded
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster

1 reply

  • Sort: 
2000002RXD gravatar image
Accepted answer

Answer by rickett (14292) | Apr 16, 2015 at 02:59 PM

The jsp file is the key in this solution/approach. In this case the native java classes in the WAS JVM are used. The html form is included in this technote in case you are more comfortable with the html forms, but you could code the input fields in the jsp itself without requiring the html form.

DISCLAIMER OF WARRANTIES:
This sample code is provided to you solely for the purpose of assisting
you in the development of your applications.
The code is provided "AS IS", without warranty of any kind. IBM shall
not be liable for any damages arising out of your use of the sample code, even if they have been advised of the possibility of such damages.

Create an html component titled "MailHTMLForm" with these contents:

 <HTML>
 <BODY>
 <FORM METHOD=POST ACTION="wcmmail.jsp">
 Enter your name:          <INPUT TYPE=TEXT NAME=username SIZE=20><BR>
 Enter your email address: <INPUT TYPE=TEXT NAME=email SIZE=20><BR>
 Enter comments:           <INPUT TYPE=TEXT NAME=content SIZE=50><BR>
 <P>
 <INPUT TYPE=SUBMIT VALUE="Send email">
 </FORM>
 </BODY>
 </HTML>


Create a jsp titled "wcmmail.jsp" and place in directory \installedApps\index\wcm.ear\ilwwcm.war\jsp\html

Here are the jsp contents:

 //START JSP CONTENTS
 <%@ page import="java.io.*, java.net.*, javax.mail.*, javax.mail.internet.*, java.util.Properties" %>
 <HTML>
 <BODY>
 <%
  
  String email = request.getParameter( "email" );
  String content = request.getParameter( "content" );
 %>
 <% if ( email == null || email.equals( "" )) { %>
 Please press back button and enter an email address.
 <% } else {
 
      Properties emailProperties = new Properties();
 
      emailProperties.setProperty("mail.transport.protocol", "smtp");
 
      emailProperties.setProperty("mail.host", "myMailServer.mycompany.com");
 
      emailProperties.setProperty("mail.from", email);
 
      Session mailSession = Session.getDefaultInstance(emailProperties, null);
 
      Transport transport = mailSession.getTransport();
 
      MimeMessage message = new MimeMessage(mailSession);
 
      message.setSubject("WCM Javamail");
 
      message.setContent( content , "text/html");
 
      message.addRecipient(Message.RecipientType.TO, new InternetAddress(email));
 
      message.setFrom(new InternetAddress(email));
 
      transport.connect();
      transport.sendMessage(message, message.getRecipients(Message.RecipientType.TO));
      transport.close();
 
 %>
 
 <br/>
 This name will be registered <%= request.getParameter( "username" ) %>
 <br/>
 
 Your email has been sent to <%= email %> with this timestamp <%= new java.util.Date() %>  
 <% } %>
 </BODY>
 </HTML>
 //END JSP CONTENTS

Modify the jsp for your email server/environment. Create a WCM JSP component titled "SendMailJSPComponent" with this path: /jsp/html/wcmmail.jsp

Preview the html component MailHTMLForm using a url similar to this:

http://myPortalServer.myCompany.com:10040/wps/wcm/jsp/html/emailform.htm

Fill in the fields, For example, enter this in the "content" field:

Please register

Press "Send email" > email arrives at destination in HTML encoded format.

Comment

People who like this

  0   Share
10 |3000 characters needed characters left characters exceeded
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster

Follow this question

24 people are following this question.

Answers

Answers & comments

Related questions

Can I create a link to a Portal page in WCM content that checks user access? 1 Answer

How can I send an email from a contact form in Web Content Manager? 1 Answer

IWKPW1015X: E-mail action was unable to add recipients. When configuring WCM for workflow alert emails 1 Answer

Is there a good example of WCM JSP Component usage? 3 Answers

How to send an email using the WCM Mail Module ? 1 Answer

  • Contact
  • Privacy
  • IBM Developer Terms of use
  • Accessibility
  • Report Abuse
  • Cookie Preferences

Powered by AnswerHub

Authentication check. Please ignore.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • API Connect
  • Analytic Hybrid Cloud Core
  • Application Performance Management
  • Appsecdev
  • BPM
  • Blockchain
  • Business Transaction Intelligence
  • CAPI
  • CAPI SNAP
  • CICS
  • Cloud Analytics
  • Cloud Automation
  • Cloud Object Storage
  • Cloud marketplace
  • Collaboration
  • Content Services (ECM)
  • Continuous Testing
  • Courses
  • Customer Experience Analytics
  • DB2 LUW
  • Data and AI
  • DataPower
  • Decision Optimization
  • DevOps Build
  • DevOps Services
  • Developers IBM MX
  • Digital Commerce
  • Digital Experience
  • Finance
  • Global Entrepreneur Program
  • Hadoop
  • Hybrid Cloud Core
  • Hyper Protect
  • IBM Cloud platform
  • IBM Design
  • IBM Forms Experience Builder
  • IBM Maximo Developer
  • IBM StoredIQ
  • IBM StoredIQ-Cartridges
  • IIDR
  • ITOA
  • InformationServer
  • Integration Bus
  • Internet of Things
  • Kenexa
  • Linux on Power
  • LinuxONE
  • MDM
  • Mainframe
  • Messaging
  • Node.js
  • ODM
  • Open
  • PartnerWorld Developer Support
  • PowerAI
  • PowerVC
  • Predictive Analytics
  • Product Insights
  • PureData for Analytics
  • Push
  • QRadar App Development
  • Run Book Automation
  • Search Insights
  • Security Core
  • Storage
  • Storage Core
  • Streamsdev
  • Supply Chain Business Network
  • Supply Chain Insights
  • Swift
  • UBX Capture
  • Universal Behavior Exchange
  • UrbanCode
  • WASdev
  • WSRR
  • Watson
  • Watson Campaign Automation
  • Watson Content Hub
  • Watson Marketing Insights
  • dW Answers Help
  • dW Premium
  • developerWorks Sandbox
  • developerWorks Team
  • Watson Health
  • More
  • Tags
  • Questions
  • Users
  • Badges