How to send E-mails using JSP

I developed a system where users can login and check for updated information and documents. But the changes are made once or twice in a year. I want to send email after changing the documents. I stored email addresses in the DB. Now the question is how to send e-mails to concerned users without using external software (Outlook, etc.). [Considering same subject and message for all e-mails.]

Go to Java Mail forum:
http://forum.java.sun.com/forum.jsp?forum=43

Similar Messages

  • How to send a Mail using JSP using browser.

    Dear friends
    I could write a code to send a mail and execute it from a command prompt using a class file, but the same code, I converted into a JSP tags to run from a browser. I am getting compilation error. Can you please help me in solving this problem.
    I am using javamail API 1.3,JAF1.0.2
    Win2000,Websphere 3.5,HostPublisher server 3.5,IE6.0
    I shall be thankful if someone shows me the solution.

    Hello
    I hope that this is useful
    I'm using Tomacat 4.0.4 and J2SDK1.4.0_01
    Setting on conf\Server.xml
    <Resource name="mail/Session" auth="Container"
                        type="javax.mail.Session"/>
              <ResourceParams name="mail/Session">
                <parameter>
                  <name>mail.smtp.host</name>
                  <value>your hostmail server</value>
                </parameter>
              </ResourceParams>Setting on web.inf/web.xml
    <servlet>
        <servlet-name>SendMailServlet</servlet-name>
        <servlet-class>SendMailServlet</servlet-class>
      </servlet>
    <servlet-mapping>
        <servlet-name>SendMailServlet</servlet-name>
        <url-pattern>/SendMailServlet</url-pattern>
      </servlet-mapping>
    <resource-ref>
        <res-ref-name>mail/Session</res-ref-name>
        <res-type>javax.mail.Session</res-type>
        <res-auth>Container</res-auth>
      </resource-ref>jsp page example:
    <html>
    <head>
    <title>Example Mail Sending Form</title>
    </head>
    <form method="POST" action="../../SendMailServlet">
    <table>
      <tr>
        <th align="center" colspan="2">
          Enter The Email Message To Be Sent
        </th>
      </tr>
      <tr>
        <th align="right">From:</th>
        <td align="left">
          <input type="text" name="mailfrom" size="60">
        </td>
      </tr>
      <tr>
        <th align="right">To:</th>
        <td align="left">
          <input type="text" name="mailto" size="60">
        </td>
      </tr>
      <tr>
        <th align="right">Subject:</th>
        <td align="left">
          <input type="text" name="mailsubject" size="60">
        </td>
      </tr>
      <tr>
        <td colspan="2">
          <textarea name="mailcontent" rows="10" cols="80">
          </textarea>
        </td>
      </tr>
      <tr>
        <td align="right">
          <input type="submit" value="Send">
        </td>
        <td align="left">
          <input type="reset" value="Reset">
        </td>
      </tr>
    </table>
    </form>
    </body>
    </html>SendMailServelet.java:
    import java.io.IOException;
    import java.io.PrintWriter;
    import javax.mail.Message;
    import javax.mail.Session;
    import javax.mail.Transport;
    import javax.mail.internet.InternetAddress;
    import javax.mail.internet.MimeMessage;
    import javax.naming.Context;
    import javax.naming.InitialContext;
    import javax.servlet.RequestDispatcher;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    public class SendMailServlet extends HttpServlet {
        public void doPost(HttpServletRequest request,
                           HttpServletResponse response)
            throws IOException, ServletException
            // Acquire request parameters we need
            String from = request.getParameter("mailfrom");
            String to = request.getParameter("mailto");
            String subject = request.getParameter("mailsubject");
            String content = request.getParameter("mailcontent");
            if ((from == null) || (to == null) ||
                (subject == null) || (content == null)) {
                RequestDispatcher rd =
                    getServletContext().getRequestDispatcher("/jsp/mail/sendmail.jsp");
                rd.forward(request, response);
                return;
            // Prepare the beginning of our response
            PrintWriter writer = response.getWriter();
            response.setContentType("text/html");
            writer.println("<html>");
            writer.println("<head>");
            writer.println("<title>Example Mail Sending Results</title>");
            writer.println("</head>");
            writer.println("<body bgcolor=\"white\">");
            try {
                // Acquire our JavaMail session object
                Context initCtx = new InitialContext();
                Context envCtx = (Context) initCtx.lookup("java:comp/env");
                Session session = (Session) envCtx.lookup("mail/Session");
                // Prepare our mail message
                Message message = new MimeMessage(session);
                message.setFrom(new InternetAddress(from));
                InternetAddress dests[] = new InternetAddress[]
                    { new InternetAddress(to) };
                message.setRecipients(Message.RecipientType.TO, dests);
                message.setSubject(subject);
                message.setContent(content, "text/plain");
                // Send our mail message
                Transport.send(message);
                // Report success
                writer.println("<strong>Message successfully sent!</strong>");
            } catch (Throwable t) {
                writer.println("<font color=\"red\">");
                writer.println("ENCOUNTERED EXCEPTION:  " + t);
                writer.println("<pre>");
                t.printStackTrace(writer);
                writer.println("</pre>");
                writer.println("</font>");
            // Prepare the ending of our response
            writer.println("<br><br>");
            writer.println("<a href=\"jsp/mail/sendmail.jsp\">Create a new message</a><br>");
            writer.println("</body>");
            writer.println("</html>");       
    }Ciao
    Riccardo

  • How to send e-mail using PL/SQL

    I need to send e-mail using PL/SQL. Is it possible?
    Thanks in advance,
    Agnaldo

    Yes. Use the UTL_SMTP package

  • How to send e-mail using java mail api

    Hi can anyone tell me how to send mail using the javamail api, in short if possible an example code.

    Theres already lots of this code in the forums, use the search bar to the left.
    Also, there is a dedicated javaMail forum which you will find useful (you are currently in a JSP forum)
    http://forum.java.sun.com/forum.jspa?forumID=43

  • Sending automatic mail using JSP or Servlet

    hello,
    i was just wondering if anyone out there knows how can automatically send emails to client from my application after receiving thier email address. the email address is received from a form and i want my application to automatically send a structured email to the client as soon as they click the send button. i am using JSP and tomcat as my server. any help will be appreciated

    You must create a class that sends the mail:
    A code example would be like this:
    import javax.mail.Message;
    import javax.mail.MessagingException;
    import javax.mail.Session;
    import javax.mail.Transport;
    import javax.mail.internet.InternetAddress;
    import javax.mail.internet.MimeMessage;
    import java.util.*;
    public class MailSender {
         public void postMail(String smtpsrv, String recipients[], String subject,
                   String message, String from) throws MessagingException {
              boolean debug = false;
              //Set the host smtp address
              Properties props = new Properties();
              props.put("mail.smtp.host", smtpsrv);
              // create some properties and get the default Session
              Session session = Session.getDefaultInstance(props, null);
              session.setDebug(debug);
              // create a message
              Message msg = new MimeMessage(session);
              // set the from and to address
              InternetAddress addressFrom = new InternetAddress(from);
              msg.setFrom(addressFrom);
              InternetAddress[] addressTo = new InternetAddress[recipients.length];
              for (int i = 0; i < recipients.length; i++) {
                   addressTo[i] = new InternetAddress(recipients);
              msg.setRecipients(Message.RecipientType.TO, addressTo);
              // Setting the Subject and Content Type
              msg.setSubject(subject);
              msg.setContent(message, "text/html;charset=utf-8");
              Transport.send(msg);
    You 'll find out that its easy to understand the code.
    I advise you not to change this code.
    I also include an example of how to right the JSP code:
    <%
    MailSender MS = new MailSender();
    try {
         MS.postMail(server, recipient,"Your E-mail Title", "BODY content", from);
         } catch (MessagingException e1) {
                        e1.printStackTrace();
    %>
    This JSP code follows the pattern of the above class
    Hope to help you
    Cheers!!!

  • How to send a mail using SMTPAppender in Log4j..?

    Hello friends,
    I'm new to this forum.
    I'm trying to send mail using SMTPAppender.
    I am getting this error..
    javax.xml.parsers.FactoryConfigurationError: Provider for javax.xml.parsers.DocumentBuilderFactory cannot be found
    at javax.xml.parsers.DocumentBuilderFactory.newInstance(Unknown Source)
    at org.apache.log4j.xml.DOMConfigurator.doConfigure(DOMConfigurator.java:772)
    at org.apache.log4j.xml.DOMConfigurator.doConfigure(DOMConfigurator.java:696)
    at org.apache.log4j.helpers.OptionConverter.selectAndConfigure(OptionConverter.java:471)
    at org.apache.log4j.LogManager.<clinit>(LogManager.java:125)
    at org.apache.log4j.Logger.getLogger(Logger.java:105)
    at com.honeywell.logging.Log.<clinit>(Log.java:36)
    Exception in thread "main"
    Here is the code...
    Log.java
    package com.something.log;
    import org.apache.log4j.Logger;
    import org.apache.log4j.LogManager;
    import javax.mail.*;
    import javax.mail.internet.*;
    import org.apache.log4j.helpers.Loader;
    import org.apache.log4j.xml.DOMConfigurator;
    import java.net.URL;
    import java.util.*;
    import javax.mail.Message;
    import org.apache.log4j.PatternLayout;
    import org.apache.log4j.net.SMTPAppender;
    public class Main {
    * @param args the command line arguments
    private static final Logger lg=Logger.getLogger("com.something.log.Main");
    public static void main(String[] args) {
    URL url = Loader.getResource("log4j.xml");
                   DOMConfigurator.configure(url);
              // create email appender
         SMTPAppender smtpAppender = new SMTPAppender();
         smtpAppender.setTo("[email protected]");
         smtpAppender.setFrom("[email protected]");
         smtpAppender.setSMTPHost("smtp.something.com");
         smtpAppender.setSubject("Testing Email");
         smtpAppender.setLocationInfo(false);
         smtpAppender.setLayout(new PatternLayout("%d{ABSOLUTE} %5p %c{1}:%L - %m%n"));
         smtpAppender.activateOptions();
         // add email appender
         lg.addAppender(smtpAppender);
    log4j.xml
    <?xml version="1.0" encoding="UTF-8"?><!DOCTYPE log4j:configuration SYSTEM "log4j.dtd" >
    <log4j:configuration>
         <appender name="file"
              class="org.apache.log4j.RollingFileAppender">
              <param name="maxFileSize" value="100KB" />
              <param name="maxBackupIndex" value="5" />
              <param name="File" value="logs/log.txt" />
              <param name="threshold" value="info"/>
              <layout class="org.apache.log4j.PatternLayout">
                   <param name="ConversionPattern"
                        value="%d{ABSOLUTE} %5p %c{1}:%L - %m%n" />
              </layout>
         </appender>
         <appender name="mail" class="org.apache.log4j.net.SMTPAppender">
              <param name="SMTPHost" value="smtp.something.com" />
              <param name="From" value="[email protected]" />
              <param name="To" value="[email protected]" />
              <param name="Subject" value="[LOG] ..." />
              <param name="BufferSize" value="1" />
              <param name="threshold" value="error" />
              <layout class="org.apache.log4j.PatternLayout">
                   <param name="ConversionPattern"
                        value="%d{ABSOLUTE} %5p %c{1}:%L - %m%n" />
              </layout>
         </appender>
         <root>
              <priority value="debug"></priority>
              <appender-ref ref="file" />
              <appender-ref ref="mail"/>
         </root>
    </log4j:configuration>
    log4j.properties
    log4j.rootLogger=warn, file, mail
    log4j.appender.file=org.apache.log4j.RollingFileAppender
    log4j.appender.file.maxFileSize=100KB
    log4j.appender.file.maxBackupIndex=5
    log4j.appender.file.File=D:\log.txt
    log4j.appender.file.threshold=info
    log4j.appender.file.layout=org.apache.log4j.PatternLayout
    log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
    #email appender
    log4j.appender.mail=org.apache.log4j.net.SMTPAppender
    #defines how othen emails are send
    log4j.appender.mail.BufferSize=1
    log4j.appender.mail.SMTPHost="smtp.something.com"
    [email protected]
    [email protected]
    log4j.appender.mail.Subject=Log ...
    log4j.appender.mail.threshold=error
    log4j.appender.mail.layout=org.apache.log4j.PatternLayout
    log4j.appender.mail.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
    Please help me in fixing the problem.....
    Is this code correct to send email...??

    I've not reviewed all of your code/config there, but the error seems to me to indicate a problem parsing your log4j.xml file - have you been able to get a simple configuration working? Can you parse other XML files?
    Good Luck
    Lee

  • How to send/receive XML using JSP

    Hi,
    I'm new to all this JSP/XML stuff so apologies if this is trivial.
    I'm trying to send an XML file via HTTP POST using JSP. Anyone know how to do this?
    Once the XML has been sent, how do you use JSP to request the XML file? I've figured out how to parse it already.
    Also, is it possible to call xsql directly within JSP?
    Thanks!

    I'm trying to send an XML file via HTTP POST using JSP. Anyone know how to do this?The question is, does anybody understand what you mean by this. Let me take a guess. You want to upload an XML file to a server. If this guess is right, then the answer is don't use JSP to do that. JSP is for generating output to be sent to a client. Use a servlet to handle an upload. And you don't need to write it yourself, there are already several file-upload servlets available on the web.
    Second guess: you have a POST request that asks your server to send an XML file back to the client. If it's a static XML file you don't need a JSP or a servlet or anything, just let your web server handle it just like any other static file. If it's dynamically generated then there's an answer worth giving, but I doubt that this is your question. But if it is, let us know.

  • How to send automated mail using Weblogic API ,,,,,, NOT Java Mail API.

    Hi All,
    I need to send an automated mail using BEA Weblogic API, can you please let me know how to accomplish this task,
    I will be heartly thankful to you,
    waiting for your response back
    naveen

    does it uses weblogic API ,, is thre any other way to do the task apart from email controls ,,,, because we are using timers and email control uses event genrators.

  • How to send Secured Mail using Java Mail?

    I want to send mails with "Send Secure" option using Java Mail. Now mails are being sent using Java Mail connecting to smtp host.
    Appreciating your help.
    Thanks.

    There are third party libraries to help with this. Bouncy Castle is very popular.
    See the [JavaMail Third Party Products|http://java.sun.com/products/javamail/Third_Party.html] page.

  • HOW TO SEND MULTIPLE MAILS USING EXTERNAL COMMUNICATION IN ACTIONS

    Hi all,
    we are working on a sales scenario in crm 5.0 ,currently we are able to send a mail to the particular BP only,what we want is mail should go to the multiple partners like contact person,prospect and user.can anyone help on this.
    Thanks in advance
    bye
    ram

    You can use the BADI: EXEC_METHODCALL_PPF for this. Use the piece of code below to get the guid, and then you can use CRM_ORDER_READ to get the partners. After that you can use the FM to send mails(Dont' remember the name right now) to send mails to all the partners. Hope this will help.
      "ASSIGN io_appl_object to
      DATA: lv_appl_object TYPE REF TO cl_doc_crm_order.
    cast object to application object
      lv_appl_object ?= io_appl_object.
      CALL METHOD lv_appl_object->get_crm_obj_guid
        RECEIVING
          result = ls_guid.

  • How to send a mail using vc

    hi,
    i have a requirement of sending a table which is displayed as a mail to the end users
    is there a possibilityof sending mails using vc
    please suggest me
    i will assign points

    Hi Venkat,
    you can not send emails from Visual Comoser without a web service. If you want to send BI reports you can use the BI broadcaster. You can also trigger the broadcaster from Visual Composer.
    If you want to send only the exception values you must filter the values and send the filtered values via email.
    E.g. you have a BI query exception revenue < 1.000.000 then you can filter in VC < 1.000.000 and pass the values to your email webservice.
    Best Regards,
    Marcel

  • How to send e-mails using CAF GP?

    Hi All,
    I have created a sample application which uses Process Control -> Visual Approval Callable Object for approving a vendor. I have also developed two mail templates for Approval and Rejection.
    The SMTP server is set to the mail server of the company.
    But the system is unable to send mails to the recipient. The following error message is displayed on clicking on "Approve":
    <i>Recipient data is missing.
    The system failed to send an e-mail notification to <Initiator>.</i>
    Can any of you suggest what the problem is and what is the possible workaround?
    Thanks in advance,
    Pavithra

    Hi Pavithra,
    Have u completed all the necessary configurations needed at the Visual Administrator level,
    You need to configure GP to be capable of picking the mails from your mail server at some regular intervals of time,
    You can refer to the document "Configuring GP for Interactive forms" at
    SAP Composite Application Framework - CAF Tutorial Center [original link is broken]
    Hope this will help,
    Rgds
    Deepak

  • How to send a mail using utl_mail

    Dear Experts
    i am facing problem while using the utl_mail package. whatever steps i have follow is underwritten.
    have a look.......
    SQL> ALTER SYSTEM SET SMTP_OUT_SERVER='smtp.gmail.com' SCOPE=SPFILE;
    System altered.
    SQL> @?/rdbms/admin/utlmail.sql
    Package created.
    Synonym created.
    SQL> @?/rdbms/admin/prvtmail.plb
    Package body created.
    No errors.
    SQL> BEGIN
    2 UTL_MAIL.SEND(SENDER => '[email protected]',recipients => '[email protected]',message => 'all is well', subject =>'wishes 4 u');
    3 END;
    4 /
    BEGIN
    ERROR at line 1:
    ORA-29279: SMTP permanent error: 530 5.7.0 Must issue a STARTTLS command first.
    39sm1824546yxd.6
    ORA-06512: at "SYS.UTL_SMTP", line 21
    ORA-06512: at "SYS.UTL_SMTP", line 99
    ORA-06512: at "SYS.UTL_SMTP", line 222
    ORA-06512: at "SYS.UTL_MAIL", line 407
    ORA-06512: at "SYS.UTL_MAIL", line 594
    ORA-06512: at line 2
    please do needful..
    thanks in advance.
    regards
    dharmendra

    But, you apparently do have an internet account (usually nowadays internet and email etc. is 'all included'), else you wouldn't be posting here. So, let's assume your provider is ACME and you live in Holland (= .nl), then you could try:
    ALTER SYSTEM SET smtp_out_server='smtp.acme.nl' SCOPE=SPFILE;
    You need to figure that out yourself, since we don't know who provides you internet access (nor whether it would work).
    That would be the simplest way.
    Not sure whether you can get gmail etc. to 'work with you': Re: utl.mail - smtp_out_server parameter

  • How to send mail using jsp program

    am very new to jsp and doing my final year project. i need to send mails using my jsp program.can anyone say wht to do that is wht to include to send mails using jsp program. n also a sample code to send mail using jsp program.
    Thanx in advance

    Use below script.
    <%@ page import="java.util.*, javax.mail.*, javax.mail.internet.*" %>
    <%
    Properties props = new Properties();
    props.put("mail.smtp.host", "mailserver.com");
    Session s = Session.getInstance(props,null);
    InternetAddress from = new InternetAddress("[email protected]");
    InternetAddress to = new InternetAddress([email protected]");
    MimeMessage message = new MimeMessage(s);
    message.setFrom(from);
    message.addRecipient(Message.RecipientType.TO, to);
    message.setSubject("Your subject");
    message.setText("Your text");
    Transport.send(message);
    %>{code}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • How to bypass proxy when trying to send a mail using javamail smtp

    Hi,
    I am trying to make a servlet send a mail using javamail smtp protocol on port 25 but i m not able to send getting an exception, i suspect proxy is blocking, so any idea anyone how bypass a proxy.

    And if it does turn out that there's a proxy server blocking access to your target SMTP server, the best way to deal with that is to discuss the issue with the person responsible for your network configuration.

Maybe you are looking for

  • New install - starting xfce4 returns blank sreen.

    Hi All, I have just attempted my first Arch install, on a Toshiba Tecra A10 laptop. The install went through fine, after configuring the network I have updated the system successfully but I'm having a problem getting my DE running. I installed xfce v

  • Can't send mail after resetting my googlemail password

    Hi. I find I cannot send mail messages although I can receive them fine on my Mac Mini.  This follows having reset my googlemail password.  I can send and receive with no problem on my other Apple devices: iPhone and iPad. The Mac Mini is updated to

  • Applet works on eclipse but not on reg browser (not inited error)

    Hi everybody, I've just made an applet, but I don't know why it can't be shown. I'm working with Eclipse, and when I run the .java file, everything works fine. It even works fine when I specify parameters through the eclipse build file parameter argu

  • How to Configure Location based Accounts system for a company

    Hi Experts, My client using SAP B1 2007B PL13. I am configuring the Accounts part. here My client is involved in manufacturing business. so there are 3 locations like Location 1: Head Office Location 2: Factory1 and Warehouse1. Location 3: Factory2 a

  • Is the OBPM Workspace application section 508 Compliant

    Our customers need the application to be section 508 compliant. Is the out of the box ...OBPM workspace application compliant or would we have to build our own user interface and use papi to interact with BPM?