semd mail on Java Applet


[ ´ÙÀ½ ±Ûµé ] [ À̾ ±Û¿Ã¸®±â(´äÇϱâ) ] [ ÀÚ¹Ù ¹¯°í ´äÇϱâ ]

±Û¾´ÀÌ :È«¼º¿í 1998³â 9¿ù 13ÀÏ 17:24:01

In Reply to: ÀÚ¹Ùapplet À¸·Î Mail Àü¼ÛÀ» ÇÏ·Á°í ÇÕ´Ï´Ù. posted by ¹Úȯ¼® on 1998³â 9¿ù 08ÀÏ 17:34:37:

ÀÌ°÷¿¡ Á¦°¡ ¸¸µç Source¸¦ ¿Ã¸³´Ï´Ù.
ÂüÁ¶ Çϼ¼¿ä..


¾ÆÁ÷ 64bit en/decoder¸¦ ¸¸µéÁö¸¦ ¸øÇß½À´Ï´Ù.
±×¸®°í thread·Î ó¸®ÇÒ ·Á°í Çß´ø »çÇ×Àº ¾ÆÁ÷ ¸¸µéÁö ¾Ê¾Ò½À´Ï´Ù.


============================================
//******************************************************************************
// SuppersSMTM.java: Applet
//
// Sung-ug, Hong (È« ¼º¿í)
//
// URL : http://my.netian.com/~supper96/index.html
//
// E-Mail : supper@jeonghan.co.kr / supper@jhkorea.co.kr / supper96@netian.com
//
//
// 1998. 09. 13 first make;
//
// 1. send default smtp header
//
//******************************************************************************
import java.applet.*;
import java.awt.*;
import java.net.*;
import java.io.*;
import java.util.*;



