|
|
<HTML>
<%@ page
language="java"
contentType="text/html;charset=shift_jis"
import="java.util.*"
import="javax.mail.*"
import="javax.mail.internet.*"
%>
<jsp:useBean id="Basic" scope="session" class="lightbox.basic" />
<%!
// *********************************************************
// 認証用のプライベートクラス
// *********************************************************
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 );
}
}
%>
<BODY>
<H2>メール送信</H2>
<FORM method=post>
<INPUT type=text name=from><br>
<INPUT type=text name=to><br>
<INPUT type=text name=subject><br>
<TEXTAREA name=comment cols=40 rows=10></TEXTAREA><br>
<INPUT name=SendButton type=submit value=送信>
</FORM>
<%
// *****************************************************
// * フォームのデータを取得して連想配列に保存
// *****************************************************
Map requestMap = request.getParameterMap();
int size = requestMap.size();
Set requestKeySet = request.getParameterMap().keySet();
Object KeyArray[] = requestKeySet.toArray();
Hashtable Form = new Hashtable();
int i;
for ( i = 0; i < size; i++ ) {
Form.put(
(String)KeyArray[i],
Basic.toShiftjis(
request.getParameter(
(String)KeyArray[i]
)
)
);
}
if ( Form.get("SendButton") != "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 );
try {
// *****************************************************
// メール用のメッセージオブジェクトを作成
// *****************************************************
MimeMessage msg = new MimeMessage(MailSession);
// *****************************************************
// 宛先
// *****************************************************
msg.setRecipients(
Message.RecipientType.TO,
(String)Form.get("to")
);
// *****************************************************
// 送信者
// *****************************************************
msg.setFrom(
new InternetAddress( (String)Form.get("from"))
);
// *****************************************************
// 件名
// *****************************************************
msg.setSubject(
MimeUtility.encodeText(
(String)Form.get("subject"),
"iso-2022-jp",
"B"
)
);
// *****************************************************
// 本文
// *****************************************************
msg.setContent(
Form.get(
"comment"
),
"text/plain; charset=\"iso-2022-jp\""
);
// *****************************************************
// 送信
// *****************************************************
Transport.send( msg );
}
catch (Exception e) {
out.println("送信エラー");
}
}
else {
out.println("メール送信データを入力して下さい<br>");
}
%>
</BODY>
</HTML>
| |
|
|
|
|
<HTML>
<%@ page
language="java"
contentType="text/html;charset=shift_jis"
import="java.util.*"
import="javax.mail.*"
import="javax.mail.internet.*"
%>
<jsp:useBean id="Basic" scope="session" class="lightbox.basic" />
<%!
// *********************************************************
// 認証用のプライベートクラス
// *********************************************************
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 );
}
}
%>
<BODY>
<H2>メール送信</H2>
<FORM method=post>
<INPUT type=text name=from><br>
<INPUT type=text name=to><br>
<INPUT type=text name=subject><br>
<TEXTAREA name=comment cols=40 rows=10></TEXTAREA><br>
<INPUT name=SendButton type=submit value=送信>
</FORM>
<%
// *****************************************************
// * リクエストデータを漢字変換して連想配列に保存
// *****************************************************
Hashtable Form = Basic.getRequest( request );
if ( Form.get("SendButton") != 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 );
try {
// *****************************************************
// メール用のメッセージオブジェクトを作成
// *****************************************************
MimeMessage msg = new MimeMessage(MailSession);
// *****************************************************
// 宛先
// *****************************************************
msg.setRecipients(
Message.RecipientType.TO,
(String)Form.get("to")
);
// *****************************************************
// 送信者
// *****************************************************
msg.setFrom(
new InternetAddress( (String)Form.get("from"))
);
// *****************************************************
// 件名
// *****************************************************
msg.setSubject(
MimeUtility.encodeText(
(String)Form.get("subject"),
"iso-2022-jp",
"B"
)
);
// *****************************************************
// 本文
// *****************************************************
msg.setContent(
Form.get(
"comment"
),
"text/plain; charset=\"iso-2022-jp\""
);
// *****************************************************
// 送信
// *****************************************************
Transport.send( msg );
}
catch (Exception e) {
out.println("送信エラー");
}
}
else {
out.println("メール送信データを入力して下さい<br>");
}
%>
</BODY>
</HTML>
| |
|
|
|