Solved

Email from Java Applet

Posted on 1998-03-23
3
190 Views
Last Modified: 2010-04-16
Is it possible to send email directly from a java applet? Or does this require a CGI script? Using a CGI script is undesirable as it means the method would have to change for every different server, based on a CGI script the uses the POST and emails the result.

Is there a mechanism for getting data from an Applet to an email address without being dependent on the Server side (in many cases I can not run customized application at the server!)
0
Comment
Question by:sdj
  • 2
3 Comments
 
LVL 6

Expert Comment

by:gadio
ID: 1233723
 It is possible through the use of the mail server on the server side. You don't need to use any special application as the mail server is usually installed on any UNIX machine, and comes up at boot time. By default it works with SMTP (simple mail transfer protocol) and listens on port 25.
Have a look at:
http://lgr.se/mailclient.htm
You can get a source code for sending and reading mail there.
0
 

Author Comment

by:sdj
ID: 1233724
This sample does not give any source code for an applet to send email. I actualy want to write the code rather than use somebody else pre-written java.

Is this sample actually valid from an applet as well as an application?
0
 
LVL 6

Accepted Solution

by:
gadio earned 50 total points
ID: 1233725
 Well sdj, I can give you source code if you want. It seems though that you want to write it yourself. Here's what you should do. You can try and read about the SMTP protocol. You can also telnet to your ISP server (or to another machine with a mail server) to port 25, and play along with the protocol. You would see that its very simple and with basic java networking knowledge you can write this code. In general I'll describe a simple send procedure in java:
o Initiate connection to the server (the machine where that applet came from) through
   socket to port 25.
o send "helo IP" command, where IP = the ISP IP, or name.
o check success (As I remember it means that you receive a line beginning with "250 ").
o send "mail from: user" where user = your email address.
o check success.
o send "rcpt to: name" where name = the destination address.
o check success.
o send "data" command
o send "Subject: xxx", xxx = whatever.
o send your text.
o send a line with only a single dot.
o check success.

And that's it! its very simple. You should check that before writing (use telnet) as I didn't. You should also improve the error handling etc.

Hope that helps.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This video teaches viewers about errors in exception handling.

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question