如何使用JSP來發送郵件

導語:以下是本站小編蒐集整理的如何使用JSP來發送郵件的.實例,希望能幫到你。

如何使用JSP來發送郵件

<TABLE width=555 border=0 align="center" cellPadding=0 cellSpacing=0>

<FORM action=message_ method=post>

<TBODY>

<TR>

<TD width=80 height=30>信件標題:<FONT color=#ff0000>*</FONT></TD>

<TD><INPUT class=input id=topic name=topic>

</TD>

</TR>

<TR>

<TD width=80 height=23 valign="top">反饋信息:<FONT color=#ff0000>*</FONT></TD>

<TD><TEXTAREA class=input id=body name=body rows=5 cols="50"></TEXTAREA>

</TD>

</TR>

<TR>

<TD width=80 height=30>如何稱呼:<FONT color=#ff0000>*</FONT></TD>

<TD><INPUT class=input id=name name=name>

</TD>

</TR>

<TR>

<TD width=80 height=30>你的郵件:<FONT color=#ff0000>* </FONT></TD>

<TD height=23><INPUT class=input id=email name=email>

</TD>

</TR>

<TR>

<TD width=80 height=30>你的電話:</TD>

<TD><INPUT name=phone class=input id="phone">

</TD>

</TR>

<TR>

<TD width=80 height=45>公司地址:<BR>

(或網址)</TD>

<TD><INPUT class=input id=http size=40 name=http>

</TD>

</TR>

<TR>

<TD align=right width=80>&nbsp;</TD>

<TD height=35><INPUT class=bt type=submit value=提交 name=tt onclick="return check()">

</TD>

</TR>

</FORM>

</TABLE>

處理頁面:

<%@ page contentType="text/html; charset=gb2312" language="java" import=".*,.*,.*,any.*,rnet.*,vation.*" errorPage="" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">

<html>

<head>

<jsp:useBean id="company" scope="page" class="any"></jsp:useBean>

<jsp:useBean id="comCtl" scope="page" class="tl"></jsp:useBean>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312">

<title>留言本發送</title>

</head>

<body>

<%

//int id=1;

company=ctCompany(1);

String email1="";

email1=mail();

if(email1==null) ";

String username=arameter("name");

String topic=arameter("topic");

String body=arameter("body");

String email=arameter("email");

String phone=arameter("phone");

String http=arameter("http");

//String email=new String(arameter("email")ytes("ISO8859_1"));

//t(username+"<br>");

//t(email+"<br>");

try{

Properties props = new Properties();

("", "");

("ocol", "smtp");

("", "true");

ion sessmail = nstance(props);

Message msg = new MimeMessage(sessmail);

String ";

rom(new InternetAddress(From));

String To=email1;

InternetAddress[] address=null;

address = e(To,false);

// ecipient(, new InternetAddress(arameter("to")));

ecipients(, address);

//設定收信人

ubject("網上留言信息:"); //設定E-Mail的主旨

entDate(new ()); //設定送信的時間

ext("標題:"+topic+",內容"+body+",聯繫人E-mail:"+email+",聯繫電話:"+phone+",公司網址/地址:"+http); //設定傳送信的MIME Type

Transport transport = ransport("smtp");

ect("","sonic260","123456789");

Message(msg, llRecipients());

e();

t("<script language='javascript'>alert('已經成功留言!!');='';</script>");

}catch(Exception e){

tln(ring());

}

%>

</body>

</html>