473,287 Members | 1,674 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

Help need to send email using java applet in html page

Help please, I try to sending an email from my html page using the java
applet.
but it give error on most of the PC only very few work, what is the error i
make
the java applet show as below

**********************************

package Celcom.Client;

import java.applet.*;
import java.awt.*;
import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;
/**
* Insert the type's description here.
* Creation date: (11/3/2003 5:19:42 PM)
* @author: Administrator
*/
public class SimpleEMail extends Applet {
//User define veriable
private String strSMTPHost = "";
private String strRecipients = "";
private String strFrom = "";
private String strSubject = "";
private String strMessage = "";
/**
* Cleans up whatever resources are being held. If the applet is active
* it is stopped.
*
* @see #init
* @see #start
* @see #stop
*/
public void destroy() {
super.destroy();

// insert code to release resources here
}
/**
* Insert the method's description here.
* Creation date: (11/4/2003 9:44:56 AM)
* @param newMsgLine java.lang.String
*/
protected void displayMsg(String newMsgLine) {
//String strMsg = gettxtMsg().getText();
//strMsg += "\n" + newMsgLine;
//gettxtMsg().setText(strMsg);
}
/**
* Insert the method's description here.
* Creation date: (11/4/2003 9:44:04 AM)
*/
protected void emptyMsg() {
//gettxtMsg().setText("");
}
/**
* Returns information about this applet.
* @return a string of information about this applet
*/
public String getAppletInfo() {
return "SimpleEMail\n" +
"\n" +
"Insert the type's description here.\n" +
"Creation date: (11/3/2003 5:18:15 PM)\n" +
"@author: James Hong\n" +
"";
}
/**
* Insert the method's description here.
* Creation date: (11/3/2003 5:51:20 PM)
* @return java.lang.String
*/
public java.lang.String getFrom() {
return strFrom;
}
/**
* Insert the method's description here.
* Creation date: (11/3/2003 5:51:20 PM)
* @return java.lang.String
*/
public java.lang.String getMessage() {
return strMessage;
}
/**
* Returns parameters defined by this applet.
* @return an array of descriptions of the receiver's parameters
*/
public java.lang.String[][] getParameterInfo() {
String[][] info = {
{"smtphost", "String", ""},
{"recipients","String",""},
{"from", "String", ""},
{"subject","String",""},
{"message", "String", ""}
};
return info;
}
/**
* Insert the method's description here.
* Creation date: (11/3/2003 5:51:20 PM)
* @return java.lang.String
*/
public java.lang.String getRecipients() {
return strRecipients;
}
/**
* Insert the method's description here.
* Creation date: (11/3/2003 5:46:49 PM)
* @return java.lang.String
*/
public java.lang.String getSMTPHost() {
return strSMTPHost;
}
/**
* Insert the method's description here.
* Creation date: (11/3/2003 5:51:20 PM)
* @return java.lang.String
*/
public java.lang.String getSubject() {
return strSubject;
}
/**
* Called whenever the part throws an exception.
* @param exception java.lang.Throwable
*/
private void handleException(java.lang.Throwable exception) {

/* Uncomment the following lines to print uncaught exceptions to stdout */
// System.out.println("--------- UNCAUGHT EXCEPTION ---------");
// exception.printStackTrace(System.out);
}
/**
* Initializes the applet.
*
* @see #start
* @see #stop
* @see #destroy
*/
public void init() {
try {
super.init();
setName("SimpleEMail");
setLayout(new java.awt.BorderLayout());
setSize(209, 21);
setVisible(false);
// user code begin {1}
// strSMTPHost = this.getParameter("smtphost");
// strRecipients = this.getParameter("recipients");
// strFrom = this.getParameter("from");
// strSubject = this.getParameter("subject");
// strMessage = this.getParameter("message");
// user code end
} catch (java.lang.Throwable ivjExc) {
// user code begin {2}
// user code end
handleException(ivjExc);
}
}
/**
* main entrypoint - starts the part when it is run as an application
* @param args java.lang.String[]
*/
public static void main(java.lang.String[] args) {
try {
Frame frame = new java.awt.Frame();
SimpleEMail aSimpleEMail;
Class iiCls = Class.forName("Celcom.Client.SimpleEMail");
ClassLoader iiClsLoader = iiCls.getClassLoader();
aSimpleEMail =
(SimpleEMail)java.beans.Beans.instantiate(iiClsLoa der,"Celcom.Client.SimpleE
Mail");
frame.add("Center", aSimpleEMail);
frame.setSize(aSimpleEMail.getSize());
frame.addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent e) {
System.exit(0);
};
});
frame.show();
java.awt.Insets insets = frame.getInsets();
frame.setSize(frame.getWidth() + insets.left + insets.right,
frame.getHeight() + insets.top + insets.bottom);
frame.setVisible(true);
} catch (Throwable exception) {
System.err.println("Exception occurred in main() of java.applet.Applet");
exception.printStackTrace(System.out);
}
}
/**
* Paints the applet.
* If the applet does not need to be painted (e.g. if it is only a container
for other
* awt components) then this method can be safely removed.
*
* @param g the specified Graphics window
* @see #update
*/
public void paint(Graphics g) {
super.paint(g);

// insert code to paint the applet here
}
/**
* Insert the method's description here.
* Creation date: (11/3/2003 5:52:32 AM)
*/
protected void postMail(String smtphost, 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", "smtp.jcom.net");
props.put("mail.smtp.host", smtphost);

// 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[i]);
}
msg.setRecipients(Message.RecipientType.TO, addressTo);
// Optional : You can also set your custom headers in the Email if you
Want
// msg.addHeader("MyHeaderName", "myHeaderValue");

