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

Similar Messages

  • How to send an email in jsp

    hei evryone!
    can anyone pls help me on how to send an email in jsp. I mean i have a webpage wherein you submit data , upon submission or after the submit button is clicked i need to send an email to a person regarding the data sumitted on the form , i dunno how to do this, can anyone please help me on how to use Javamail, or can anyone post a sample code or site of a tutorial .. thx!

    There are some quite good examples on the use of Javamail on the Sun website. No, we're not going to write your application for you, unless you're willing to pay consultancy fees in real money.
    http://java.sun.com/products/javamail/index.jsp
    http://java.sun.com/products/javamail/FAQ.html
    http://java.sun.com/products/javamail/reference/techart/index.html

  • How to send ENCRYPTED email from 10v2

    Helllo,
    How to send ENCRYPTED email from 10v2 to end users who will receive their emails from Microsoft Outlook?
    I created a stored procedure to change user passwords. I need to email the users their passwords but the email message has to be encrypted since it contains user passwords. How do I use util_mail to send encrypted messages? The users will pick up their passwords through Microsoft Outlook. Thank you in advance.

    not sure what is the mechanics of decrypting (PGP maybe?)
    I have few tips ...
    1. look at DBMS_CRYPTO package
    2. create JAVA stored procedure (I'm sure there are some good samples to use java for encryption) to encrypt the body (this can be executed from pl/sql)
    3. save the body as a file on unix and encrypt it with unix command (this can be executed from PL/SQL utilizing UTL_FILE and JAVA stored procedure)
    4. forget sending the password in email and save the password on Oracle Apex site and configure access using single sign-on with transparent windows authentication

  • How to send an email from ADF11g.

    Hi,
    How to send an email from ADF11g.can u give example code and send me any link.
    Regards
    AP

    perfect and simple way is to use the java mail api from apache
    very simple, easy to use, and handle all types of emails.
    http://commons.apache.org/email/userguide.html

  • How to send an email from a VI

    Hello..
         I want to know how to send an email from VI. I am using Labview 8.6 . I tried some examples also. But when I run those VIs, I getting errror. It is smtp server error. I dont have any idea about how to change smtp server settings. Can any body tell step by step procedure to accomplish this task.. 
    Further, I need send an attachment with this email... 
    Please help me
    Thanks
    Prashanth
    Solved!
    Go to Solution.

    Hello harold..
               thanks for sending VI. I tried it, but I am getting following error
    Error 1172 occurred at Error calling method System.Net.Mail.SmtpClient.Send of ObjectId handle: 0xCD21184 for obj 0x212E63[System.Net.Mail.SmtpClient] in domain [LabVIEW Domain for Run] and thread 280, (System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
        Inner Exception: System.Net.Mail.SmtpException: Failure sending mail.
        Inner Exception: System.Net.WebException: Unable to connect to the remote server
        Inner Exception: System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it
    ) in GmailLV86.vi
    How can I solve this problem..
    Please let me know.
    Thanks
    Prashanth

  • How to send group emails from ipad

    How to send group emails from ipad

    Thanks.  So matters haven't changed.  Ipad and iohone systems still not make use of the groups created in OSX Contacts, although one can "see" the groups synced through iCloud.  They just do not function as real distribution lists in Mail.
    With the Mailshot app, one creates Mailshot groups with Mailshot group name.  It's as smooth as a work around can get.
    Silly that Apple iOS folks never got around to connecting the contact groups now listed in iOS Contacts through iCloud syncing to also be fully functional in iOS Mail for the purpose of group emailing. 

  • How to send only email from workflow

    Hi Guys,
    I want to send an email from a workflow without sending a notification ... how do i do it ?
    Thanks In advance
    Tom.

    Hi,
    Two possible ways - neither of which I would recommend.
    1 - Write a trigger on the WF_NOTIFICATIONS table, so that if the notification for the process that you require is sent, then you populate the mailer status column to 'spoof' the mailer into thinking that it has already sent it. That should suppress the email.
    2 - Modify the flow to include an activity prior to the notification to change the recipient preferences to not receive email, send the notification, then change the preferences back.
    Email is an "all or nothing" solution - either get email from everything, or get it from nothing. How are they planning on dealing with the notification that they are sent? If they are logging into the application to view the notification, then you could consider sending summary notification emails, and force the users to log into the application to view them all, rather than trying to adopt a half-and-half solution where some things come by email and some only come in the application.
    HTH,
    Matt
    WorkflowFAQ.com - the ONLY independent resource for Oracle Workflow development
    Alpha review chapters from my book "Developing With Oracle Workflow" are available via my website http://www.workflowfaq.com
    Have you read the blog at http://thoughts.workflowfaq.com ?
    WorkflowFAQ support forum: http://forum.workflowfaq.com

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

  • How to Send HTML Email from Webpage?

    Hi Everyone!
    I'm Looking to Send Emails with an Option to Send Text Format (from textfile on Webserver, ex. textfile.txt) or HTML Format (from webpage on Web Server, example: test.html).
    I will include My Current Code at the end of this Q.
    What Code will I need to use to create the Option, extract the data from the .txt file Or HTML File, and send the Content in the Body of the E-mail?
    Also, how can I send the e-mails (both HTML and/or Text Format) to Multiple Recipients by adding the names into the '$email' textbox on the current form?
    Thanks in Advance!

    Which class are u using for the same purpose ?

  • How to send out email from table data every day?

    want to implement email function:
    send out data in email from a table with select everyday
    how to implement it in ASE 12.5?

    You can use the Job Scheduler functionality within ASE or a UNIX OS cron job to cause something to happen at a particular time every day.
    With Job Scheduler, you might have it use xp_cmdshell to execute a script on the OS,
    while cron would just execute the script directly.
    The script would log into ASE, run the select and store the results into a file, then send the file contents.
    A simple example of such a script file might be:
    isql -Usa -Ppassword -o /work/my_output.txt  << EOF
    select * from mydb..mystatus
    go
    EOF
    mailx -s"My Daily Status" bret < /work/my_output.txt
    As the file contains your password, be sure permissions are set so only you can read and execute the file.

  • How to send automatic EMail from SQL or SAP B1

    hi experts as we are using SQL as DB i ned to send E-mails from sap system automatically but from SBO mailer  or Scheduler is not working from my side now i was planning to send emails from SQL can any one help me how to send emails automatically from SAP business one or from SQL

    Hi
    In SQL under Management\Database Mail
    You can configure account you use to send mails from SQL
    Then you can prepare procedure that will send mail
    for example
    EXEC msdb.dbo.sp_send_dbmail
    @profile_name = 'Hurtpol',
    @recipients = '[email protected]',
    @query = 'select isnull(syncherror,'''')  collate polish_ci_as
    from np.dbo.OITM
    where U_SynchStatus=''Failed''',
    --@body = @tresc,
    @subject = 'synch error'
    read about sp_send_dbmail

  • How to send an email from CRM that shows-up as Meeting invite?

    Hi, 
    I want to send an email invitation for a meeting to the contact such that it appears as a meeting invite on Outlook. How can this be achieved?
    I know one way is to create an Appointment, sync it with Outlook, add attendees and send invite. But can we do this from within CRM?
    We have a custom meeting entity and we can add our contacts and employees as attendees. But we want to send an email to all those attendees from within CRM such that it appears as a meeting invite/Appointment.
    Please advise. 
    Thanks, 
    Fahad Ali Shaikh

    If you want to use meeting invites, it needs to be a meeting, not a custom entity.
    You could write code to send an .ics file for the meeting for example, but the point of an Outlook meeting invite is that the organiser can track who has said they are or are not attending, or have not yet replied, for example.
    Note that more recent versions of CRM *do* send invitations out for appointments created in CRM, depending on how you configure your synchonisation (eg using SSS they are automatically sent out).
    Hope this helps.
    Adam Vero, Microsoft Certified Trainer | Microsoft Community Contributor 2011
    UK CRM Guru Blog

  • How to send an email from oracle?

    Hi I want to send email from oracle database.
    i have tried following procedure
    create or replace
    2 PROCEDURE send_mail (p_sender IN VARCHAR2,
    3 p_recipient IN VARCHAR2,
    4 p_message IN VARCHAR2)
    5 as
    6 l_mailhost VARCHAR2(255) := 'aria.us.oracle.com';
    7 l_mail_conn utl_smtp.connection;
    8 BEGIN
    9 l_mail_conn := utl_smtp.open_connection(l_mailhost, 25);
    10 utl_smtp.helo(l_mail_conn, l_mailhost);
    11 utl_smtp.mail(l_mail_conn, p_sender);
    12 utl_smtp.rcpt(l_mail_conn, p_recipient);
    13 utl_smtp.open_data(l_mail_conn );
    14 utl_smtp.write_data(l_mail_conn, p_message);
    15 utl_smtp.close_data(l_mail_conn );
    16 utl_smtp.quit(l_mail_conn);
    17 end;
    and when i execute the following
    begin
    send_mail( '[email protected]',
    '[email protected]',
    'Hello arun' );
    end;
    I get the following errors
    ERROR at line 1:
    ORA-29278: SMTP transient error: 421 Service not available
    ORA-06512: at "SYS.UTL_SMTP", line 21
    ORA-06512: at "SYS.UTL_SMTP", line 97
    ORA-06512: at "SYS.UTL_SMTP", line 139
    ORA-06512: at "TEST.SEND_MAIL", line 8
    ORA-06512: at line 2
    Please help
    Regards
    Arun

    C:\>telnet aria.us.oracle.com 25Only if you work ofr Oracle & start behind their firewall would I expect this to work.
    The SMTP server to which PL/SQL connects needs to be YOUR corporate email (MTA) server & configured to RELAY message.
    Contact your LOCAL postmaster/Network Admin
    NONE of this is related to Oracle RDBMS!

  • How to send an Email from XI

    Hello all,
    Can any body please suggest the procedure to send a mail from XI.
    Help will be appreciated.
    Thanks and best regards,
    Kulwant Singh

    Hi,
    Refer the below weblog.
    Send an attachement
    https://www.sdn.sap.com/irj/sdn/weblogs?blog=/pub/wlg/1685 [original link is broken] [original link is broken] [original link is broken]
    http://help.sap.com/saphelp_nw04/helpdata/en/3c/b4a6490a08cd41a8c91759c3d2f401/content.htm
    /people/prasad.ulagappan2/blog/2005/06/07/mail-adapter-scenarios-150-sap-exchange-infrastructure
    Mail Adapter (XI) - how to implement dynamic mail address
    /people/michal.krawczyk2/blog/2005/03/07/mail-adapter-xi--how-to-implement-dynamic-mail-address
    XI: Sender mail adapter - PayloadSwapBean - Step by step
    /people/michal.krawczyk2/blog/2005/12/18/xi-sender-mail-adapter--payloadswapbean--step-by-step
    Thnx
    Chirag

  • 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

Maybe you are looking for

  • Form is not working after table refresh

    I've made a form and have added pre-insert trigger for the block. And the form is working perfectly fine with no issues. Two new columns have been added to the table and have to be added to the form now. I opened the data block wizard of the form and

  • JDev 10.1.3 Prod Bug in Structure Window when using PL/SQL and Stored Types

    Using JDev 10.1.3 build 3673 When loading/editing a PL/SQL package with code like the following: rec := NEW Record001Row; Where Record001Row is a stored type on the database gives an "Error Expecting ;" in the JDev Structure Window. Once the above li

  • End to End processes in Customer Messaging and Points card

    Dear friends What are the E2E business processes involved in a typical customer messaging and points card scenario for a high street retailer. How best can we define Customer messaging processes? And what is the right way to model these processes if

  • C4C - ERP business partner number range alignment

    Hi all, Is there any way to ensure that business partners created in Cloud for customer get the same ID number in both C4C and ERP? As I understand it the ERP number is not assigned until the business partner is sent from C4C? So actually there are t

  • Copy express add on  sap 8.8 -PLD coping problem

    Dear Experts    While coping the PLD  from one database to another by using copy express ( sap 8.8 PL 00 ) only the empty layout (without any field) was creating. Pleas give the solution. Thanks