Solved

Email from Java Applet

Posted on 1998-03-23
3
186 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
groupNoAdj 7 95
maven project error 5 54
HashTable highest marks enumeration alternative 9 37
Way to decrease size of apk file 9 65
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This video teaches viewers about errors in exception handling.

785 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