// Setting the Subject and Content Type
msg.setSubject(subject);
msg.setContent(message, "text/html");
Transport.send(msg);
}
/**
* Comment
*/
public String sendEMail() {
java.util.StringTokenizer stkRecipientsList = null;
String recipients[] = null;
int nCnt = 0;

emptyMsg();
// verify smtp host
displayMsg("SMTP host : " + getSMTPHost());
if (getSMTPHost().trim().equalsIgnoreCase("")){
return "Blank SMTP host.";
}

// verify From EMail
displayMsg("From Email : " + getFrom());
if (getSMTPHost().trim().equalsIgnoreCase("")){
return "Blank from email address.";
}

// verify Recipients EMail
displayMsg("Recipients Email : " + getRecipients());
stkRecipientsList = new java.util.StringTokenizer(getRecipients(), ";");
if (stkRecipientsList.countTokens() == 0){
return "No recipients email found.";
}

// verify Subject
displayMsg("Subject : " + getSubject());

// verify Message
displayMsg("Message body : \n" + getMessage());
recipients = new String[stkRecipientsList.countTokens()];
while(stkRecipientsList.hasMoreTokens()) {
recipients[nCnt] = stkRecipientsList.nextToken();
nCnt += 1;
}

try {
postMail(getSMTPHost(), recipients, getSubject(), getMessage(),
getFrom());
} catch (MessagingException exc) {
return exc.getMessage();
}

return "";
}
/**
* Insert the method's description here.
* Creation date: (11/3/2003 5:51:20 PM)
* @param newFrom java.lang.String
*/
public void setFrom(java.lang.String newFrom) {
strFrom = newFrom;
}
/**
* Insert the method's description here.
* Creation date: (11/3/2003 5:51:20 PM)
* @param newMessage java.lang.String
*/
public void setMessage(java.lang.String newMessage) {
strMessage = newMessage;
}
/**
* Insert the method's description here.
* Creation date: (11/3/2003 5:51:20 PM)
* @param newRecipients java.lang.String
*/
public void setRecipients(java.lang.String newRecipients) {
strRecipients = newRecipients;
}
/**
* Insert the method's description here.
* Creation date: (11/3/2003 5:46:49 PM)
* @param newSMTPHost java.lang.String
*/
public void setSMTPHost(java.lang.String newSMTPHost) {
strSMTPHost = newSMTPHost;
}
/**
* Insert the method's description here.
* Creation date: (11/3/2003 5:51:20 PM)
* @param newSubject java.lang.String
*/
public void setSubject(java.lang.String newSubject) {
strSubject = newSubject;
}
/**
* Called to start the applet. You never need to call this method
* directly, it is called when the applet's document is visited.
* @see #init
* @see #stop
* @see #destroy
*/
public void start() {
super.start();

// insert any code to be run when the applet starts here
}
/**
* Called to stop the applet. It is called when the applet's document is
* no longer on the screen. It is guaranteed to be called before destroy()
* is called. You never need to call this method directly.
* @see #init
* @see #start
* @see #destroy
*/
public void stop() {
super.stop();

// insert any code to be run when the applet is stopped here
}
}
********************************
and the html page as below
********************************

