Help me with mail sending with servlets/jsp

: doe any one have a clue as to how to send a mail via jsp/servlets.

An obvious solution is to use JavaMail. It is part of j2EE.

Similar Messages

  • Can you help me with an jsp execption please?

    Hello!
    Could you please try to help me with this code
    that brings me an exception?
    this is the jsp page :
    <%@ page import="java.io.*,javax.servlet.http.HttpServletRequest,javax.servlet.ServletInputStream" %>
    <%@ page import="java.io.FileWriter,java.io.IOException" %>
    <%
        String savePath = "", filepath = "", filename = "";
        String contentType = "", fileData = "", strLocalFileName = "";
        int startPos = 0;
        int endPos = 0;
    %>
    <%!
        temp data buffer
        void copyByte(byte [] fromBytes, byte [] toBytes, int start, int len){
           for(int i=start;i<(start+len);i++)
              toBytes[i - start] = fromBytes;
    %>
    <%
    int BOF = 0, EOF = 0;
    contentType = request.getContentType();
    out.println("<br>Content type is :: " +contentType);
    if ((contentType != null) && (contentType.indexOf("multipart/form-data") >= 0)) {
         DataInputStream in = new DataInputStream(request.getInputStream());
         DataInputStream in1 = in;
         int formDataLength = request.getContentLength();
         byte dataBytes[] = new byte[formDataLength];
         int byteRead = 0;
         int totalBytesRead = 0;
         while (totalBytesRead < formDataLength){     
              byteRead = in1.read(dataBytes, totalBytesRead, formDataLength);
              totalBytesRead += byteRead;
         out.println("<br>totalBytesRead : " + totalBytesRead + " : formDataLength = " + formDataLength);
         byte[] line = new byte[128];
         if (totalBytesRead < 3){
         return;     //exit if file length is not sufficiently large
         String boundary = "";
         String s = "";
         int count = 0;          
         int pos = 0;
         do{
         copyByte(dataBytes, line, count ,1);     //read 1 byte at a time
         count+=1;
         s = new String(line, 0, 1);
         fileData = fileData + s;
         pos = fileData.indexOf("Content-Disposition: form-data; name=\""); //set the file name
         if(pos != -1)
         endPos = pos;
         }while(pos == -1);
         boundary = fileData.substring(startPos, endPos);
         startPos = endPos;
         do{
         copyByte(dataBytes, line, count ,1);     //read 1 byte at a time
         count+=1;
         s = new String(line, 0, 1);
         fileData = fileData + s;
         pos = fileData.indexOf("filename=\"", startPos); //set the file name
         if(pos != -1)
    startPos = pos;
         }while(pos == -1);                         
         do{
         copyByte(dataBytes, line, count ,1);     //read 1 byte at a time
         count+=1;
         s = new String(line, 0, 1);
         fileData = fileData + s;
         pos = fileData.indexOf("Content-Type: ", startPos);
         if(pos != -1)
              endPos = pos;                              
         }while(pos == -1);
         filename = fileData.substring(startPos + 10, endPos - 3);     //to eliminate " from start & end
         strLocalFileName = filename;
         int index = filename.lastIndexOf("\\");
         if(index != -1)
         filename = filename.substring(index + 1);
         else
         filename = filename;
         boolean blnNewlnFlag = false;
         startPos = endPos;     //added length of "Content-Type: "
         do{
         copyByte(dataBytes, line, count ,1);     //read 1 byte at a time
         count+=1;
         s = new String(line, 0, 1);
         fileData = fileData + s;               
         pos = fileData.indexOf("\n", startPos);
         if(pos != -1){
              if(blnNewlnFlag == true)
                   endPos = pos;                         
              else{
              blnNewlnFlag = true;
              pos = -1;
         }while(pos == -1);
    contentType = fileData.substring(startPos + 14, endPos);
         startPos = count + 1;
         do{
         copyByte(dataBytes, line, count ,1);     //read 1 byte at a time
         count+=1;
         s = new String(line, 0, 1);
         fileData = fileData + s;
         pos = fileData.indexOf(boundary, startPos);     //check for end of file data i.e boundry value               
         }while(pos == -1);
         endPos = count - boundary.length();
         out.println("<br><br>0. Local File Name = " + strLocalFileName);
         out.println("<br><br>1. filename = " + filename);
         out.println("<br>2. contentType = " + contentType);
         out.println("<br>3. startPos = " + startPos);
         out.println("<br>4. endPos = " + endPos);
         out.println("<br>5. boundary = " + boundary);
         String appPath = application.getRealPath("/");
         out.println("<br>appPath : " + appPath);
         String destFolder = appPath + "images/";
    String name = request.getParameter("signinName").trim();
    String email = request.getParameter("signinEmail").trim();
    String age = request.getParameter("signinAge").trim();
    String passwd = request.getParameter("signinPassword").trim();
    String profile = request.getParameter("signinProfile").trim();
    String type = filename.substring(filename.lastIndexOf("."));
         filename = destFolder + name + type;
         fileOutputStream fileOut = new FileOutputStream(filename);
         fileOut.write(dataBytes, startPos, (endPos - startPos));
         fileOut.flush();
         fileOut.close();
         out.println("<br>File saved as >> " + filename);
         else {
              out.println("Error in uploading ");
    %>
    this is the exception:
    exception
    org.apache.jasper.JasperException: java.lang.NullPointerException
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:382)
         org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:409)
         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:317)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
         com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:73)
         com.sun.enterprise.web.VirtualServerPipeline.invoke(VirtualServerPipeline.java:120)
         org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:231)
         com.sun.enterprise.web.connector.grizzly.ProcessorTask.invokeAdapter(ProcessorTask.java:667)
         com.sun.enterprise.web.connector.grizzly.ProcessorTask.processNonBlocked(ProcessorTask.java:574)
         com.sun.enterprise.web.connector.grizzly.ProcessorTask.process(ProcessorTask.java:844)
         com.sun.enterprise.web.connector.grizzly.ReadTask.executeProcessorTask(ReadTask.java:287)
         com.sun.enterprise.web.connector.grizzly.ReadTask.doTask(ReadTask.java:212)
         com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:252)
         com.sun.enterprise.web.connector.grizzly.WorkerThread.run(WorkerThread.java:75)
    root cause
    java.lang.NullPointerException
         org.apache.jsp.uploadFile_jsp._jspService(uploadFile_jsp.java:190)
         org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:111)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:353)
         org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:409)
         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:317)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
         com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:73)
         com.sun.enterprise.web.VirtualServerPipeline.invoke(VirtualServerPipeline.java:120)
         org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:231)
         com.sun.enterprise.web.connector.grizzly.ProcessorTask.invokeAdapter(ProcessorTask.java:667)
         com.sun.enterprise.web.connector.grizzly.ProcessorTask.processNonBlocked(ProcessorTask.java:574)
         com.sun.enterprise.web.connector.grizzly.ProcessorTask.process(ProcessorTask.java:844)
         com.sun.enterprise.web.connector.grizzly.ReadTask.executeProcessorTask(ReadTask.java:287)
         com.sun.enterprise.web.connector.grizzly.ReadTask.doTask(ReadTask.java:212)
         com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:252)
         com.sun.enterprise.web.connector.grizzly.WorkerThread.run(WorkerThread.java:75)Thanks a lot !!

    root cause
    java.lang.NullPointerException
         org.apache.jsp.uploadFile_jsp._jspService(uploadFile_jsp.java:190)Some variable is getting null value ..so debug it.
    Best way is to start putting System.out's ....
    System.out.println("Step ############1");
    Put the incremental numbering between several code blocks. Check the log output. You will surely be able to find out till what point ur code is Ok.
    -Rohit

  • Help! Sporadic Mail sending issues

    I have recently upgraded to Lion and since then have been having sporadic problems sending mail.  I use a .mac account with O2 broadband at home and an unknown provider at work. 
    Mail stops sending for several hours at a time, and has done so from both locations.  Since my iphone and ipad still send mail without a problem at these times, I have to assume that it is a Lion issue and not a provider issue.
    Connection doctor shows green for incoming and outgoing but mail simply refuses to send.
    My current mail-send-blackout has been going on for 18 hours now.  Yet yesterday my mail would send from home and also when I arrived at work.  But halfway through the working day it just stopped.  Again.  No apparent reason or pattern
    If anyone has any suggestions, I'd be very grateful
    Thanks
    Cal

    Yes well there were no changes to the account, just stopped sending mail via SMTP
    Deleted account and set up new one, same thing cannot send mail via Mail app
    As mentioned another disc on the same comp with same account details etc works fine
    so don't understand
    Seems a lot of people are having this problem too.
    Thanks Anyway

  • Help requierd on mail sender adapter

    i m workin on a scenario to send email from a mail server inbox to XI.i need to configure mail sender adapter....need step by step help on that.
    regards,
    latika.

    hi latika,
    the Message Structure to be defined depends on the message protocol that you are trying to use.
    I would recommend using XIPAYLOAD. From the help link,
    <b>XIPAYLOAD</b>
    In this mode, the content of the e-mail is put in the payload of the XI message. If you do not set the Use Mail Package indicator, the information about the sender (From), receiver (To), and subject of the e-mail is lost.
    If you have selected XIPAYLOAD as the message protocol, you must make the following additional specifications under Mail Attributes:
    If you want to put the entire e-mail message including the header information (From, To, Subject) in the payload, set the Use Mail Package indicator. See the example below. The header information is included in an XML mail package format.
    <i>
    Source Structure</i>
    <i><?xml version="1.0" encoding="UTF-8"?>
    <ns:Mail xmlns:ns="http://sap.com/xi/XI/Mail/30">
      <Subject>Subject</Subject>
      <From>[email protected]</From>
      <To>[email protected]</To>
      <Reply_To />
      <Content_Type>text/plain</Content_Type>
      <Content>
      This is the content.
      </Content>
    </ns:Mail></i>
    Regards,
    Bhavesh

  • Help with Servlet - JSP Newbie

    I'm trying to teach myself jsp. I've created a couple of classes to do my data I/O. I have a form to collect user data and the page the form posts to should write the data to a text file. When I run the form and form handler the data is presented back to the user and everything looks fine... no errors or anything. However, the text file I'm trying to create/append does not get modified. Any suggestions would be greatly appreciated as I can't move on with what I want to do until I figure this out.
    Thanks,
    Steven Lee / EMC
    [email protected]
    I'm running Apache 2.0.52/Tomcat 5.5 on Win 2000. Here's my directory structure:
    C:\Apache\Tomcat 5.5.\webapps\ROOT
    /ROOT
    index.jsp
    OptIn.jsp
    show_email_entry
    /admin
    /WEB-INF -->web.xml
    /classes
    /business -->User.class
    /data -->UserIO.class
    /lib
    ***UserIO.class:***
    package data;
    import java.io.*;
    import business.User;
    public class UserIO{
    public synchronized static void addRecord(User user, String filename)
              throws IOException{
                   PrintWriter out = new PrintWriter(
                        new FileWriter(filename, true));
                   out.println(user.getEmailAddress() + "|"
                        + user.getFirstName() + "|"
                        + user.getLastName() );
                   out.close();
    ***User.class***
    package business;
    public class User {
         private String firstName;
         private String lastName;
         private String emailAddress;
         public User() {}
         public User(String first, String last, String email) {
         firstName = first;
         lastName = last;
         emailAddress = email;
         public void setFirstName(String f) {
              firstName = f;
         public String getFirstName() { return firstName; }
         public void setLirstName(String l) {
              lastName = l;
         public String getLastName() { return lastName; }
         public void setEmailAddress(String e) {
              emailAddress = e;
         public String getEmailAddress() { return emailAddress; }
    ***OptIn.jsp***
    <%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Untitled Document</title>
    </head>
    <body>
    <p>Join E- Mail List</p>
    <form action="show_email_entry.jsp" method="get" name="FRMjoinList" id="FRMjoinList">
    <input name="txFN" type="text" id="txFN">
    first name
    <br>
    <input name="txLN" type="text" id="txLN">
    last name <br>
    <input name="txEMAIL" type="text" id="txEMAIL">
    e-mail <br>
    <input type="submit" name="Submit" value="Submit">
    </form>
    <p> </p>
    </body>
    </html>
    ***show_email_entry.jsp***
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Untitled Document</title>
    </head>
    <body>
    <%@ page import="business.*, data.*, java.util.Date" %>
    <%
         String firstName = request.getParameter("txFN");
         String lastName = request.getParameter("txLN");
         String emailAddress = request.getParameter("txEMAIL");
         User user = new User(firstName, lastName, emailAddress);
         UserIO.addRecord(user, "UserEmail.txt");
    %>
    <p>Today's Date is <%=new Date() %></p>
    <H2>Thanks for joining our list</H2>
    <p>Here's your information:</p>
    <table width="300" border="0" cellspacing="0" cellpadding="0">
    <tr>
    <td width="92">First Name </td>
    <td width="208"><%=user.getFirstName() %></td>
    </tr>
    <tr>
    <td>Last Name </td>
    <td><%=user.getLastName() %></td>
    </tr>
    <tr>
    <td>E-Mail</td>
    <td><%=user.getEmailAddress() %></td>
    </tr>
    </table>
    <p>Click here to enter another address.</p>
    <form name="form1" method="post" action="optIn.jsp">
    <input type="submit" value="Return">
    </form>
    <p> </p>
    </body>
    </html>

    I just realized that the file is given as just a filename. No path.
    Are you SURE the file isn't being created, just somewhere you don't expect?
    Try putting a full path in there instead of just a filename.

  • Please help me with the jsp page

    Hi,
    I have a parent jsp page. I have a button in that page. If I click the button in the parent page, a child page will be opened which consists of huge data. I have set an option such that if I click the jsp page it asks to open directly or save so as to edit the data in MSWORD format. The child page has a print button at the end of the page which prints all the data. But since the data is very vast I want page breaks at certain places so that when I edit the data and click print button it prints the data with page breaks at certain points. I know that in MSWORD we have page breaks. But I should not do it manually as there would be thousands and thousands of pages to be printed.
    ANY IDEA OR HELP IN THIS MATTER IS GREATLY APPRECIATED. I HAVE BEEN TRYING TO SOLVE THIS MATTER AND POSTED IN MANY SITES. BUT NOBODY RESPONDED. ATLEAST PLEASE LET ME KNOW IF THE IDEA WHICH I MENTIONED IS WORNG OR NOT.
    THANKYOU
    MOUNTAINEER

    use java report?

  • Automatic Mail Sending in Java/JSP/Servlets

    Hi,
    How to send mails with a specified format automatically after a stipulated no of days when the user does not access a file/page.
    TIA

    1. In your web application, have a database that keeps track of when a user accesses a page.
    2. Once a day, run a program that scans that database looking for cases when a user has not accessed a page for N days, or whatever your criterion is. Use JavaMail to send an e-mail message to each of those users.
    If you have specific questions about any of these things, don't hesitate to ask them in the appropriate forum.

  • Can someone help me with my JSP DataSoource ...

    I have built a JSP web app using JSTL and it works very well on my local system tomcat 5.5 server, but not on the same remote server. This is what I get after I try to browse;
    type Exception report
    message
    description The server encountered an internal error () that prevented it from fulfilling this request.
    exception
    org.apache.jasper.JasperException: Unable to get connection, DataSource invalid: "org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null'"
         org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:460)
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:355)
         org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    root causeCan someone give me a HELPING HAND...

    Can you give some idea of how you have configured the datasource?
    - using JNDI?
    - hard coding it in the page?
    What code do you use in the JSP to access it?

  • Object living with servlet/jsp container

    How do I make an Object live until the servlet container lives? I mean I want an Object to be instantiated once in the lifetime of the webserver session and its has to be singleton and should live alive until the webserver dies? How can I make this possible? I should be able to keep that object alive even if any no references are made to the object. Moreover I should be able to access that object from any java class on that webserver?

    You can't do this in memory. The easiest thing to do would be to read/write the persistant data you need from disk.
    Anything your JSP or servlet creates in memory will be cleared when it is done serving the request.

  • Object living along with servlet/jsp container

    How do I make an Object live until the servlet container lives? I mean I want an Object to be instantiated once in the lifetime of the webserver session and its has to be singleton and should live alive until the webserver dies? How can I make this possible? I should be able to keep that object alive even if any no references are made to the object. Moreover I should be able to access that object from any java class on that webserver?

    if mean u want to keep the object live for
    one user session
    use session.setAttribute("name",object)
    and if mean for the time btw start up and shutdown of the
    server use application scope
    alternatively
    use session scope in bean or application scope as needed
    like
    <jsp:useBean id="db_in" scope="session" class="com.ww.ert.Bean_IN" />
    or
    <jsp:useBean id="db_in" scope="application" class="com.ww.ert.DatabaseBean_IN" />
    Regards
    manu

  • HelpMac mail sends emails prematurely  while I'm still composing..sometimes it sends 4-5 email versions in various states of completion. I've got clients asking what happened, because they only get a partial email..its becoming a serious problem. Help!

    Help. Mac mail sends myemails prematurely  while I'm still composing..sometimes it sends 4-5 email versions in various states of completion. I've got clients asking what happened, because they only get a partial email..its becoming a serious problem. Help!

    Launch the Console application in any of the following ways:
    ☞ Enter the first few letters of its name into a Spotlight search. Select it in the results (it should be at the top.)
    ☞ In the Finder, select Go ▹ Utilities from the menu bar, or press the key combination shift-command-U. The application is in the folder that opens.
    ☞ If you’re running OS X 10.7 or later, open LaunchPad. Click Utilities, then Console in the page that opens.
    Make sure the title of the Console window is All Messages. If it isn't, select All Messages from the SYSTEM LOG QUERIES menu on the left.
    Click the Clear Display icon in the toolbar. Try the action again. Post any messages that appear in the Console window – the text, please, not a screenshot.
    Important: Some private information, such as your name, may appear in the log. Edit it out by search-and-replace in a text editor before posting.

  • Want to run servlets, jsp and ejb

    Hi there, I have just installed Oracle9iAS on my PC and want to check how to use OAS with servlets, JSPs and ejbs, so can any one tell me where can I find some worked examples and step by step deployment process, any help would be appreciated, regards, Shabbier

    If you have installed Oracle9iAS, you should be able to get to the welcome page at
    http://<machine_name>:7778/
    You can see J2EE demos off that page.
    Also, you can find info about oracle9iAS and documentation
    at http://otn.oracle.com/products/ias/content.html
    OC4J info can be found at
    http://otn.oracle.com/tech/java/oc4j
    -Prasad

  • Ejb + servlet + jsp

    Hallo everybody,
    i try to develop an application with servlet jsp and ejbs but i don't have enough information about this thema.
    for example i want to make a simple login szenario :
    user type the name and passwd and the system contact with the db and show a wellcome page if the login is succesfull and an error page if the login is unsuccessfull.
    which component does was??
    the first page can be a html form and post the name and passwd to a servlet.
    in this case servlet can make a connection with the DB and can forward the user to next page or error page. BUT where should i use EJB? can i realize the db connection with ejb ? if yes how can interact the servlet with the ejb and how can i store the information (for example address of user) which i have taken from the DB?
    thanks a lot

    Thanks for the antwort
    this means that the servlet connected to DB and execute the sql to authenticate user??
    and the second part is my bigger problem :)
    what does it mean "it will pass the control
    to the enterprise java bean which will be housing the business logic for your application."
    what does a java bean really do? how can i find information about them?
    and is ther an example in which i can see how servlets, jsps and beans interact??
    thanks

  • HT6030 I would like to send an e-mail to a group of people I have the group created, but when I drag it to bcc or to it will not attach. can anymon help me with this?

    Help I would like to send an e-mail to a group of people,  I have the group created, but when I drag it to bcc or to- it will not attach. can anymon help me with this?

    In a new email message window start to type the name of the Group you have in Contacts/Address Book in the 'To' field - it should self-complete when it recognises the name.
    (Note: this only works with 'normal' Groups and not Smart 'Groups').

  • Need help with mail sending mails..

    Can anybody help me with a code that works perfectly for sending mails.. since i used many codes which are not working, so please help me with the code to send mails please or else with an example.

    Hi kirupa_sankar,
    To send mails to others you have to use javax.mail.jar file and sample code is
    import javax.mail.*;
    import javax.mail.internet.*; // important
    import javax.mail.event.*; // important
    import java.net.*;
    import java.util.*;
    public class Mail {
    Properties props;
    Session session1;
    Message message;
    boolean flag=false;
    public boolean sendMail()
    props=new Properties();
    props.put("mail.smtp.host","mail.website.com"); // 'localhost' for testing
    session1 = Session.getDefaultInstance(props,null);
    String from= "[email protected]" ;
    String subject = "testing mail(subjective matter)";
    message =new MimeMessage(session1);
    message.setFrom(new InternetAddress(from));
    message.setRecipients(Message.RecipientType.TO,InternetAddress.parse("toaddress",false));
    message.setSubject(subject);
    message.setContent("content of the message");
    Transport.send(message);
    return true;
    try this one you will get success....

Maybe you are looking for

  • I Can't install Firefox Sync on Firefox 25.0.1 for Mac, which I need to use Firefox on iphone.

    When I tried to install Firefox sync it said it was not compatible with firefox 25.0.1. Mac 10.6.8 is the most my system can handle. I have an iphone 4 running iOS 7.0.3. I want to use firefox on my iphone and believe i need to install Firefox Sync t

  • Sending mail to domains containing extended characters?

    Hi! I'm having trouble sending e-mail with cfmail to domains containing characters like å ä ö. In mail.log I get the following message: "508 5.5.2 Illegal character in address". Is this a bug or a setting somewhere in the Administrator? Thanks in adv

  • How can I solve this problem?

    Hello, I have an array which contains 6 randomly generated numbers (which is dealt with in a method). What I want to do is display these numbers in a row, as shown below: 7     12     14     15     19     44 How would I go about achieving this please

  • About LTS

    Hi friends, Can any one tel me 1. How many LTS's we can create in one logical table? 2.Is it possible to create hierarchy for year with out quater level ( directly year to month) if so then how? 3.Where will we find sql query other than default file(

  • Re: How do you remove deleted apps icons in App Store in purchased area?

    Somebody please answer this. i wasnt ment to download games on my ipad but i accidentaly did, HELP!!!!!