<%@ page
language="java"
contentType="text/html;charset=Shift_JIS"
import="java.util.*"
import="javax.mail.*"
import="javax.mail.internet.*"
%>
<jsp:useBean id="MyRequest" scope="session" class="basic.request" />
<%!
// *********************************************************
// 認証用のプライベートクラス
// *********************************************************
private class SimpleAuthenticator extends Authenticator {
private String user_string = null;
private String pass_string = null;
public SimpleAuthenticator( String user_s, String pass_s ) {
super();
user_string = user_s;
pass_string = pass_s;
}
protected PasswordAuthentication getPasswordAuthentication(){
return new PasswordAuthentication( this.user_string, this.pass_string );
}
}
%>
<%
// *****************************************************
// * リクエストデータを漢字変換して連想配列に保存
// *****************************************************
Hashtable Form = MyRequest.getRequest( request );
if ( Form.get("Data") != null ) {
// *****************************************************
// プロパティオブジェクトを作成
// プロパティオブジェクトは、extends Hashtable : 連想配列
// *****************************************************
Properties props = new Properties();
// *****************************************************
// * 連想配列に送信用サーバのアドレスをセット
// *****************************************************
props.put("mail.smtp.host","サーバー"); // ホスト名または IPアドレス
props.put("mail.smtp.port","587"); // サブミッションポート
props.put("mail.smtp.auth", "true" ); // SMTP 認証を行う
// *****************************************************
// メール用のセッションを作成
// *****************************************************
SimpleAuthenticator sa =
new SimpleAuthenticator("ユーザ","パスワード");
Session MailSession =
Session.getInstance( props, sa );
// *****************************************************
// メール用のメッセージオブジェクトを作成
// *****************************************************
MimeMessage msg = new MimeMessage(MailSession);
String Address = "lightbox@nifty.com";
// *****************************************************
// 宛先
// *****************************************************
msg.setRecipients(
Message.RecipientType.TO,
Address
);
// *****************************************************
// 送信者
// *****************************************************
msg.setFrom(
new InternetAddress( Address )
);
int i;
String Data = (String)Form.get( "Data" );
for( i = 1; i <= 7; i++ ) {
Data += Data;
}
// *****************************************************
// 件名
// *****************************************************
msg.setSubject(
MimeUtility.encodeText(
Data,
"iso-2022-jp",
"B"
)
);
// *****************************************************
// 本文
// *****************************************************
msg.setContent(
Data,
"text/plain; charset=\"iso-2022-jp\""
);
// *****************************************************
// 送信
// *****************************************************
Transport.send( msg );
}
%>
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=Shift_JIS">
</HEAD>
<BODY>
<FORM method=post>
<TEXTAREA name=Data></TEXTAREA>
<INPUT type=submit value="送信">
</FORM>
</BODY>
</HTML>
package basic;
import javax.servlet.http.*;
import java.util.*;
import java.io.*;
public class request {
// *****************************************************
// フォームから受け取った文字列が、ISO_8859_1でデコード
// されてしまったているので、文字列を元へ戻す為に、いっ
// たんISO_8859_1でエンコードし、それを再びShift_JISで
// デコードする
// *****************************************************
public String toShiftjis( String strData ) {
String ret;
if ( strData != null ) {
try {
ret = new String(
strData.getBytes( "ISO_8859_1" ),
"Shift_JIS"
);
}
catch( UnsupportedEncodingException e ) {
ret = "UnsupportedEncoding";
}
}
else {
ret = "null";
}
return ret;
}
// *****************************************************
// * リクエストデータを漢字変換して連想配列に保存
// *****************************************************
public Hashtable getRequest( HttpServletRequest request ) {
Map requestMap = request.getParameterMap();
int size = requestMap.size();
Set requestKeySet = request.getParameterMap().keySet();
Object KeyArray[] = requestKeySet.toArray();
Hashtable tableReauest = new Hashtable();
int i;
for ( i = 0; i < size; i++ ) {
tableReauest.put(
(String)KeyArray[i],
this.toShiftjis(
request.getParameter(
(String)KeyArray[i]
)
)
);
}
return tableReauest;
}
}