Send an email from JSP page

Hi everyone,
What's the easiest way to send an email from a JSP page?
Thanks in advance
Chris

If you mean from the client that displays JSP-generated HMTL, generate a "mailTo" tag. If you want to send an E-mail from the server, use the JavaMail API (http://developer.java.sun.com/developer/onlineTraining/JavaMail/)

Similar Messages

  • 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);

  • How to send the data from jsp page to excel ???

    hi all,
    i want to send the data from my jsp form to excel sheet. any one can help me ??

    Hope this sample code might help :
    StringBuffer data = new StringBuffer();
    OutputStream ostream = response.getOutputStream();
    response.setContentType("application/vnd.ms-excel");
    response.setHeader( "Content-Disposition",
    "attachment; filename=sample.xls" );
    ostream.write(data.toString().getBytes());
    ostream.flush();
    Try it out.
    Swathi

  • Why is it that often when i attempt to send an email from some pages where you are meant to say, click on the words "email me" instead of taking you to an email form or window it begins opening endless tabs to infinity & i am forced to forcequit firefox?

    i click on "email me" or "send me an email" & it just begins opening tabs endlessly & so fast i have to force firefox to quit & not save my tabs & windows- its happened on many sites

    i dont understand your answer... its not my email that isnt working right, my email works fine... its just when i am on a site like for instance i was attempting to write to one of my congress people & when i clicked on "email me" boom! there it was... firefox just started making endless tabs without stopping...

  • Send message from JSP page to Java message driven bean

    Hi all
    I'm using Jdev903.
    I need to send a message from JSP page (Web Application) to Java Message Driven Bean.
    * I created Message Driven Bean that named: MyMessageDrivenEJBBean
    * I have configed jms.xml:
    <topic-connection-factory name="ChatTopicConnectionFactory" location="jms/theTopicConnectionFactory"/>
    <topic name="ChatTopic" location="jms/theTopic"/>
    * In JSP page, my code is:
    final Context ctx = new InitialContext();
    // 1: Lookup ConnectionFactory via JNDI
    TopicConnectionFactory factory =(TopicConnectionFactory)ctx.lookup("jms/theTopicConnectionFactory");
    But trouble occurs is:
    javax.naming.NameNotFoundException: jms/theTopicConnectionFactory not found
    please help me!
    thank a lot.

    Welcome to the Sun forums.
    1. Please post your code using code tags, this formats it so that it is easier for people to read and understand it. Click on 'CODE' above the text area when posting.
    2. As far as possible, please post an SSCCE
    What have learnt about JSPs and servlets till now? Because reading the values submitted in a form is pretty much the base of all operations. I suggest you Google for [servlet tutorials|http://www.google.com/search?q=servlet+tutorial] and [JSP tutorials|http://www.google.com/search?q=jsp+tutorial] and go through them thoroughly. After you understand what is to be done and what options are available to you, if you still face problems, please feel free to post your queries here. But this isn't exactly a site for tutorials, especially since there are so many good ones already out there, that explain all this stuff in detail. There's no point in re-inventing the wheel.
    Hints: [ServletRequest#getParameter()|http://java.sun.com/javaee/5/docs/api/javax/servlet/ServletRequest.html#getParameter(java.lang.String)] and [RequestDispatcher#forward|http://java.sun.com/javaee/5/docs/api/javax/servlet/RequestDispatcher.html]

  • 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

  • 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);
         }

  • 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

  • Sending email from aspx-page

    Is there an example on how I can send an email from an
    aspx-page?
    reidarT

    On 09 Jan 2007 in macromedia.dreamweaver, reidarT wrote:
    > Is there an example on how I can send an email from an
    aspx-page?
    There are a number of them. To some extent, it depends on
    what your host
    has installed.
    http://www.google.com/search?q=asp.net+email
    Joe Makowiec
    http://makowiec.net/
    Email:
    http://makowiec.net/email.php

  • Sending email from numbers pages pics etc... Goes to out box

    When sending an email from pages,numbers, pictures etc. it is going to out box and staying there... Help?  When email composed and sent from mail it sends just fine. 

    By the way I have multipule email accounts

  • TS3899 Whenever I send a email from iPad mail app with an attachment from pages or numbers, the receiver is getting only attachment in the email. They are getting the email content. How to troubleshoot this issue.

    Whenever I send a email from iPad mail app with an attachment from pages or numbers, the receiver is getting only attachment in the email. They are getting the email content. How to troubleshoot this issue.

    Someone is probably sending spam with your address forged on the To: line.  Could be one of your old contacts with a Windows machine has a virus that's doing it.  It's also possible your e-mail account has been hacked, though I'd think such a hacker would be a bit more purposeful.
    For more information, see:
    http://www.reedcorner.net/guides/macvirus/is_it_malware.php#spam
    * Disclaimer: links to my pages may give me compensation, and should not be taken as endorsement of my services by Apple.

  • How to call RDF report from JSP page

    Dear all,
    I want to call a RDF report from JSP page. I am creating the JSP page using j developer 10G.
    Can anyone help me out in this case. Is there any tag or procedure or any other way by of that i can perform this work.
    please help and send the reply on [email protected],[email protected]
    thanks
    Ashok

    Hi Ashok,
    You can use rwservlet - nothing really to do with JDeveloper. Once you have report server up and running (hint: read http://download-uk.oracle.com/docs/cd/B14099_19/bi.1012/b14048/toc.htm), you can call a report like this:
    http://server:port/rwservlet?report=my_report.rdf&destype=cache&desformat=html&p_my_parameter=xxx etcHope this helps,
    John

  • How to call cystal report8 report file from jsp page

    hi guys
    present i am using cystal report8 already i am having ReportViewer.jar and ReportviewerBean.jar files
    using that please send me sample code how to call that report from jsp page..
    and how to pass the parameters from jsp page to crystalreport8 report file.
    it was very urgent task to me..so please send sample code on above topic..
    or send me crystalreport8 API
    thanks
    regards

    Hi,
    I also want to work on crystal report but i dont have the ReportViewerBean.jar and ReportViewer.jar. So, please tell from where will i get those jar files.
    Thanks in advanced.

  • How can I send an email from Sharepoint Online using sandbox solution?

    How can I send an email from Sharepoint Online using sandbox solution?
    If possible I do not want to use workflow.
    Is It possible to do it without using workflow?

    hello Steven Andrews,
    when any user sends a message using contact us page in SharePoint online.
    1. We are inserting item in Contact Us List . - This is working fine
    for anonymous users also. We have used Office365 anonymous codeplex wsp and it is working fine. Anonymous user is able to insert new record in the Contact Us List.
    2. Once, new record is inserted in Contact Us list, we want to fire email notifying thanks to the user on his email id as well as to our company x person for notification of new inquiry. 
    We tried using Workflow having impersonation step for  anonymous user but it is not working for Anonymous users. Workflow is able to sent the email if someone logged into system but not working for Anonymous user although workflow is getting started
    but not able to send email although used Imperonsation step.
    We are stuck into implementing second step.

  • HT1277 I can send & receive email from my ipad but for some reason I can no longer do this from my i mac.It keeps telling me that the password is not valid with the imap server.I keep entering the password but it won't accept it.

    I can send & receive email from my ipad but for some reason I can no longer do this from my i mac.It keeps telling me that the password is not valid with the imap server.I keep entering the password but it won't accept it.

    Do you have one, two or more entries in the left colum of Mail.app for your mail server(s)?  That is, do you have your Mail.app set up with either a btinternet entry, with a btyahoo entry, or both?  Or more?
    I'm guessing that you might have one account (btyahoo?) listed for incoming (IMAP server) mail, and with the outbound (SMTP server) mail is configured and named btinternet.
    Based on what little I see posted, it looks like BT uses both btinternet and btyahoo, but I'm not exactly clear on how they have their stuff set up, and their web set gets helpful and tries to help configure my mail — I don't immediately see a single web page with the mail server set-up details.  The BT email client set-up starts here.

Maybe you are looking for