<HTML>
<HEAD>
<TITLE>SimpleEMail</TITLE>
<script language="JavaScript">
function sendingEMail(){
window.SimpleEMail.setSMTPHost(window.smtphost.val ue);
window.SimpleEMail.setFrom(window.fromemail.value) ;
window.SimpleEMail.setRecipients(window.toemail.va lue);
window.SimpleEMail.setSubject(window.subject.value );
window.SimpleEMail.setMessage(window.message.inner Text);
window.SimpleEMail.sendEMail();
alert("done");
}
</script>
</HEAD>
<BODY>
<H1>SimpleEMail</H1>
<P>
<APPLET style="LEFT: 0px; WIDTH: 144px; TOP: 0px; HEIGHT: 14px" height=14
archive=CelcomClient.jar width=144 code=Celcom.Client.SimpleEMail.class
name=SimpleEMail>
<PARAM NAME="from" VALUE="te**@mail.com">
<PARAM NAME="smtphost" VALUE="mango">
<PARAM NAME="recipients" VALUE="te**@mail.com;">
<PARAM NAME="subject" VALUE="Testing">
<PARAM NAME="message" VALUE="Hello">
</APPLET>
</P>
<P>
<TABLE>
<tr>
<td>Smtp Host</td><td align=middle> : </td>
<td><INPUT style="WIDTH: 255px; HEIGHT: 22px" size=32 id=smtphost
name=smtphost value=smtp.mail.com></td>
<tr>
<tr>
<td>From Email</td><td align=middle> : </td>
<td><INPUT style="WIDTH: 255px; HEIGHT: 22px" size=32 id=fromemail
name=fromemail value=te**@mail.com></td>
<tr>
<tr>
<td>To Email</td><td align=middle> : </td>
<td><INPUT style="WIDTH: 255px; HEIGHT: 22px" size=32 id=toemail
name=toemail value=te**@mail.com;></td>
<tr>
<tr>
<td>Subject</td><td align=middle> : </td>
<td><INPUT style="WIDTH: 255px; HEIGHT: 22px" size=32 id=subject
name=subject value=Testing></td>
<tr>
<tr>
<td valign=top>Message</td><td align=middle valign=top> : </td>
<td><TEXTAREA id=message style="WIDTH: 253px; HEIGHT: 88px" name=message
rows=4 cols=27>Hello</TEXTAREA></td>
<tr>
<tr>
<td align=middle colspan=3><INPUT type=button value="Send Mail"
onclick="javascript:sendingEMail()" id=button1 name=button1><td></td>
</tr>
</TABLE>
</P>
</BODY>
</HTML>

********************************
--
Best Regards,
James Hong
Jul 17 '05 #1
0 9838

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: apchar | last post by:
I am trying to use php as a kind of servlet to act as a middle man between a java applet and mysql. I know java has jdbc but it's flakey and painful. php access to mysql is much nicer. So I have:...
1
by: Dan | last post by:
Hello, I am trying to read and write to an Excel file via my Java applet. I have done so successfully on several simple Excel files that simply had data cells without many complicated equations...
0
by: Emre Sevinc | last post by:
Hi, I'm simply trying to run that small bioinformatic Java utility, locally on my computer: "Chromatogram Applet, Release 1, 6/30/96 by Eugen Buehler" I don't have problem with Java...
8
by: DKM | last post by:
Here are the source code files to a Java applet that utilizes LiveConnect to communicate with Javascript, and the HTML file. The thing works both in IE 6.0 and FireFox 1.4. but with some...
7
by: Wayne Gibson | last post by:
Hi, I need some advise with a java applet. I am nearing completing of the project and am getting a little concerned how long it is taking for the applet to load. I have developed the java applet...
16
by: pamelafluente | last post by:
I am still working with no success on that client/server problem. I need your help. I will submit simplified versions of my problem so we can see clearly what is going on. My model: A client...
1
by: Pratyush | last post by:
There is a Java Applet which digitally signs files after taking private key from a smart card.This applet takes external files. I want to do this "Generate digital signature of a web page with...
8
by: Richard Maher | last post by:
Hi, I am in a mouseup event for button A and I'd like to disable=false button B before starting some work. Is there anyway that an event for button B can then fire before my event processing for...
1
by: Fool | last post by:
Ok I was doing this project but now Im halfway stuck. This project contains 3 class at the moment. Im mainly trying to make this applet like the game pong. I have the paddle and a ball and background...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.