JSP and dynamic email from form on web page

I fairly new to JSP, I trying to create a form the will automatically send an email once an insert button is clicked. But in the email there will be to dynamic fields, like SSN and Last Name. These would be passed in from to textboxes on the page. Here is the code I have so far. Thanks for any help
Joaquin
<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %>
<%
// Set Session Variable To Value Of Form Element - JSPSessions_102
session.setAttribute
("SSN",
request.getParameter
("txtSSN"));
// Send Email From Web Page - JSPMail_101
Properties props = new Properties();
props.put("smtp.sbcglobal.yahoo.com", "smtp.sbcglobal.yahoo.com");
Session s = Session.getInstance(props,null);
MimeMessage message = new MimeMessage(s);
InternetAddress from = new InternetAddress("[email protected]");
message.setFrom(from);
InternetAddress to = new InternetAddress("[email protected]");
message.addRecipient(Message.RecipientType.TO, to);
message.setSubject("New Employee.");
message.setText("This is a test ");
Transport.send(message);
%>
<%@ include file="Connections/conCap2.jsp" %>
<%
// *** Restrict Access To Page: Grant or deny access to this page
String MM_authorizedUsers="";
String MM_authFailedURL="loginFailedFac.htm";
boolean MM_grantAccess=false;
if (session.getValue("MM_Username") != null && !session.getValue("MM_Username").equals("")) {
if (true || (session.getValue("MM_UserAuthorization")=="") ||
(MM_authorizedUsers.indexOf((String)session.getValue("MM_UserAuthorization")) >=0)) {
MM_grantAccess = true;
if (!MM_grantAccess) {
String MM_qsChar = "?";
if (MM_authFailedURL.indexOf("?") >= 0) MM_qsChar = "&";
String MM_referrer = request.getRequestURI();
if (request.getQueryString() != null) MM_referrer = MM_referrer + "?" + request.getQueryString();
MM_authFailedURL = MM_authFailedURL + MM_qsChar + "accessdenied=" + java.net.URLEncoder.encode(MM_referrer);
response.sendRedirect(response.encodeRedirectURL(MM_authFailedURL));
return;
%>
<%
// *** Edit Operations: declare variables
// set the form action variable
String MM_editAction = request.getRequestURI();
if (request.getQueryString() != null && request.getQueryString().length() > 0) {
MM_editAction += "?" + request.getQueryString();
// connection information
String MM_editDriver = null, MM_editConnection = null, MM_editUserName = null, MM_editPassword = null;
// redirect information
String MM_editRedirectUrl = null;
// query string to execute
StringBuffer MM_editQuery = null;
// boolean to abort record edit
boolean MM_abortEdit = false;
// table information
String MM_editTable = null, MM_editColumn = null, MM_recordId = null;
// form field information
String[] MM_fields = null, MM_columns = null;
%>
<%
// *** Insert Record: set variables
if (request.getParameter("MM_insert") != null && request.getParameter("MM_insert").toString().equals("FacSupPo")) {
MM_editDriver = MM_conCap2_DRIVER;
MM_editConnection = MM_conCap2_STRING;
MM_editUserName = MM_conCap2_USERNAME;
MM_editPassword = MM_conCap2_PASSWORD;
MM_editTable = "facsupport";
MM_editRedirectUrl = "insertOk.jsp";
String MM_fieldsStr = "txtSSN|value|txtLstNm|value|DkCHDo|value|doCompDK|value|GenOffSupDo|value";
String MM_columnsStr = "SSN|',none,''|LstName|',none,''|DeskChair|',none,''|CompDsk|',none,''|GenOffSup|',none,''";
// create the MM_fields and MM_columns arrays
java.util.StringTokenizer tokens = new java.util.StringTokenizer(MM_fieldsStr,"|");
MM_fields = new String[tokens.countTokens()];
for (int i=0; tokens.hasMoreTokens(); i++) MM_fields[i] = tokens.nextToken();
tokens = new java.util.StringTokenizer(MM_columnsStr,"|");
MM_columns = new String[tokens.countTokens()];
for (int i=0; tokens.hasMoreTokens(); i++) MM_columns[i] = tokens.nextToken();
// set the form values
for (int i=0; i+1 < MM_fields.length; i+=2) {
MM_fields[i+1] = ((request.getParameter(MM_fields)!=null)?(String)request.getParameter(MM_fields[i]):"");
// append the query string to the redirect URL
if (MM_editRedirectUrl.length() != 0 && request.getQueryString() != null) {
MM_editRedirectUrl += ((MM_editRedirectUrl.indexOf('?') == -1)?"?":"&") + request.getQueryString();
%>
<%
// *** Insert Record: construct a sql insert statement and execute it
if (request.getParameter("MM_insert") != null) {
// create the insert sql statement
StringBuffer MM_tableValues = new StringBuffer(), MM_dbValues = new StringBuffer();
for (int i=0; i+1 < MM_fields.length; i+=2) {
String formVal = MM_fields[i+1];
String elem;
java.util.StringTokenizer tokens = new java.util.StringTokenizer(MM_columns[i+1],",");
String delim = ((elem = (String)tokens.nextToken()) != null && elem.compareTo("none")!=0)?elem:"";
String altVal = ((elem = (String)tokens.nextToken()) != null && elem.compareTo("none")!=0)?elem:"";
String emptyVal = ((elem = (String)tokens.nextToken()) != null && elem.compareTo("none")!=0)?elem:"";
if (formVal.length() == 0) {
formVal = emptyVal;
} else {
if (altVal.length() != 0) {
formVal = altVal;
} else if (delim.compareTo("'") == 0) {  // escape quotes
StringBuffer escQuotes = new StringBuffer(formVal);
for (int j=0; j < escQuotes.length(); j++)
if (escQuotes.charAt(j) == '\'') escQuotes.insert(j++,'\'');
formVal = "'" + escQuotes + "'";
} else {
formVal = delim + formVal + delim;
MM_tableValues.append((i!=0)?",":"").append(MM_columns[i]);
MM_dbValues.append((i!=0)?",":"").append(formVal);
MM_editQuery = new StringBuffer("insert into " + MM_editTable);
MM_editQuery.append(" (").append(MM_tableValues.toString()).append(") values (");
MM_editQuery.append(MM_dbValues.toString()).append(")");
if (!MM_abortEdit) {
// finish the sql and execute it
Driver MM_driver = (Driver)Class.forName(MM_editDriver).newInstance();
Connection MM_connection = DriverManager.getConnection(MM_editConnection,MM_editUserName,MM_editPassword);
PreparedStatement MM_editStatement = MM_connection.prepareStatement(MM_editQuery.toString());
MM_editStatement.executeUpdate();
MM_connection.close();
// redirect with URL parameters
if (MM_editRedirectUrl.length() != 0) {
response.sendRedirect(response.encodeRedirectURL(MM_editRedirectUrl));
return;
%>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<form action="<%=MM_editAction%>" method="POST" name="FacSupPo" id="FacSupPo">
<table width="575" border="1">
<tr>
<td><div align="center">
<h2>Facilities Support Form Submition</h2>
<p><strong>Please Check all of the Fields</strong></p>
</div></td>
</tr>
</table>
<p>  </p>
<p>Please Enter Employees SSN </p>
<p>
<input name="txtSSN" type="text" id="txtSSN" value="<%= ((request.getParameter("txtSSN")!=null)?request.getParameter("txtSSN"):"") %>"readonly="true">
</p>
<p>Enter Last Name</p>
<p>
<input name="txtLstNm" type="text" id="txtLstNm" value="<%= ((request.getParameter("txtLstNm")!=null)?request.getParameter("txtLstNm"):"") %>"readonly="true">
</p>
<table width="575" border="1" cellspacing="0" bordercolor="#000000">
<!--DWLayoutTable-->
<tr bgcolor="#FF0000">
<td height="23" colspan="3"> </td>
</tr>
<tr>
<td width="179" height="102" valign="top">
<p>
<input name="DkCHDo" type="text" id="DkCHDo" value="<%= ((request.getParameter("DkCHDo")!=null)?request.getParameter("DkCHDo"):"") %>"size="9" readonly="true">
</p>
<p>Desk & Desk Chair</p>
</td>
<td width="191"><p>
<input name="doCompDK" type="text" id="doCompDK" value="<%= ((request.getParameter("doCompDK")!=null)?request.getParameter("doCompDK"):"") %>"size="9" readonly="true">
</p>
<p>Computer Desk</p></td>
<td width="191"><p>
<input name="GenOffSupDo" type="text" id="GenOffSupDo" value="<%= ((request.getParameter("GenOffSupDo")!=null)?request.getParameter("GenOffSupDo"):"") %>"size="9" readonly="true">
</p> <p>General Office Supplies</p>
</td>
</tr>
<tr>
<td height="31" colspan="3" valign="top">
<div align="center">
<p>
<input type="submit" value=" Insert " name="Submit">
</p>
<p>Back </p>
</div>
</td>
</tr>
</table>
<p> </p>
<input type="hidden" name="MM_insert" value="FacSupPo">
</form>
</body>
</html>

This how I send out e-mail(s)
'emailBean
import java.io.*;
import java.net.Socket;
import java.net.SocketException;
public class EMailBean {
     private Socket socket;
     private OutputStreamWriter outputStreamWriter;
     private BufferedReader bufferedReader;
     public void start( String subject, String message, String from, String to ) {
          try {
               System.out.println( "Connection to smtp.host.com..." );
               this.socket = new Socket( "smtp.host.com", 25 );
               this.outputStreamWriter = new OutputStreamWriter( this.socket.getOutputStream() );
               this.bufferedReader = new BufferedReader( new InputStreamReader( this.socket.getInputStream() ) );
               System.out.println( "Connected!" );
               System.out.println( "From server: " + bufferedReader.readLine() );
               send( "helo smtp.host.com" );
               send( "MAIL FROM:<" + from + ">" );
               send( "RCPT TO:<" + to + ">" );
               send( "DATA" );
               send("Subject:"+subject+"\r\n\r\n"+message + "\r\n.\r\n" );
               this.outputStreamWriter.close();
               this.bufferedReader.close();
               this.socket.close();
          catch( Exception e ) {
               System.err.println( "Error: " + e.getMessage() );
               e.printStackTrace();
     private void send( String sendMe ) throws Exception {
          System.out.println( "To server: " + sendMe );
          this.outputStreamWriter.write( sendMe + "\r\n" );
          this.outputStreamWriter.flush();
          System.out.println( "From server: " + this.bufferedReader.readLine() );
}And the .jsp looks like:
<jsp:useBean id="mailBean" scope="request" class="EMailBean" />
<%
try {
String date = activateBean.doQuery();
String from = "[email protected]";
String to = "[email protected]";
String subject = "Myserverspy - Activation";
String emsg = "Dear " + to + ",";
emsg += "\nsome text here, maybe recive some variables.";
mailBean.start(subject, emsg, from, to);
%>
E-mail has been sent
<%
catch(Exception exp){
     System.out.println("Exception: "+exp);
%>Just insert the parameters into the emsg string.
Andreas

Similar Messages

  • Unable to send web content emails from mail as web page since upgrading to the new OS X 10.9

    I am no longer able to send web content emails from mail as web page. The images / layout no longer transmit. This started when I upgraded to the new OS X 10.9. The emails appear correctly in the orginal message prior to sending but once they are sent all the images and layout are removed. The sent message folder shows the emails in the changed versions vs what the draft showed prior to sending. If the webpage is only an image my final sent message will only show an empty box with an question mark.

    Hold down the option key and select
     ▹ System Information...
    from the menu bar. In the window that opens, select
    Hardware ▹ USB
    from the list on the left. On the right you should now see a list of all connected USB devices, as well as some built-in components. Is the device shown?

  • Sending an email from forms

    hi all,
    i need your help.i.e how to send an email from forms .we actually want that facility in our project.we are trying for that but not yet geting .please help me giving information about email in forms.
    thank you in advance

    If you are using Forms on the web, one of the most easiest way to do it is to use the Java mailing support from sun. You can load it into the rdbms 8i or later and use it. There is a step by stepp detailed description on
    www.oracle.com > publications > Oracle Magazine > Ask Tom. If you just type java mail it will be between the first ten I suppose, it's a popular topic.
    HTH,
    Tamas

  • Reports 9i Printing from Forms with WEB.SHOW_DOCUMENT

    I want to print a Report from Forms via WEB.SHOW_DOCUMENT directly to the printer and it works fine.
    But every time i print it from my web application a new browser-windows opens and shows a message "Printed successfully" or something like that. If I start the printjob again nothing happens - if I press the Browser-Refresh-Button in the new Browser-Windows with the Message ("Printed Successfully") it prints.
    So now I have 2 questions:
    a) How can I disable the "Printed successfully"-Message
    b) What hava I to do that I not must press on the Refresh-Button to start the printing again
    I hope I hava explained my problem clearly. 4
    Here ist the complet WEB.SHOW_DOCUMENT-Command I fire in Forms when a Button is pressed:
    WEB.SHOW_DOCUMENT('http://mymachine:8888/reports/rwservlet?report=testreport.rdf&destype=printer&desname=\\NTS32\VZ_D3&desformat=html&userid='|| sUser ||'/'|| sPW ||'@'|| sDB,'_blank');      
    Many thanx for your help!
    Regards
    Marc

    Hello,
    for the problem:
    b) What hava I to do that I not must press on the Refresh-Button to start the printing again
    may be it just a setting in your Browser ?
    For Internet Explorer :
    go to I.E General Options screen. click on settings button and choose
    "Every visit to the page " option.
    Regards

  • Sending email from forms using 'from'

    I'm trying to send an email from forms. It goes well, but I like to use the 'from' field from Outlook. How can I use it in OLE? I have searched everywhere, but can't find it.
    It seems to me it is something like the way you do with BCC and CC options, but I haven't found a way to do the same thing with the From field. Can anyone help?
    Thanks,
    Pauline Kooy

    Fabrizio,
    Are you just sending the Line Feed character 'CHR(10)"? I typically send the Carrage Return character 'CHR(13)' as well. I'll create a variable called CRLF and assign the Carrage Return and Line Feed characters to this variable. Then reference the CRLF variable when I want to embed a new line.
    For example:
    DECLARE
       crlf         VARCHAR2(2) := chr(13)||chr(10);
       v_msg_body   VARCHAR2(2000);
    BEGIN
       v_msg_body := 'lots of text here'||crlf;
    END;Hope this helps.
    Craig...

  • Send email from forms

    Can anybody send me a code how to send an email from forms
    with attachement for multiple users
    I am using oracle 8i and forms 6i
    My mail application is Novel group wise
    Thanks for your help

    Oracle Reports can be run directly to email.
    Check out the DESTYPE parameter.
    To send emails you can use a call to Java Mail using the Java importer. There is a sample form for this in the Oracle9i Forms demos. This should work in 6i also.
    You might also be able to use email from the database with the UTL_SMTP package:
    http://otn.oracle.com/sample_code/tech/pl_sql/htdocs/maildemo8i_sql.txt

  • Eudora Email from Forms

    We are trying to send email from Forms (background not interactively). We use Eudora as a standard mail application. I am trying to use OLE Automation to send mails as I have to attach Word documents to the mail. There are sample code in Metalink for OLE automation of Outlook but not for Eudora. I'm not even sure if Eudora is an OLE server application. I would appreciate any kind of help and suggestions here.
    Thx
    --Shyam                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by jilla:
    I want to send email from forms 45 .
    how can I do it.
    appreciate any help on this<HR></BLOCKQUOTE>
    To send the mail from within a program unit/trigger, you will have to find out the mail batch command for the mail program that you are using eg. Microsoft Mail. If you are not sure, contact whoever created the mail program. Next, use TEXT_IO (built-in package) or some other method to write to the 'control' file that will be the email file you will send. Once you have done this you will need to invoke the HOST command, passing the mail batch command as a parameter to it.
    It is possible to write to an error file to see why the email was not sent, if this so happens. Again this file (any name you like to give it) will be a parameter to the mail batch command.
    To test if the mail was sent, write code like the following:
    procedure send_mail is
    l_file text_io.file_type;
    l_buffer varchar2(2000);
    l_mail_command varchar2(1000);
    begin
    /* Send mail */
    host(l_mail_command);
    /* Check if mail was sent */
    l_file := text_io.fopen('c:\temp\mailerr.err','r');
    text_io.get_line(l_file,l_buffer);
    /* If there is data in this file display message to user, using an alert for example */
    exception
    when no_data_found
    then
    text_io.fclose(l_file);
    end;
    One other point. When you are creating your 'control' file, make sure you precede the email address of the recipient with 'SMTP:'.
    I hope this helps.

  • How can i send emails from forms

    I need to be able to send emails from forms 6.(assuming the pc is running Outlook) What is the best way of doing this? Would OLE or DDE control of Outlook be the easiest method?
    If anyone has done this please let me know.

    See:
    iOS: Unable to send or receive email
    I would Google for:
    setup verizon email on phone
    for the settings to use.

  • I moved from NJ to Puerto Rico recently and the emails from Apple are now arriving in Spanish.  Please advise.  Thanks.

    I moved from NJ to Puerto Rico recently and the emails from Apple are now arriving in Spanish.  Please advise.  Thanks.

    HI, cabrinii. 
    This sounds like your language preference is set to Spanish on your Apple ID.  I would go toMy Apple ID, Manage Your Apple ID and change the language and contact preferences.
    Cheers,
    Jason H.

  • How do i send a html email from office outlook web access?

    how do i send a html email from office outlook web access?

        glenholmes,
    You've come to the right place for help. Sorry to hear that you have had hard time with your Gmail app lately. What steps have you tried to get this to work? We want to ensure that you are able to start sending those messages right away.
    ErinW_VZW
    Follow us on Twitter @VZWSupport

  • Email from forms 45

    I want to send email from forms 45 .
    how can I do it.
    appreciate any help on this

    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by jilla:
    I want to send email from forms 45 .
    how can I do it.
    appreciate any help on this<HR></BLOCKQUOTE>
    To send the mail from within a program unit/trigger, you will have to find out the mail batch command for the mail program that you are using eg. Microsoft Mail. If you are not sure, contact whoever created the mail program. Next, use TEXT_IO (built-in package) or some other method to write to the 'control' file that will be the email file you will send. Once you have done this you will need to invoke the HOST command, passing the mail batch command as a parameter to it.
    It is possible to write to an error file to see why the email was not sent, if this so happens. Again this file (any name you like to give it) will be a parameter to the mail batch command.
    To test if the mail was sent, write code like the following:
    procedure send_mail is
    l_file text_io.file_type;
    l_buffer varchar2(2000);
    l_mail_command varchar2(1000);
    begin
    /* Send mail */
    host(l_mail_command);
    /* Check if mail was sent */
    l_file := text_io.fopen('c:\temp\mailerr.err','r');
    text_io.get_line(l_file,l_buffer);
    /* If there is data in this file display message to user, using an alert for example */
    exception
    when no_data_found
    then
    text_io.fclose(l_file);
    end;
    One other point. When you are creating your 'control' file, make sure you precede the email address of the recipient with 'SMTP:'.
    I hope this helps.

  • Help: how to send emails from FORMS?

    Are there simple steps to send emails from FORMS?
    Thank you in advance.
    Jimmy

    I'm sure there are many ways to send emails from Forms. Personally I never had to do this, but I can imagine following ways.
    a) use UTL_SMTP-Package to send the email via your database
    b) use a Java-Call
    Peter

  • I have an iMac desk top, iPad, and two iPhones. Someone (a family relative) has somehow copied text messages, and possibly emails from our iPhones, and sent them to other people. He has had access to my wife's iPhone numerous times. Can I check our iPhone

    I have an iMac desk top, iPad, and two iPhones. Someone (a family relative) has somehow copied text messages, and possibly emails from our iPhones, and sent them to other people. He has had access to my wife's iPhone numerous times. Can I check our iPhones to detect any surveillance apps(bugs) on them?

    Whose Apple ID are you using? It sounds like whoever co-opted the account may have changed the security questions as well.
    Follow the instructions here: http://support.apple.com/kb/HT5665
    What should I do if I don't remember the answers to my Apple ID security questions?
    Try answering them at least once to see if you can get them right, even if you are not sure you remember the answers to your security questions.
    If you are confident you can't remember them, try one of the following:
    If you have three security questions and a rescue email address
    sign in to My Apple ID and select the Password and Security tab to send an email to your rescue email address to reset your security questions and answers. 
    If you have one security question and you know your Apple ID passwordsign in to My Apple ID and select the Password and Security tab to reset your security question.
    If you have one security question, but don't remember your Apple ID password
    contact Apple Support for assistance. Learn more about creating a temporary support PIN to help Apple confirm your identity when you contact Apple Support.
    Note: If you have forgotten your password and answer your security questions incorrectly too many times in a row, you will be unable to try to answer your security questions for a period of time. During that time you will not be able to reset your password and will not have access to your account.

  • HT201364 I recently installed Yosemite from Mavericks.  I find that Yosemite is slowing me down and causing havoc on my home web page.  How do uninstall Yosemite and get back to Mavericks?

    I recently installed Yosemite from Mavericks.  I find that Yosemite is slowing me down and causing havoc on my home web page.  How do uninstall Yosemite and get back to Mavericks?

    kenmac1969 wrote:
    I'm gonna jump in as I have similar issues with Yosemite.
    My two old white MacBooks run perfect with Snow leopard, but my 2011 17" i7 Macbook Pro is a dead slug with yosimite installed.
    Tried the start with C held down, also with option held down.  All it does is beeps at me three times, then again three times..... 
    I want to remove yosimite and install Snow leopard from dvd as yosimite runs worse than a Windows OS.
    Can it be done, what do I need to do please?
    Examples of faults,  even with a 1tb solid state drive and 16 gig of ram, it is incredibly slow.  Took four hours to install Logic 8 last night, I still have to reinstall logic 9 upgrade.   On the White MacBooks I got both 8 and 9 installed in under an hour and a half all up.
    Beeping on startup means failed RAM.
    Slowness is usually caused by incompatible third-party system modifications.

  • How to copy and paste text from one photo book page to another.

    hello,i downloaded this software 2days ago,and i've been having so much fun with it. pls i need help on how to copy and paste text from one photo book page to another. Secondly how to copy my completed photo book pages project to another laptop for printing. thanks
    This question was solved.
    View Solution.

    Hi DG.
    The easiest way to copy an HP Photo Creations project to another computer is to click the Share button. That will upload the project to the Web and give you a link you can paste into an email. Clicking the link on the other computer allows you to download the project and personalize it. This quick video shows the process. (The screen looks slightly different now, but the concept is the same.)
    Another way to share a project is copy the project folder to a thumb drive. Look in Documents/HP Photo Creations/My Things to find your saved projects.
    Our customer support team would be happy to walk you through the process. Contact them at [email protected]
    Hope this helps,
    RocketLife 
    RocketLife, developer of HP Photo Creations
    » Visit the HP Photo Creations Facebook page — news, tips, and inspiration
    » See the HP Photo Creations video tours — cool tips in under 2 minutes
    » Contact Customer Support — get answers from the experts

Maybe you are looking for

  • Memup hard disc does not show in Finder

    I have attached a Memup 250GB hard disk by USB to my MBP. The disk does not show up in Finder, nor in Disk Utility. The disk works fine if I plug it into a PC. I have formatted it on the PC to FAT. Any suggestions on how I can get it to work on my MB

  • Problem in table locking while running the parallel jobs (deadlock?)

    Hi, I am trying to delete the entried from a custom table. If I schedule the parallel jobs, I am getting the following dump while deleting the entries from table. This is happening for custom table ( in CRM system). Exception : DBIF_RSQL_SQL_ERROR An

  • Application Mime File Type Preferences

    I'm stumped! I've gone through the entire user preferences, application support files, and library files and still cannot locate which file is containing the settings for mime type application association with .php files. I am having an issue with Fi

  • Macbook pro logs plenty of errors on Airport

    I run a home network composed of an Airport Extreme and an Airport Express associated in WDS, and a dozen machines coming and going daily. We recently added a Macbook pro which behaved poorly from the start, with e. g. much longer pings than everyone

  • Start-up drive full - when its not

    Yesterday I rebuilt my xserve, with leopard OSx server. I've just got a message saying that the start-up drive is full, and when I get info on the drive, it is showing it as full. However, I've only installed the OS, nothing else! Not only that, when