Send Email From JSP.

Hai,
I am new to JSP.Now I create one application in jsp using netbean5.I need code for send a email from that application.
please any one help to me
by
Beemaraj.v

You can use the JavaMail API for that.
JavaMail homepage: http://java.sun.com/products/javamail
JavaMail FAQ: http://java.sun.com/products/javamail/FAQ.html
JavaMail subforum here: http://forum.java.sun.com/forum.jspa?forumID=43

Similar Messages

  • I want to send email from jsp,

    i want to send email from jsp, i dont know smtp:host, how to send mail?
    plz carify this doubt sir.

    OK thanks sir but i installed alredy. i write this code. plz send any error's are there. and i dont know smtp:host name. i put my port address?
    try{
        //Set the host smtp address
        Properties props = new Properties();
        props.put("mail.smtp.host", "//10/0/6/252");
        // create some properties and get the default Session
        Session session = Session.getDefaultInstance(props, null);
         // create a message
        Message msg = new MimeMessage(session);
        // set the from and to address
        msg.setFrom(new InternetAddress("[email protected]"));
         msg.addRecipient(Message.RecipientType.To,new InternetAddress("[email protected]"));
        // Setting the Subject and Content Type
        msg.setSubject("hi..");
        msg.setText("hi bharath how are you");
        Transport.send(msg);
    catch(Exception e)
                  out.println(e);
         }

  • Help: sending email from JSP or MSB problem

    Hi Everyone,
    I have an J2EE application which sends email to a user when a user submit a form. The email is send from Jsp page and MSD using sun.net.smtp.SmtpClient class. The codes for sending email are:
    String to = "[email protected]";
    String from="[email protected]";
    String smtpHost="the mail smtp host";
    SmtpClient client = new SmtpClient(smtpHost);
    client.from(from);
    client.to(to);
    PrintStream message = client.startMessage();
    message.println("To: " + to);
    message.println("Subject: a subject");
    message.println("email body");      
    It sends email to internal email account user without a problem. However, when the email reciever's email address is a outside email account such as yahoo, I got the following error message:
    Error 500: 550 not local host yahoo.com, not a gateway                     
    This email sending system worked ok before for outsider email address in our old email server. We recerently switched to a new email server. The jsp page and MDB can no longer send email to outside account.
    Any help is appreciated.
    thanks

    Please see this section in The J2EE 1.4 Tutorial for an example of sending email from an enterprise bean:
    http://java.sun.com/j2ee/1.4/docs/tutorial/doc/Resources5.html#wp79827

  • JavaMail - Sending Email from JSP Templates

    Is there any existing method of sending emails (I'm using JavaMail) from templates written as JSP files? I've done quite a bit of Googling on the matter, and I'm still a bit new to JSP.
    The solution I'm looking for is a way to have an HTML template for an email with variables embedded, which are to be replaced by data from the servlet.
    I know numerous individuals have run in to a similar situations, so I'm sure a solution exists.

    The content of an email can come from a "DataSource"
    There is an implementation of Datasource that can download from a URL (javax.activation.URLDataSource)
    That means you can write a JSP which will be your "email" and then call that JSP to generate the email text.

  • How can Send Email From JSP to all Mail server.it gives error

    I try this code in netbean 5.But it will give the Error.
    The code:
    <%@page import="java.util.*"%>
    <%@page import="javax.mail.*"%>
    <%@page import="javax.mail.internet.*"%>
    <%
    Properties props = System.getProperties();
    props.put("mail.smtp.host", "smtp.gmail.com" );
    props.put("mail.smtp.port", "465" );
    Session s = Session.getInstance(props, null);
    MimeMessage message = new MimeMessage(s);
    String From = request.getParameter("sender");
    InternetAddress from = new InternetAddress(From);
    message.setFrom(from);
    String Tos = request.getParameter("reciever");
    InternetAddress to = new InternetAddress(Tos);
    message.addRecipient(Message.RecipientType.TO, to);
    String sub =request.getParameter("subject");
    message.setSubject(sub);
    String mgs =request.getParameter("message");
    message.setText(mgs);
    Transport.send(message);
    %>
    <html>
    <p align="center">
    A Message has been sent. <br>
    Check your inbox.
    </p>
    <p align="center">
    Click here to send another!
    </p>
    </html>
    Error is :
    javax.servlet.ServletException: Could not connect to SMTP host: smtp.gmail.com, port: 465
         org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:848)
         org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:781)
         org.apache.jsp.MailBeema_jsp._jspService(MailBeema_jsp.java:88)
         org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)
         org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:291)
         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
         org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:362)
    root cause
    javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 465;
    nested exception is:
         java.net.ConnectException: Connection timed out: connect
         com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1282)
         com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:370)
         javax.mail.Service.connect(Service.java:275)
         javax.mail.Service.connect(Service.java:156)
         javax.mail.Service.connect(Service.java:105)
         javax.mail.Transport.send0(Transport.java:168)
         javax.mail.Transport.send(Transport.java:98)
         org.apache.jsp.MailBeema_jsp._jspService(MailBeema_jsp.java:68)
         org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)
         org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:291)
         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
         org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:362)

    javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 465;
    nested exception is:
    java.net.ConnectException: Connection timed out: connectFairly self-explaining, isn't it? That host cannot be connected.
    Either check the correctness of the hostname/port, or check your network settings (firewall, router, etc).

  • Sending emails from jsp

    hi,
    I have a tomcat running on linux, database on oracle9i windows and mail server is exchange 2000
    I want to set reminders to the users of one portal ,
    like if they insert new data they should get reminders via email after first 7 days to update the data. if they do not update after 7 days an escalation should go to the managers for not updating data on 10th day.
    also i want to send a mail immediately when they insert the data for first time.
    help please.

    You can use the mailer taglib

  • How to send an email from jsp

    hello
    i want to send email from jsp
    the following is that code
    and i also downloaded the mail.jar and activation.jar
    and there is no error in the code
    but the email is not sent
    kindly tell me that what can be the reason
    <%@ page import="sun.net.smtp.SmtpClient, java.io.*" %>
    <%
    String from="[email protected]";
    String to="[email protected]";
    try{
    SmtpClient client = new SmtpClient("xx.xxx.xx.xx");//replace with the reqiured smtp
    client.from(from);
    client.to(to);
    PrintStream message = client.startMessage();
    message.println("To: " + to);
    message.println("Subject: Sending email from JSP!");
    message.println("This was sent from a JSP page!");
    message.println();
    message.println();
    message.println();
    client.closeServer();
    catch (IOException e){     
    System.out.println("ERROR SENDING EMAIL:"+e);
    %>

    try this:
    <html>
    <body>
    <form action="enviaremail.jsp" method="post">
    <table border="0" align="center" bgcolor="tan">
    <tr>
    <td><b>Para..:</b></td>
    <td><input type="Text" name="para"</td>
    </tr>
    <tr>
    <td><b>De..:</b></td>
    <td><input type="Text" name="de"</td>
    </tr>
    <tr>
    <td><b>Assunnto..:</b></td>
    <td><input type="Text" name="assunto"</td>
    </tr>
    <tr>
    <td colspan="2">
    <textarea name="mensagem" rows=10 cols=45></textarea>
    </td>
    </tr>
    </table>
    <center> <input type="Submit" value="Enviar Email"></center>
    </form>
    </body>
    </html>
    <html>
    <body>
    <%@ page import="jspbrasil.Email" %>
    <jsp:useBean id="email" class="jspbrasil.Email"/>
    <%
    try {
    String mailServer = "mail.seumailserver.com.br"
    String assunto = request.getParameter("assunto")
    String para = { request.getParameter("para") };
    String de = request.getParameter("de");
    String mensagem =request.getParameter("mensagem");
    email.sendSimpleMail(mailServer, assunto, para, de, mensagem);
    %>
    <p>Email enviado com Sucesso !!!</p>
    <%
    catch (AddressException e) { %>
    <p>Endere�o de Email inv�lido</p>     
    <%}%>
    <%
    catch (MessagingException e) { %>
    <p>Imposs�vel enviar o email.</p>     
    <%}%>
    </body>
    </html>
    package jspbrasil;
    import javax.mail.*;
    import javax.mail.internet.*;
    import.java.util.*;
    public class Email {
    public void sendSimpleMail (String mailServer, String subject,
    String to,String from, String mensagem)
    throws AddressException, MessagingException {
    Properties mailProps = new Properties();
    //defini��o do mailserver
    mailProps.put("mail.smtp.host", mailServer)
    Session mailSession = Session.getDefaultInstance(mailProps, null);
    //As duas linhas seguintes de c�digo, colocam no
    //formato de endere�os,
    //supostamente v�lidos, de email os dados
    //passados pelos par�metros to e from.
    InternetAddress destinatario = new InternetAddress (to);
    InternetAddress remetente = new InternetAddress (from);
    //As duas linhas de c�digo a seguir, s�o
    //respons�veis por setar os atributos e
    //propriedas necess�rias do objeto message
    //para que o email seja enviado.
    //inicializa��o do objeto Message
    Message message = new MimeMessage (mailSession);
    //Defini��o de quem est� enviando o email
    message.setFrom(remetente);
    //define o(s) destinat�rio(s) e qual o tipo do
    //destinat�rio.
    //os poss�veis tipos de destinat�rio: TO, CC, BCC
    message.setRecipient( Message.RecipientType.TO, destinat�rio );
    //defini��o do assunto do email
    message.setSubject (subject);
    //defini��o do conte�do da mensagem e do
    //tipo da mensagem
    message.setContent (mensagem.toString(), "text/plain");
    //a linha de c�digo seguinte � a respons�vel
    //pelo envio do email
    Transport.send (message);

  • Sending emails from the JSP application

    hi,
    I am trying to send emails from my jsp application using JavaMail API's.
    I am using my own mailserver.
    Iam able to send emails from my applications to the ids of my own mailserver but not the yahoo,gmail and rediff ids.
    Is it because of blocking of any firewall or somthing else to do within my application?
    Can anyone help me in this?
    Thanks a lot.

    Please read the JavaMail FAQ.
    It's probably due to the configuration of your mail server,
    which is refusing to relay your messages.

  • Sending Email From a JSP Page

    Hi All,
    Can anybody tell me how to send email from the jsp page. My requirement is to send email to the user when he click on a button on the jsp page.
    thanks and regards
    MSoldier

    You need to install an SMTP server, or access an existing one.
    Contact your network administrator about this, he should be able to help you.
    PLEASE don't go around installing your own mailservers on the internet unless you know very well what you're doing, as most of those are wide open to abuse by spammers and people spreading email virusses as relays (plus it's likely against company or ISP policy).
    And NEVER use someone else's servers without their consent to send email.

  • How to send emails using JSP?

    How can i send emails using JSP? what are the things that i will need? please help me asap...thanks

    Hi,
    This works for me:
    <%
    String from = "Person"
    String to= "my-email-address;
    try{
    SmtpClient client = new SmtpClient("smtp.stuff.com");
    client.from(from);
    client.to(to);
    PrintStream message = client.startMessage();
    message.println("To: " + to);
    message.println("Subject: Sending an e-mail");
    message.println();
    message.println("Groovy :-)");
    client.closeServer();
    catch (IOException e){
    System.out.println("ERROR SENDING EMAIL: "+e);
    %>

  • Send mail from JSP page

    Hello,
    can some one help me to send emails from a jsp page.
    and if possible the source code of jsp or java...
    Thanks !

    read this:
    http://www.jspinsider.com/tutorials/jsp/javamail/jspjavamail_1.view

  • Email From JSP

    I am dealing with sending emails from a jsp
    In fact, I don't know where to start...
    How do send a user an email if they just click a button on my page..
    Assistance will be much appreciated......
    ps:Something besides the subject: I would like to get to know some peeps from India as I am Indian and I need to get in touch with my roots...
    Reply to the post.....
    Thank You
    Out Of South Africa.....

    When user clicks a Button on your web page,you can redirect a jsp file which contains below code....
    <%@ page import="java.util.Properties,javax.mail.*,javax.mail.internet.*," %>
    <%
    String from="[email protected]";//replace your valid mail id here
    // Get system properties
    Properties props = System.getProperties();
    // Setup mail server
    props.put("mail.smtp.host", "SMTPServerIP or Name");//Replace SMTPServerIP or Name and Put your SMTP Server IP or Name.
    // Get session
    Session se = Session.getDefaultInstance(props, null);
    // Define message
    MimeMessage message = new MimeMessage(se);
    // Set the from address
    message.setFrom(new InternetAddress(from,"-yourName-"));
    // Set the to address
    message.addRecipient(Message.RecipientType.TO, new InternetAddress("[email protected]"));//replace your valid mail id here
    // Set the subject
    message.setSubject("Subject");
    // Set the content
    message.setText("Content to be written");
    // Send message
    try
    Transport.send(message);
    }catch(SendFailedException sf){
    %>
    Save this code as a JSP file.(like sendmail.jsp)
    Sample HTML code here
    <input type="button" name="b1" value="Click Me" onClick="javascrip:window.navigate('sendmail.jsp');"/>
    Try this and let me know if itz working or not

  • How to send email through jsp

    can anyone please help me ...
    how do we send an email from a jsp page to any gmail,hotmail,yahoomail etc....
    what is the code for that
    if anybody know the solution it will be greatly appreciated ..
    regards
    santhosh
    9341208148

    I have a writeup that shows how to use JavaMail. It presents my EmailDelivery class (and example of how to use it) which I wrote to help me easily send emails from my Java applications using JavaMail. It supports relaying through SMTP servers that require authentication and has convenience methods for easily adding file attachments.
    Check it out at:
    http://timarcher.com/?q=node/53

  • Cannot send email from yahoo account on iPhone 5

    I just got an iPhone5 and I couldn't set up my Yahoo email as "yahoo"--it would not allow me to complete the process despot multiple attempts. I had to set it up as an "other" account. I can receive and read emails on my phone, but when I reply those messages will not send. They go to the outbox and an error message pops up that says" the email account has been rejected by the server" Does anyone have advice on either issue: setting up yahoo properly and/or sending email from phone?

    outgoing mail server
    SMTP - Yahoo! SMTP Server
    primary server
    Yahoo! SMTP server - ON
    server port 465
    That's what I have for my yahoo account.

  • Cannot send email from non .mac server

    I am only able to send/reply emails using my .mac address. My 2 other server addresses keep giving me the following message.
    "Cannot send mail. One of the recipient addresses was invalid".
    How can I fix this?

    You should be able to send email from Safari, however I do wonder why you wish to do this and whether there is something inherently wrong with using your mail app and your iCloud address.

Maybe you are looking for

  • Problem showing BI Publisher Report in Dashboard with Prompt

    Hi, I've created a BI Publisher report using BI Answer as data source. For getting some xml files for building the rtf Template I've set my filter datas to fixed values. I've created my dashboard with my BIP report and a query from BI Answer. All was

  • Can I upgrade IPhoto 6.0.6 to IPhoto 11' on a Mac OS 10.4.1?

    Can I upgrade IPhoto 6.0.6 to Iphoto 11' on my Mac OS 10.4.1 ?

  • Why cant my ipod connect to my home wifi?

    Whenever i go anywhere, i can connect to wifi no problem, but i am unable to connect to it at home. When i tap the network, the check mark never appears, just the spinning wheel. I have already tried resets and backing it up. NOTHING WORKS!!!!!!! how

  • Can you edit whole audio as one file?

    I have done the bulk of transitions and mixing in final cut and just want to use soundtrack to eliminate some hiss and tiny bit of clean up can i send the audio as a complete file so I dont have to do multitrack and risk messing my mixes and transiti

  • Problem with webcam publisher

    hi there,        Webcam publisher displaying in mozilla  but not in chrome or ie.i had tried private stream example but also having the same issue.       Any help would be greatly appreciated. Thanks in advance, Sreeja