用JSP來(lái)發(fā)送郵件_JSP教程
推薦:jsp分頁(yè)類---統(tǒng)一使用一、建立數(shù)據(jù)庫(kù)分頁(yè)的類 package newsbean; import java.sql.*; public class DBConnection{ //這里使用ms jdbc String sDBDriver = com.microsoft.jdbc.sqlserver.SQLServerDriver; //指定數(shù)據(jù)庫(kù)名/url private final String url = jdbc:microsoft:sqlse
MESSAGE.JSP
<TABLE width=555 border=0 align="center" cellPadding=0 cellSpacing=0>
<FORM action=message_do.jsp method=post>
<TBODY>
<TR>
<TD width=80 height=30>信件標(biāo)題:<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>
(或網(wǎng)址)</TD>
<TD><INPUT class=input id=http size=40 name=http>
</TD>
</TR>
<TR>
<TD align=right width=80> </TD>
<TD height=35><INPUT class=bt type=submit value=提交 name=tt onclick="return check()">
</TD>
</TR>
</FORM>
</TABLE>
處理頁(yè)面:
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*,java.util.*,javax.mail.*,cn.cmpy.company.*,javax.mail.internet.*,javax.activation.*" errorPage="" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<jsp:useBean id="company" scope="page" class="cn.cmpy.company.company"></jsp:useBean>
<jsp:useBean id="comCtl" scope="page" class="cn.cmpy.company.comCtl"></jsp:useBean>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>留言本發(fā)送</title>
</head>
<body>
<%
//int id=1;
company=comCtl.selectCompany(1);
String email1="";
email1=company.getEmail();
if(email1==null) email1="nbybc@sina.com";
String username=request.getParameter("name");
String topic=request.getParameter("topic");
String body=request.getParameter("body");
String email=request.getParameter("email");
String phone=request.getParameter("phone");
String http=request.getParameter("http");
//String email=new String(request.getParameter("email").getBytes("ISO8859_1"));
//out.print(username+"<br>");
//out.print(email+"<br>");
try{
Properties props = new Properties();
props.put("mail.smtp.host", "smtp.sohu.com");
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.auth", "true");
javax.mail.Session sessmail = javax.mail.Session.getInstance(props);
Message msg = new MimeMessage(sessmail);
String From="sonic260@sohu.com";
msg.setFrom(new InternetAddress(From));
String To=email1;
InternetAddress[] address=null;
address = InternetAddress.parse(To,false);
// newMessage.setRecipient(Message.RecipientType.TO, new InternetAddress(request.getParameter("to")));
msg.setRecipients(Message.RecipientType.TO, address);
//設(shè)定收信人
msg.setSubject("網(wǎng)上留言信息:"); //設(shè)定E-Mail的主旨
msg.setSentDate(new java.util.Date()); //設(shè)定送信的時(shí)間
msg.setText("標(biāo)題:"+topic+",內(nèi)容"+body+",聯(lián)系人E-mail:"+email+",聯(lián)系電話:"+phone+",公司網(wǎng)址/地址:"+http); //設(shè)定傳送信的MIME Type
Transport transport = sessmail.getTransport("smtp");
transport.connect("smtp.sohu.com","sonic260","123456789");
transport.sendMessage(msg, msg.getAllRecipients());
transport.close();
out.print("<script language='javascript'>alert('已經(jīng)成功留言!!');window.location.href='message.jsp';</script>");
}catch(Exception e){
out.println(e.toString());
}
%>
</body>
</html>
分享:解析Jsp常用技巧:圖片驗(yàn)證碼思路 : 圖片驗(yàn)證碼的實(shí)現(xiàn)主要的技術(shù)點(diǎn)是如何生成一個(gè)圖片。生成圖片可以使用java.awt包下的類來(lái)實(shí)現(xiàn)。我們先寫(xiě)一個(gè)簡(jiǎn)單的生成圖片的程序HelloImage.java。以下是代碼部分。 package com.vogoal.test; import java.awt.Color; import java.awt.Graphics; imp
- jsp response.sendRedirect不跳轉(zhuǎn)的原因分析及解決
- JSP指令元素(page指令/include指令/taglib指令)復(fù)習(xí)整理
- JSP腳本元素和注釋復(fù)習(xí)總結(jié)示例
- JSP FusionCharts Free顯示圖表 具體實(shí)現(xiàn)
- 網(wǎng)頁(yè)模板:關(guān)于jsp頁(yè)面使用jstl的異常分析
- JSP頁(yè)面中文傳遞參數(shù)使用escape編碼
- 基于jsp:included的使用與jsp:param亂碼的解決方法
- Java Web項(xiàng)目中連接Access數(shù)據(jù)庫(kù)的配置方法
- JDBC連接Access數(shù)據(jù)庫(kù)的幾種方式介紹
- 網(wǎng)站圖片路徑的問(wèn)題:絕對(duì)路徑/虛擬路徑
- (jsp/html)網(wǎng)頁(yè)上嵌入播放器(常用播放器代碼整理)
- jsp下顯示中文文件名及絕對(duì)路徑下的圖片解決方法
- 相關(guān)鏈接:
- 教程說(shuō)明:
JSP教程-用JSP來(lái)發(fā)送郵件。