//==============================================================================
// Main Class for applet SuppersSMTM
//
//==============================================================================
public class SuppersSMTM extends Applet implements Runnable
{
// THREAD SUPPORT:
// m_SuppersSMTM is the Thread object for the applet
//--------------------------------------------------------------------------
private Thread m_SuppersSMTM = null;


// PARAMETER SUPPORT:
// Parameters allow an HTML author to pass information to the applet;
// the HTML author specifies them using the <PARAM> tag within the <APPLET>
// tag. The following variables are used to store the values of the
// parameters.
//--------------------------------------------------------------------------


// Members for applet parameters
// <type> <MemberVar> = <Default Value>
//--------------------------------------------------------------------------
private String m_DefSMailServer = "jeonghan.co.kr";
private String m_DefSenderName = "Sung-ug Hong";
private String m_DefSenderAddress = "supper@jeonghan.co.kr";
private String m_DefReceiverAddress = "";
private String m_DefSubject = " ";
private String m_DefContext = " ";
private String m_DefReturnHTML = "http://my.netian.com/~supper96/index.html";


// Parameter names. To change a name of a parameter, you need only make
// a single change. Simply modify the value of the parameter string below.
//--------------------------------------------------------------------------
private final String PARAM_DefSMailServer = "DefSMailServer";
private final String PARAM_DefSenderName = "DefSenderName";
private final String PARAM_DefSenderAddress = "DefSenderAddress";
private final String PARAM_DefSubject = "DefSubject";
private final String PARAM_DefReturnHTML = "DefReturnHTML";


URL SuppersPage = null;
URL ReturnPage = null;
URL HelpDoc = null;
URL ERA00001 = null;
URL ERA00002 = null;
URL ERA00003 = null;
URL ERA00004 = null;
URL ERA00005 = null;
URL ERA00006 = null;


// Socket SMTPScoket = null;


DataInputStream DataIS;


String RCVDMessage = null;
String SENTMessage = null;


String checkS;
String lastline;


static PrintStream PrintS = null;
static InputStream InputS = null;


InetAddress LocalIPAddress;


private String LocalIPDNS = "";
private String LocalIPADDR = "";
private String LocalIPString = "";


static long SMTPStatus = 0;


Button MailSendingNow = new Button("Send Mail"); // Send Button
Button MailHelp = new Button("Help"); // Send Button



TextField MailSenderName; // E-Mail Sender Name
TextField MailSenderAddress; // E-Mail Sender Address
TextField MailReceiverAddress; // E-Mail Receiver Address
TextField MailSubject; // E-Mail Subject
TextArea MailContext; // E-Mail Context


Font FArial18b; // Font Arial Bold 18pt
Font FArial14b; // Font Arial Bold 14pt
Font FArial14p; // Font Arial Plain 14pt
Font FArial12b; // Font Arial Bold 12pt
Font FArial12p; // Font Arial Plain 12pt
Font FArial10b; // Font Arial Bold 10pt
Font FArial10p; // Font Arial Plain 10pt
Font FArial08b; // Font Arial Bold 8pt
Font FArial08p; // Font Arial Plain 8pt


int isOk;


// SuppersSMTM Class Constructor
//--------------------------------------------------------------------------
public SuppersSMTM()
{
// TODO: Add constructor code here
}


// APPLET INFO SUPPORT:
// The getAppletInfo() method returns a string describing the applet's
// author, copyright date, or miscellaneous information.
//--------------------------------------------------------------------------
public String getAppletInfo()
{
return "Name: SMTM\r\n" +
"Version; 1.0\r\n" +
"Author: Sung-ug, Hong(È«¼º¿í)\r\n" +
"EMail: supper@jeonghan.co.kr, supper@jhkorea.co.kr\r\n" +
"Korean Call: 017-651-5452\r\n" +
"Company: Software Dev. Team, JeongHan System co.\r\n" +
"Created with Microsoft Visual J++ Version 1.1\r\n" +
"============================================\r\n" +
"\r\n" +
"I Need a High Speed Way.\r\n" +
"\r\n" +
"HMC Marcia 2.0 (Black on Dark Gray)\r\n" +
"L.S 250 km/h\r\n" +
"180HP\r\n" +
"205, R16j, 55 serize, 5 Sporke Silver\r\n" +
"Kenwood Sound\r\n" +
"============================================\r\n\r\n" +
"And\r\n" +
"wanna good girl friends\r\n" +
":)";
}


// PARAMETER SUPPORT
// The getParameterInfo() method returns an array of strings describing
// the parameters understood by this applet.
//
// SuppersSMTM Parameter Information:
// { "Name", "Type", "Description" },
//--------------------------------------------------------------------------
public String[][] getParameterInfo()
{
String[][] info =
{
{ PARAM_DefSMailServer, "String", "Default Send Mail Server Domain Name" },
{ PARAM_DefSenderName, "String", "Default Sender User Name" },
{ PARAM_DefSenderAddress, "String", "Default Sender E-Mail Address" },
{ PARAM_DefSubject, "String", "Default Send Mail Subject" },
{ PARAM_DefReturnHTML, "String", "Default Return HTML Page" },
};
return info;
}


// The init() method is called by the AWT when an applet is first loaded or
// reloaded. Override this method to perform whatever initialization your
// applet needs, such as initializing data structures, loading images or
// fonts, creating frame windows, setting the layout manager, or adding UI
// components.
//--------------------------------------------------------------------------
public void init()
{
// PARAMETER SUPPORT
// The following code retrieves the value of each parameter
// specified with the <PARAM> tag and stores it in a member
// variable.
//----------------------------------------------------------------------
String param;



// If you use a ResourceWizard-generated "control creator" class to
// arrange controls in your applet, you may want to call its
// CreateControls() method from within this method. Remove the following
// call to resize() before adding the call to CreateControls();
// CreateControls() does its own resizing.
//----------------------------------------------------------------------
resize(600, 400);


// TODO: Place additional initialization code here


FArial18b = new Font("Arial", Font.BOLD, 18);


FArial14b = new Font("Arial", Font.BOLD, 14);
FArial14p = new Font("Arial", Font.PLAIN, 14);


FArial12b = new Font("Arial", Font.BOLD, 12);
FArial12p = new Font("Arial", Font.PLAIN, 12);


FArial10b = new Font("Arial", Font.BOLD, 10);
FArial10p = new Font("Arial", Font.PLAIN, 10);


FArial08b = new Font("Arial", Font.BOLD, 8);
FArial08p = new Font("Arial", Font.PLAIN, 8);


setLayout(null);


MailSenderName = new TextField(m_DefSenderName); // 79
MailSenderAddress = new TextField(m_DefSenderAddress); // 79
MailReceiverAddress = new TextField(m_DefReceiverAddress); // 79
MailSubject = new TextField(m_DefSubject); // 79
MailContext = new TextArea(); // 15, 94


add(MailSenderName);
add(MailSenderAddress);
add(MailReceiverAddress);
add(MailSubject);
add(MailContext);


add(MailSendingNow);
add(MailHelp);


show();


// DefSMailServer: Default Send Mail Server Domain Name
//----------------------------------------------------------------------
param = getParameter(PARAM_DefSMailServer);
if (param != null)
m_DefSMailServer = param;


// DefSenderName: Default Sender User Name
//----------------------------------------------------------------------
param = getParameter(PARAM_DefSenderName);
if (param != null) {
m_DefSenderName = param;
MailSenderName.setText(m_DefSenderName);
}


// DefSenderAddress: Default Sender E-Mail Address
//----------------------------------------------------------------------
param = getParameter(PARAM_DefSenderAddress);
if (param != null) {
m_DefSenderAddress = param;
MailSenderAddress.setText(m_DefSenderAddress);
}


// DefSubject: Default Send Mail Subject
//----------------------------------------------------------------------
param = getParameter(PARAM_DefSubject);
if (param != null) {
m_DefSubject = param;
MailSubject.setText(m_DefSubject);
}


param = getParameter(PARAM_DefReturnHTML);
if (param != null) {
m_DefReturnHTML = param;
}
}


// Place additional applet clean up code here. destroy() is called when
// when you applet is terminating and being unloaded.
//-------------------------------------------------------------------------
public void destroy()
{
// TODO: Place applet cleanup code here
}


// SuppersSMTM Paint Handler
//--------------------------------------------------------------------------
public void paint(Graphics g)
{
// TODO: Place applet paint code here
GetLocalIPInformation();


g.setFont(FArial18b);
g.drawString("JeongHan System co.", 390, 20);


g.setFont(FArial10p);
g.drawString("Supper's Java Send Mailer v.0.1", 20, 385);


MailSendingNow.reshape(455, 375, 80, 20);
MailHelp.reshape(545, 375, 40, 20);


g.setFont(FArial12b);
g.drawString("Sender Name", 10, 45);
g.drawString("Sender Addr", 10, 75);
g.drawString("RCVD. Addr", 10, 105);
g.drawString("Subject", 10, 135);


MailSenderName.reshape(105, 30, 485, 20);
MailSenderAddress.reshape(105, 60, 485, 20);
MailReceiverAddress.reshape(105, 90, 485, 20);
MailSubject.reshape(105, 120, 485, 20);
MailContext.reshape(10, 150, 580, 220);
}


public void update(Graphics g)
{
paint(g);
}


// The start() method is called when the page containing the applet
// first appears on the screen. The AppletWizard's initial implementation
// of this method starts execution of the applet's thread.
//--------------------------------------------------------------------------
public void start()
{
if (m_SuppersSMTM == null)
{
m_SuppersSMTM = new Thread(this);
m_SuppersSMTM.start();
}
// TODO: Place additional applet start code here
}

// The stop() method is called when the page containing the applet is
// no longer on the screen. The AppletWizard's initial implementation of
// this method stops execution of the applet's thread.
//--------------------------------------------------------------------------
public void stop()
{
if (m_SuppersSMTM != null)
{
m_SuppersSMTM.stop();
m_SuppersSMTM = null;
}


// TODO: Place additional applet stop code here
}


// THREAD SUPPORT
// The run() method is called when the applet's thread is started. If
// your applet performs any ongoing activities without waiting for user
// input, the code for implementing that behavior typically goes here. For
// example, for an applet that performs animation, the run() method controls
// the display of images.
//--------------------------------------------------------------------------
public void run()
{
while (true)
{
try
{
repaint();
// TODO: Add additional thread-specific code here
Thread.sleep(50);
}
catch (InterruptedException e)
{
// TODO: Place exception-handling code here in case an
// InterruptedException is thrown by Thread.sleep(),
// meaning that another thread has interrupted this one
stop();
}
}
}



// Pressed Button
//
//------------
public boolean handleEvent(Event evt)
{
int i, j;
int aVal = 1;

if (evt.id == evt.ACTION_EVENT && evt.target == MailHelp) {
try {
HelpDoc = new URL("http://www.jeonghan.co.kr/help/suppersJavaSMTP.HTM");
getAppletContext().showDocument(HelpDoc, "_blank");
}
catch (MalformedURLException e) {}


HelpDoc = null;
return true; // pressed button
} // if (evt.id == evt.ACTION_EVENT && evt.target == MailHelp)
else if (evt.id == evt.ACTION_EVENT && evt.target == MailSendingNow) {
m_DefSenderName = MailSenderName.getText();
m_DefSenderAddress = MailSenderAddress.getText();
m_DefReceiverAddress = MailReceiverAddress.getText();
m_DefSubject = MailSubject.getText();
m_DefContext = MailContext.getText();


if (m_DefSenderName == null)
m_DefSenderName = m_DefSenderAddress;


if (m_DefSenderAddress.indexOf('@') < 1) {
// error sender e-mail address
}


m_DefSMailServer = m_DefSenderAddress.substring(m_DefSenderAddress.indexOf('@') + 1);


if (m_DefReceiverAddress.indexOf('@') < 1) {
// error receiver e-mail address
}


if (m_DefSubject == null)
m_DefSubject = "from Suppers Java Send Mailer v.1.0 (http://www.jeonghan.co.kr/)";


SendMail();
return true;
} // else if (evt.id == evt.ACTION_EVENT && evt.target == MailSendingNow)


return false; // other event
}
/*
public boolean keyDown(Event evt, int key)
{
Component CurrentField = (Component) evt.target;


m_DefSenderName = MailSenderName.getText();
m_DefSenderAddress = MailSenderAddress.getText();
m_DefReceiverAddress = MailReceiverAddress.getText();
m_DefSubject = MailSubject.getText();
m_DefContext = MailContext.getText();


return true;
}
*/
// TODO: Place additional applet code here


public void GetLocalIPInformation()
{
int i, j;
int pLen;


try {
LocalIPAddress = InetAddress.getLocalHost();
LocalIPString = LocalIPAddress.toString();

pLen = LocalIPString.length();


for (i = 0; i < pLen; i++) {
if (LocalIPString.charAt(i) == '/') break;
LocalIPDNS += LocalIPString.charAt(i);
}


i++;


for (j = i; j < pLen; j++) {
LocalIPADDR += LocalIPString.charAt(j);
}
}
catch (UnknownHostException e) {}
}


void expect(String expected) throws Exception {
lastline = DataIS.readLine();
if (!lastline.startsWith(expected))
throw new Exception(" : " + lastline);


while (lastline.startsWith(expected + "-"))
lastline = DataIS.readLine();


// checkS = lastline.substring(0, 2);
}


void expect() throws Exception {
lastline = DataIS.readLine();
}


public boolean SendMail() {
Socket s = null;


try {
s = new Socket(m_DefSMailServer, 25);


PrintStream p = new PrintStream(s.getOutputStream());
DataIS = new DataInputStream(s.getInputStream());


expect();


p.print("HELO " + LocalIPAddress.getHostName() + "\r\n");
expect();


p.print("MAIL FROM: \"" + m_DefSenderName + "\"<" + m_DefSenderAddress + ">\r\n");
expect();


p.print("RCPT TO: <" + m_DefReceiverAddress + ">\r\n");
expect();


p.print("DATA\r\n");
expect();


p.print("Subject: " + m_DefSubject + "\r\n");
p.print("MIME-Version: 1.0\r\n");
p.print("Content-Type: text/plain; charset=ks_c_5601-1987\r\n");

// TODO: Place additional SMTP Header code here


DataInputStream Dis = new DataInputStream(new StringBufferInputStream(m_DefContext));
while(Dis.available() > 0) {
String ln = Dis.readLine();
if (ln.equals("."))
ln = "..";
p.print(ln);
}


p.print("\r\n.\r\n");
expect();


p.print("QUIT\r\n");
expect();
}
catch (Exception e) {
return false;
}
finally {
try {
if (s != null)
s.close();
}
catch (Exception e) {}
}


if (m_DefReturnHTML != null) {
try {
ReturnPage = new URL(m_DefReturnHTML);
getAppletContext().showDocument(ReturnPage, "_self");
}
catch (MalformedURLException e) {}
}


return true;
}
}


/*
** Error Document HTML
**
** MailSenderAddress == null is ERA00001.HTM
** MailReceiverAddress == null is ERA00002.HTM
**
*/


´ÙÀ½ ±Ûµé:



À̾ ±Û¿Ã¸®±â(´äÇϱâ)

À̸§:
E-Mail:
Á¦¸ñ:
³»¿ë:
HTML ÅÂ±× Æ÷ÇÔ ¿©ºÎ: HTML ¹®¼­ÀÏ °æ¿ì üũ
°ü·Ã URL(¼±ÅÃ):
URL Á¦¸ñ(¼±ÅÃ):
°ü·Ã À̹ÌÁö URL:


[ ´ÙÀ½ ±Ûµé ] [ À̾ ±Û¿Ã¸®±â(´äÇϱâ) ] [ ÀÚ¹Ù ¹¯°í ´äÇϱâ ]