473,729 Members | 2,243 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.inte rnet.*;
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.Strin g
*/
protected void displayMsg(Stri ng newMsgLine) {
//String strMsg = gettxtMsg().get Text();
//strMsg += "\n" + newMsgLine;
//gettxtMsg().set Text(strMsg);
}
/**
* Insert the method's description here.
* Creation date: (11/4/2003 9:44:04 AM)
*/
protected void emptyMsg() {
//gettxtMsg().set Text("");
}
/**
* Returns information about this applet.
* @return a string of information about this applet
*/
public String getAppletInfo() {
return "SimpleEMai l\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.Strin g
*/
public java.lang.Strin g getFrom() {
return strFrom;
}
/**
* Insert the method's description here.
* Creation date: (11/3/2003 5:51:20 PM)
* @return java.lang.Strin g
*/
public java.lang.Strin g getMessage() {
return strMessage;
}
/**
* Returns parameters defined by this applet.
* @return an array of descriptions of the receiver's parameters
*/
public java.lang.Strin g[][] getParameterInf o() {
String[][] info = {
{"smtphost", "String", ""},
{"recipients"," String",""},
{"from", "String", ""},
{"subject","Str ing",""},
{"message", "String", ""}
};
return info;
}
/**
* Insert the method's description here.
* Creation date: (11/3/2003 5:51:20 PM)
* @return java.lang.Strin g
*/
public java.lang.Strin g getRecipients() {
return strRecipients;
}
/**
* Insert the method's description here.
* Creation date: (11/3/2003 5:46:49 PM)
* @return java.lang.Strin g
*/
public java.lang.Strin g getSMTPHost() {
return strSMTPHost;
}
/**
* Insert the method's description here.
* Creation date: (11/3/2003 5:51:20 PM)
* @return java.lang.Strin g
*/
public java.lang.Strin g getSubject() {
return strSubject;
}
/**
* Called whenever the part throws an exception.
* @param exception java.lang.Throw able
*/
private void handleException (java.lang.Thro wable exception) {

/* Uncomment the following lines to print uncaught exceptions to stdout */
// System.out.prin tln("--------- UNCAUGHT EXCEPTION ---------");
// exception.print StackTrace(Syst em.out);
}
/**
* Initializes the applet.
*
* @see #start
* @see #stop
* @see #destroy
*/
public void init() {
try {
super.init();
setName("Simple EMail");
setLayout(new java.awt.Border Layout());
setSize(209, 21);
setVisible(fals e);
// user code begin {1}
// strSMTPHost = this.getParamet er("smtphost") ;
// strRecipients = this.getParamet er("recipients" );
// strFrom = this.getParamet er("from");
// strSubject = this.getParamet er("subject");
// strMessage = this.getParamet er("message");
// user code end
} catch (java.lang.Thro wable 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.Strin g[]
*/
public static void main(java.lang. String[] args) {
try {
Frame frame = new java.awt.Frame( );
SimpleEMail aSimpleEMail;
Class iiCls = Class.forName(" Celcom.Client.S impleEMail");
ClassLoader iiClsLoader = iiCls.getClassL oader();
aSimpleEMail =
(SimpleEMail)ja va.beans.Beans. instantiate(iiC lsLoader,"Celco m.Client.Simple E
Mail");
frame.add("Cent er", aSimpleEMail);
frame.setSize(a SimpleEMail.get Size());
frame.addWindow Listener(new java.awt.event. WindowAdapter() {
public void windowClosing(j ava.awt.event.W indowEvent e) {
System.exit(0);
};
});
frame.show();
java.awt.Insets insets = frame.getInsets ();
frame.setSize(f rame.getWidth() + insets.left + insets.right,
frame.getHeight () + insets.top + insets.bottom);
frame.setVisibl e(true);
} catch (Throwable exception) {
System.err.prin tln("Exception occurred in main() of java.applet.App let");
exception.print StackTrace(Syst em.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 MessagingExcept ion
{
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.getDefa ultInstance(pro ps, null);
session.setDebu g(debug);

// create a message
Message msg = new MimeMessage(ses sion);

// set the from and to address
InternetAddress addressFrom = new InternetAddress (from);
msg.setFrom(add ressFrom);

InternetAddress[] addressTo = new InternetAddress[recipients.leng th];
for (int i = 0; i < recipients.leng th; i++)
{
addressTo[i] = new InternetAddress (recipients[i]);
}
msg.setRecipien ts(Message.Reci pientType.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.Strin gTokenizer stkRecipientsLi st = null;
String recipients[] = null;
int nCnt = 0;

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

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

// verify Recipients EMail
displayMsg("Rec ipients Email : " + getRecipients() );
stkRecipientsLi st = new java.util.Strin gTokenizer(getR ecipients(), ";");
if (stkRecipientsL ist.countTokens () == 0){
return "No recipients email found.";
}

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

// verify Message
displayMsg("Mes sage body : \n" + getMessage());
recipients = new String[stkRecipientsLi st.countTokens( )];
while(stkRecipi entsList.hasMor eTokens()) {
recipients[nCnt] = stkRecipientsLi st.nextToken();
nCnt += 1;
}

try {
postMail(getSMT PHost(), recipients, getSubject(), getMessage(),
getFrom());
} catch (MessagingExcep tion exc) {
return exc.getMessage( );
}

return "";
}
/**
* Insert the method's description here.
* Creation date: (11/3/2003 5:51:20 PM)
* @param newFrom java.lang.Strin g
*/
public void setFrom(java.la ng.String newFrom) {
strFrom = newFrom;
}
/**
* Insert the method's description here.
* Creation date: (11/3/2003 5:51:20 PM)
* @param newMessage java.lang.Strin g
*/
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.Strin g
*/
public void setRecipients(j ava.lang.String newRecipients) {
strRecipients = newRecipients;
}
/**
* Insert the method's description here.
* Creation date: (11/3/2003 5:46:49 PM)
* @param newSMTPHost java.lang.Strin g
*/
public void setSMTPHost(jav a.lang.String newSMTPHost) {
strSMTPHost = newSMTPHost;
}
/**
* Insert the method's description here.
* Creation date: (11/3/2003 5:51:20 PM)
* @param newSubject java.lang.Strin g
*/
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>SimpleEM ail</TITLE>
<script language="JavaS cript">
function sendingEMail(){
window.SimpleEM ail.setSMTPHost (window.smtphos t.value);
window.SimpleEM ail.setFrom(win dow.fromemail.v alue);
window.SimpleEM ail.setRecipien ts(window.toema il.value);
window.SimpleEM ail.setSubject( window.subject. value);
window.SimpleEM ail.setMessage( window.message. innerText);
window.SimpleEM ail.sendEMail() ;
alert("done");
}
</script>
</HEAD>
<BODY>
<H1>SimpleEMail </H1>
<P>
<APPLET style="LEFT: 0px; WIDTH: 144px; TOP: 0px; HEIGHT: 14px" height=14
archive=CelcomC lient.jar width=144 code=Celcom.Cli ent.SimpleEMail .class
name=SimpleEMai l>
<PARAM NAME="from" VALUE="te**@mai l.com">
<PARAM NAME="smtphost" VALUE="mango">
<PARAM NAME="recipient s" VALUE="te**@mai l.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>Mess age</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><INPU T type=button value="Send Mail"
onclick="javasc ript:sendingEMa il()" id=button1 name=button1><t d></td>
</tr>
</TABLE>
</P>
</BODY>
</HTML>

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

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

Similar topics

5
3383
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. An html page that holds the applet. 2. a php page that accepts data submitted to it by the applet via the $_POST array and writes it to the mysql database. This page never makes it to the browser window. 3. a simple Thank you page that shows...
1
11044
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 or any other Excel extras. However, now is the time to get the complicated ones to work. I didn't think that there would be a difference, but there is. At first, I was beginning to think that it was a file size problem, but now I am unsure. ...
0
1834
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 because the version at that site works without a single problem in my browsers:
8
3389
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 problems. IE crashes when one refreshes the page or leave the page. This happens only after calling the Java method more than once. It does not crash if the Java method is called just once and then the page is refreshed. FireFox does not crash at all...
7
5050
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 with Jbuilder using the JDK 1.1.8 as I need to support users with that haven't installed the latest version of the Java Runtime. So I have been searching the internet trying to see how to speed up the loading process. I've notice that some...
16
2537
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 uses IE to talk with a server. The user on the client (IE) sees an ASP net page containing a TextBox. He can write some text in this text box and push a submit button.
1
1431
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 the help of an applet of which the applet is itself a part" I am trying using Java Applet to Javascript Communication. I am able to access the object which represents the HTML document. That abject is represented by document itself.
8
2048
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 button A's mouseup has completed? I beleive event processing to be single-threaded for good reason but I need a "stop" button and it's no good if it doesn't do anything until the other processing has finished :-)
1
1960
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 and stuff. Now my main problem is that I need to make the ball bounce back after it touches the paddle...Right now the ball goes through the paddle. And the paddle is moved using arrow keys. So now I need like a code for me to make the ball...
0
8761
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9426
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9280
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8144
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6016
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4525
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4795
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3238
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2677
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.