Composing mail from email web application using jsp and custom tags

here is the send.jsp file
<%@ page language="java" %>
<%@ page errorPage="errorpage.jsp" %>
<%@ taglib uri="http://java.sun.com/products/javamail/demo/webapp"
prefix="javamail" %>
<html>
<head>
     <title>JavaMail send</title>
</head>
<body bgcolor="white">
hi
<javamail:sendmail
recipients="<%= request.getParameter(\"to\") %>"
sender="<%= request.getParameter(\"from\") %>"
subject="<%= request.getParameter(\"subject\") %>">
<%= request.getParameter("text") %>
</javamail:sendmail>
<h1>Message sent successfully</h1>
</body>
</html>
Here is the java file i.e used to refer to this custom tag
package taglib;
import java.util.*;
import java.net.*;
import javax.mail.*;
import javax.mail.Authenticator;
import javax.mail.internet.*;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
* Custom tag for sending messages.
public class SendTag extends BodyTagSupport {
private String body;
private String cc;
private String host;
private String recipients;
private String sender;
private String subject;
* host attribute setter method.
public void setHost(String host) {
this.host = host;
System.out.println("Host is : " +host);
* recipient attribute setter method.
public void setRecipients(String recipients) {
this.recipients = recipients;
System.out.println("recipients is " +recipients );
* sender attribute setter method.
public void setSender(String sender) {
this.sender = sender;
System.out.println("Sender is : " +sender);
* cc attribute setter method.
public void setCc(String cc) {
this.cc = cc;
* subject attribute setter method.
public void setSubject(String subject) {
this.subject = subject;
System.out.println("subject is : " +subject);
* Method for processing the end of the tag.
public int doEndTag() throws JspException {
     System.out.println(" ** In do end tag");
Properties props = System.getProperties();
try {
if (host != null)
props.put("mail.smtp.host", host);
else if (props.getProperty("mail.smtp.host") == null)
props.put("mail.smtp.host", InetAddress.getLocalHost().
getHostName());
} catch (Exception ex) {
throw new JspException(ex.getMessage());
Session session = Session.getDefaultInstance(props,null);
     Message msg = new MimeMessage(session);
     InternetAddress[] toAddrs = null, ccAddrs = null;
try {
     if (recipients != null) {
     toAddrs = InternetAddress.parse(recipients, false);
     msg.setRecipients(Message.RecipientType.TO, toAddrs);
     } else
     throw new JspException("No recipient address specified");
if (sender != null)
msg.setFrom(new InternetAddress(sender));
else
throw new JspException("No sender address specified");
     if (cc != null) {
ccAddrs = InternetAddress.parse(cc, false);
     msg.setRecipients(Message.RecipientType.CC, ccAddrs);
     if (subject != null)
     msg.setSubject(subject);
     if ((body = getBodyContent().getString()) != null)
     msg.setText(body);
else
msg.setText("");
Transport.send(msg);
} catch (Exception ex) {
throw new JspException(ex.getMessage());
return(EVAL_PAGE);
all the entries in taglib.tld and web.xml are correct.
It is one of the article given at this url:
http://java.sun.com/developer/technicalArticles/javaserverpages/emailapps/

First, you should not take copyrighted code and post it without a copyright.
The code you posted is copyright Sun Microsystems.
Second, why did you post it? Did you have a question?

Similar Messages

  • Any good books on web application using JSP/servlet?

    Does anyone know good books on how-to build enterprise web application using JSP/servlet? Aside from the book "Head First JSP/Servlet". Development using Netbeans is more preferrable.

    801264 wrote:
    What about the free web server? JBoss or Glassfish or something else? I prefer web/application server that is fully compatible with JEE6 (unlike Tomcat that can't handle EJB). thanksI'm a JBoss user myself, so naturally I would advise that to you if I were ignorant. I'm not however, so in stead I'll tell you to investigate yourself and see which one you prefer. Nobody is going to tell you which one to use as there is no such thing as a 'better' or 'best' server. Just different servers each with different issues.
    And the community edition of JBoss has had many issues in the past (because Red Hat of course wants to advise you to go to the enterprise platform which ain't cheap), but JBoss 5.1 was a rock solid piece of software that I have had zero problems with (after reading the odd forum or two). JBoss 6 builds on top of JBoss 5.1 and provides the full JEE6 web profile; this means it does NOT provide a certified 'full' JEE6 stack yet. This means nothing however as all the services you may need in an enterprise application are already there.
    BTW: for simple servlet programming, don't neglect Apache Tomcat. Its a lightweight server that just works.

  • Building a best practice web application using ColdFusion and Jave EE

    I've been tasked with rewriting a software using ColdFusion.  I cannot seem to find a lot of information on best practice development in ColdFusion.  I am an experience Java developer who has never used ColdFusion before.  I want to build this application using a synergy of ColdFusion and Java EE technologies.  Can someone recommend me a book that outlines how to developer in ColdFusion?  Ideally this book assumes the reader is an experienced developer with no exposure to ColdFusion.  Ideally the methods outlined in the book are still "best practice" methods.

    jaisheela wrote:
    Hello Friends,
    I am also in the same situation.
    I am a building a new web application using JSF and AJAX.
    Requirement is I need to use IBM version of DOJO and JSF but I need to develop the whole application using Eclipse 3.3,2 and Tomcat 5.5.
    With IBM version of DOJO and JSF, will Eclipse and Tomcat help to speed up the development or do you suggest me to go for Rational Application Developer and WebSphere Application Server.
    If I need to go with RAD and WAS, then I am new to RAD and WAS, is it easy to use RAD and WAS for this kind of application and implement web applicaiton fast.
    Any feedback will be great help.Those don't sound like requirements of the system to me. They sound more like someone wants to improve their CV/resume
    From what I've read recently, if it's just fast you want, look at Ruby on Rails

  • Buling a new Web Application using JSF and Ajax.

    Hello Group,
    I am a building a new web application using JSF and AJAX. Planning to use Myfaces Tomahawk, Dojo for Ajax, Hibernate, Spring,Eclipse IDE and Jetty Server.Can some one please suggest me will this be a right one for
    building complex UI and will it support for using the jsf features and would like to know any other free open
    source framework, ide, tools which support the best way for an agile project..?. There is restriction like i have to use java1.4

    jaisheela wrote:
    Hello Friends,
    I am also in the same situation.
    I am a building a new web application using JSF and AJAX.
    Requirement is I need to use IBM version of DOJO and JSF but I need to develop the whole application using Eclipse 3.3,2 and Tomcat 5.5.
    With IBM version of DOJO and JSF, will Eclipse and Tomcat help to speed up the development or do you suggest me to go for Rational Application Developer and WebSphere Application Server.
    If I need to go with RAD and WAS, then I am new to RAD and WAS, is it easy to use RAD and WAS for this kind of application and implement web applicaiton fast.
    Any feedback will be great help.Those don't sound like requirements of the system to me. They sound more like someone wants to improve their CV/resume
    From what I've read recently, if it's just fast you want, look at Ruby on Rails

  • How to fecth the contents of a mail from the server by using jsp

    hi
    Can any body tell me how to fetch the contents of mail from the server by using javamail api...please send me code if some one have
    bye.

    hi
    Can any body tell me how to fetch the contents of mail from the server by using javamail api...please send me code if some one have
    bye.

  • Standards in a web application with JSP and J2EE

    Hello!
    Can anyone to point me to a tutorial or an URL that contains standards for an web application with jsp(including tag libs), beans and servlets.
    Thanks
    Catalin

    on the left side of this page...there are links "Documenation", "Tutorials", "Code Samples", pick your choice...there are alot of tutorials, try some or try them all :)

  • Consuming a Web Service using JSP and servlet

    I have created a Web Service in Netbeans IDE 5.5. I developed a JSP to provide input to the Web Service, and a servlet that will pass the input to the web service through a request and outputs the result.
    I am getting the following error:
    HTTP Status 500 -
    type Exception report
    message
    description The server encountered an internal error () that prevented it from fulfilling this request.
    exception
    javax.servlet.ServletException: Servlet.init() for servlet TestServlet threw exception
    root cause
    java.lang.RuntimeException: WEB5002: Exception in handleBeforeEvent.
    root cause
    com.sun.enterprise.InjectionException: Exception attempting to inject Env-Prop: test.org.TestServlet/service@Field-Injectable Resource. Class name = test.org.TestServlet Field name=[email protected]@@@ into class test.org.TestServlet
    root cause
    javax.naming.NamingException [Root exception is java.lang.reflect.InvocationTargetException]
    root cause
    java.lang.reflect.InvocationTargetException
    root cause
    javax.xml.ws.WebServiceException: java.io.FileNotFoundException: http://localhost:8080/TestWebApplication/TestWSService?wsdl
    root cause
    java.io.FileNotFoundException: http://localhost:8080/TestWebApplication/TestWSService?wsdl
    note The full stack traces of the exception and its root causes are available in the Sun Java System Application Server Platform Edition 9.0_01 logs.
    Any hints???

    You probably should post to either the NetBeans website mailing list, or the Sun forum that supports the Sun Application Server, as the error is the result of a configuration error of one or both of these products. A file can't be found:
    java.io.FileNotFoundException: http://localhost:8080/TestWebApplication/TestWSService?wsdl
    note The full stack traces of the exception and its root causes are available in the Sun Java System Application Server Platform Edition 9.0_01 logs.
    These forums are for support of the Java language.

  • Regarding SMS application using jsp

    Hi Friends,
    I want to develop an application for sending and receiving sms from pc to mobile using jsp and servlets.I am new to it.can anyone guide me how to develop that application.
    Thanks and Regards,
    V.S.Ravi Kiran Balusu.

    The Java Messaging Service is middleware for exchanging messages between programs and such, not text messages to cell phones.
    You can send text messages to cellphones via email using carrier-specific addresses.
    [http://www.tech-recipes.com/rx/939/sms_email_cingular_nextel_sprint_tmobile_verizon_virgin/|http://www.tech-recipes.com/rx/939/sms_email_cingular_nextel_sprint_tmobile_verizon_virgin/]

  • How can I develop a web application using EJB design pattern?

    I have searched over the web and found quite a lot of tutorials on how to use the EJB design pattern.
    I know that there will be a home interface, EJB object interface and a SessionBean.
    But the tutorials often only cover a single class, this made me unable to get a complete picture of how EJB design pattern can be implemented into a whole system.
    I am now required to devleop an online shopping web application using EJB and JSP page.
    I think I will need to create a lot of classes: Member, ShoppingCart, Product...etc.
    What I want to ask is that, do I need to create a home interface, EJB object interface and a SessionBean for each of these classes?
    I really need some ideas on how to develop this system using EJB + JSP pages.
    Many thanks to you all.

    For every EJB that you want to create, you will need to code a home and remote interface and a bean class.
    You could start getting your ideas here
    http://www.theserverside.com/books/wiley/masteringEJB/
    http://www.coreservlets.com

  • JSP with Custom tags error during verify.

    Hi, i am new to JSP and Custom tag Library. The tools that i am using to deploy is "Sun Deploy Tool 8.2" with Sun Application Server. When i try to verify my JSP page i get this error message
    tests.web.AllJSPsMustBeCompilable . I guess there is nothing wrong for my code, will it be path problem, because
    i already check that i had included all the path that i need. Any idea what might cause this problem? Thank You.
    Assertion:All the JSPs that are bundled inside a web application must be compilable using a J2EE compliant JSP compiler that does not have any proprietary or optional features in it.
    For [ /tag/tag.war ]
    Error: Some JSPs bundled inside [ tag ] could not be compiled. See details below.
    org.apache.jasper.JasperException: Unable to compile class for JSP
    An error occurred at line: 12 in the jsp file: /currentTime.jsp
    Here are my class file :
    Custom lib java Class timetag.java
    import javax.servlet.jsp.tagext.*;
    import javax.servlet.jsp.*;
    import java.text.SimpleDateFormat;
    public class timetag extends TagSupport{
         public int doEndTag() throws JspException
              SimpleDateFormat sdf;
              sdf = new SimpleDateFormat("HH:mm:ss");
              String time = sdf.format(new java.util.Date());
              try {
                   pageContext.getOut().print(time);
              }catch(Exception ex)
                   throw new JspException(ex.toString());
              return EVAL_PAGE;
    Tag file *.tld : examplesTag.tld
    <?xml version="1.0" encoding="ISO-8859-1" ?>
    <taglib xmlns="http://java.sun.com/xml/ns/j2ee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"
    version="2.0">
    <tlib-version>1.0</tlib-version>
    <jsp-version>2.0</jsp-version>
    <short-name>ExamplesTags</short-name>
    <description>A set of example tag handlers.</description>
    <tag>
    <name>time</name>
    <tag-class>timetag</tag-class>
    </tag>
    </taglib>
    JSP File : currentTime.jsp
    <?xml version="1.0" encoding="ISO-8859-1" ?>
    <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <%@ taglib prefix="examples" uri="/WEB-INF/examplesTags.tld" %>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
    <title>Insert title here</title>
    </head>
    <body>
    <examples:time /> //If i remove this it will be fine.
    </body>
    </html>

    I am sorry for the double post because the format mess up..Please ignore this POST..Apologies again..Thanks

  • Is it posssible to lunch one application from the client system using JSP

    Is it possible to Lunch one application from the client system using JSP or Servlet .If it is possible then how can we do that ?
    Thanks in advance
    Sil

    If its a java application - yes. You can use jnlp and web start.
    ram.

  • Capture an image using the web camera from a web application

    Hi All,
    Could anyone please share the steps what have to be followed for capture an image using the web camera from a web application.
    I have a similar requirement like this,
    1) Detect the Webcam on the users machine from the web application.(To be more clear when the user clicks on 'Add Photo' tool from the web application)
    2) When the user confirms to save, save the Image in users machine at some temporary location with some unique file name.
    3) Upload the Image to the server from the temporary location.
    Please share the details like, what can be used and how it can be used etc...
    Thanks,
    Suman

    1) Detect the Webcam on the users machine from the web application.(To be more clear when the user clicks on 'Add Photo' tool from the web application)There's not really any good way to do this with JMF. You'd have to somehow create a JMF web-start application that will install the native JMF binaries, and then kick off the capture device scanning code from the application, and then scan through the list of devices found to get the MediaLocator of the web cam.
    2) When the user confirms to save, save the Image in users machine at some temporary location with some unique file name.You'd probably be displaying a "preview" window and then you'd just want to capture the image. There are a handful of ways you could capture the image, but it really depends on your situation.
    3) Upload the Image to the server from the temporary location.You can find out how to do this on google.
    All things told, this application is probably more suited to be a FMJ (Freedom for Media in Java) application than a JMF application. JMF relies on native code to capture from the web cams, whereas FMJ does not.
    Alternately, you might want to look into Adobe Flex for this particular application.

  • Have a question I do not use mail in my computer I use yahoo and I have all these emails and selected all and then delete then delete trash and they always come back how do I stop these old email in apple mail? I never send anything from there but I have

    have a question I do not use mail in my computer I use yahoo and I have all these emails and selected all and then delete then delete trash and they always come back how do I stop these old email in apple mail? I never send anything from there but I have the same email in yahoo but delete them and they still show up in apple mail from day one how do I get rid of these once and for all.Please help
    <Edited by Host>

    I am soooooooooooo confused now.  Ok, if you are having problems with Yahoo Mail and Gmail but you do not use Apple's Mail you need to do the following:
    1 - Post in Yahoo's Mail forums and/or contact their tech support.
    2 - Post in Gmails forums and/or contact their tech support.
    Neither of the above are Apple's products.

  • Pass data from one web application to another web application

    Hi,
    Please provide suggestion for following scenario:
    Scenario: Basically the aim is to transfer large amount of data from one application to another and display JSP of second application.
    User enteres data on a JSP of one web application. When he submits that data, another web application opens in new window and data from first application should be passed to this second web application. Another web application will display that data on its own JSP. User can perform whatever he wants on second application screen.
    Possible solutions:
    1) response.sendRedirect(): This makes GET request. But, there is large data to send. So, GET is not effective.
    2) forward(request, response): Can't use as I have to pass data to different application that is in another context.
    3) URLConnection: Here, I can make POST request and set attributes in HTTP request and make connection to another application. I can pass data using output stream. But, I can't display second application JSP to user even if I use input stream to read response. Because control will be ultimately in first application only.
    Is there any othe method to achieve this or any of the above options extendable?
    Please give your inputs.

    Hi,
    According to your post, my understanding is that you want to migrate list data from one web application to another.
    We can migrate list data programmatically, there are some articles for your reference.
    http://blogs.msdn.com/b/tejasr/archive/2007/11/12/code-snippet-copy-list-data-between-sites-programmatically.aspx
    http://www.fivenumber.com/copy-sharepoint-list-items-from-one-site-to-another-programmatically/
    http://geekswithblogs.net/AnneBougie/archive/2009/01/23/copy-a-sharepoint-list.aspx
    Thanks & Regards,
    Jason
    Jason Guo
    TechNet Community Support

  • Code for mailing from behing a proxy using Authentication

    Dear friends,
    I have found several requests regarding the mailing from behing a firewall/proxy with Authentication.. So here is the entire code for the same..
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    import java.util.*;
    import javax.mail.*;
    import javax.mail.event.*;
    import javax.mail.internet.*;
    public class MailClient extends Frame{
    static String mailHost="proxyAddress";
    public MailClient() {
    public static void main(String[] args) {
    Properties properties=new Properties();
    properties.put("mail.smtp.host",mailHost);
    properties.put("mail.smtp.auth","true");
    Session session=Session.getDefaultInstance(properties,new MyAuthentication());
    try{
    Message msg=new MimeMessage(session);
    InternetAddress address[]={new InternetAddress("toAddress1.domain.com")};
    msg.setRecipients(Message.RecipientType.TO,address);
    msg.setSubject("Test Mail");
    msg.setFrom(new InternetAddress("[email protected]"));
    msg.setContent("Please reply.. This is a java mail using Authentication
    technique..","text/plain");
    Transport transport=session.getTransport("smtp");
    transport.connect();
    transport.sendMessage(msg,msg.getAllRecipients());
    }catch(Exception e){e.printStackTrace();}
    Hope this helps..
    regards Stallon
    class MyAuthentication extends Authenticator{
    public PasswordAuthentication getPasswordAuthentication(){
    return new PasswordAuthentication("userName","password");
    }

    Hi stallon,
    Thanks for ur reply.Actually my application is at server2. I have an account in server1 and sending mail from server2. server1 requires authentication to send it to server3. Though we provide it is not accepting.There no errors while execution but mail couldn't be send.
    Please help me as soon as possible.
    Thanks in advance,
    bdurvasula
    //debug code.
    DEBUG: getProvider() returning
    javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun
    Microsystems, Inc]
    DEBUG SMTP: useEhlo true, useAuth true
    DEBUG: SMTPTransport trying to connect to host
    "host", port 25
    DEBUG SMTP RCVD: 220 host ESMTP
    server (Netscape Messaging Server - Version 3.6)
    ready
    Thu, 21 Jun 2001 14:23:15 +0800
    DEBUG: SMTPTransport connected to host
    "host", port: 25
    DEBUG SMTP SENT: EHLO rao
    DEBUG SMTP RCVD: 250-host
    250-HELP
    250-EXPN
    250-ETRN
    250-PIPELINING
    250-DSN
    250 AUTH=LOGIN
    DEBUG SMTP SENT: MAIL FROM:<[email protected]>
    DEBUG SMTP RCVD: 250 Sender
    <[email protected]>
    Ok
    DEBUG SMTP SENT: RCPT TO:<[email protected]>
    DEBUG SMTP RCVD: 250 Recipient
    <[email protected]> Ok
    Verified Addresses
    [email protected]
    DEBUG SMTP SENT: DATA
    DEBUG SMTP RCVD: 354 Ok Send data ending with
    <CRLF>.<CRLF>
    DEBUG SMTP SENT:
    DEBUG SMTP RCVD: 250 Message received:
    7745C8DA90B.AAA27D7
    DEBUG SMTP SENT: QUIT
    //now i am sending the mail that was sent by my server
    This Message was undeliverable due to the following
    reason:
    Your message was not delivered because the
    destination
    computer
    refused to accept it. The error message generated
    by
    the server
    is reproduced below.
    Non-local addressee. We do not relay!
    Please reply to Postmaster@mailserver .if you feel
    this message to be in error.Thanks once again
    bdurvasula

Maybe you are looking for

  • HT5622 How can I get an Apple ID for US store when I am in another country?

    hi, I am now in China, and I have bought a iPad there, I want to download apps in US store, but I can't . Could you please help me? Thanks, Alan.

  • TS1420 how can i see what accounts are synched to my iphone

    i just purchased an ipad a few weeks ago.  once i synched my ipad to my itunes, my favorite songs are greyed out on my iphone.  and the first half of all my audible books are also greyed out. my husband's iphone is syncing just fine.  i'm thinking i

  • Adf components not seen at design time

    Hi All, At design time pages are displayed like: <>Root <>Output @page directive <>View <>Html, and so on, for any page in the application. In another application all the pages look fine (if I copy their contents). Tag libraries and libraries in proj

  • Priority field mandatory for planning plant-order type

    Hi Is there a standard way through configuration that I may contol priority field in order header to be mandatory for some order types only in one planning plant? Problem is that if I make the priority field mandatory for order type, it will be so fo

  • Hand tool pressed and its option

    Hi, can the hand tool, when it's pressed and when you get the gigantic red rectangle, which zooms out, be stopped in the middle of that process and leave the magnification position of where I stopped? I tried with alt, command, ctrl, shift, nothing..