用JSP来发送邮件_JSP教程

编辑Tag赚U币
教程Tag:暂无Tag,欢迎添加,赚取U币!

推荐:jsp分页类---统一使用
一、建立数据库分页的类 package newsbean; import java.sql.*; public class DBConnection{ //这里使用ms jdbc String sDBDriver = com.microsoft.jdbc.sqlserver.SQLServerDriver; //指定数据库名/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>信件标题:<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="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>留言本发送</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);
//設定收信人
msg.setSubject("网上留言信息:"); //設定E-Mail的主旨
msg.setSentDate(new java.util.Date()); //設定送信的時間
msg.setText("标题:"+topic+",内容"+body+",联系人E-mail:"+email+",联系电话:"+phone+",公司网址/地址:"+http); //設定傳送信的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('已经成功留言!!');window.location.href='message.jsp';</script>");

}catch(Exception e){
out.println(e.toString());
}

%>
</body>
</html>

 

 

分享:解析Jsp常用技巧:图片验证码
思路 : 图片验证码的实现主要的技术点是如何生成一个图片。生成图片可以使用java.awt包下的类来实现。我们先写一个简单的生成图片的程序HelloImage.java。以下是代码部分。 package com.vogoal.test; import java.awt.Color; import java.awt.Graphics; imp

来源:模板无忧//所属分类:JSP教程/更新时间:2010-04-23
相关JSP教程