<html>
<head>
<title>新建邮件</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="pragma" content="no-cache">
</head>
<body>
<form method="post" action="SendMailPlain.jsp">
<table width="75" border="0" align="center" cellspacing="1">
<tr bgcolor="#FFFFFF">
<td width="24%">收信人地址:</td>
<td width="76%">
<input name="to" type="text" id="to" value="[email protected]"></td>
</tr>
<tr bgcolor="#FFFFFF">
<td>主题:</td>
<td>
<input name="title" type="text" value="这是一封文本的测试邮件"></td>
</tr>
<tr>
<td height="107" colspan="2" bgcolor="#FFFFFF">
<textarea name="content" cols="50" rows="5">这是一封文本的测试邮件</textarea></td>
</tr>
<tr align="center">
<td colspan="2" bgcolor="#FFFFFF">
<input type="submit" name="tSubmit" value="发送">
<input type="reset" name="bReset" value="重置">
</td>
</tr>
</table>
</form>
</body>
</html>
<head>
<title>新建邮件</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="pragma" content="no-cache">
</head>
<body>
<form method="post" action="SendMailPlain.jsp">
<table width="75" border="0" align="center" cellspacing="1">
<tr bgcolor="#FFFFFF">
<td width="24%">收信人地址:</td>
<td width="76%">
<input name="to" type="text" id="to" value="[email protected]"></td>
</tr>
<tr bgcolor="#FFFFFF">
<td>主题:</td>
<td>
<input name="title" type="text" value="这是一封文本的测试邮件"></td>
</tr>
<tr>
<td height="107" colspan="2" bgcolor="#FFFFFF">
<textarea name="content" cols="50" rows="5">这是一封文本的测试邮件</textarea></td>
</tr>
<tr align="center">
<td colspan="2" bgcolor="#FFFFFF">
<input type="submit" name="tSubmit" value="发送">
<input type="reset" name="bReset" value="重置">
</td>
</tr>
</table>
</form>
</body>
</html>
解决方案 »
- mysql配置向导里,字符集设置utf8与gb2312有什么区别,哪个好?
- hibernate映射自动获取时间的问题
- spring+hibernate+struts问题
- myeclipse文件已经改了,但是运行后网页中的内容不变,就是说还是我没有改变之前的!
- java自动重连机制的实现
- 分布式是一个什么概念?
- 怎么关联为什么不对呢?
- 请问webservice中如何实现这样的功能的最佳方法是什么??详情请进
- 有哪位大哥大姐做vrml的呀?
- java里批量插入数据,不经过实体类
- 100分相送,郁闷了好久的问题,一旦解决立即送分
- JDBC的问题:使用Access如何在JBuilder9实现查询字符串功能!
<%@ page contentType="text/html;charset=GB2312"%>
<%request.setCharacterEncoding("gb2312");%><!--中文处理代码-->
<!--引入要用到的类库-->
<%@ page import="java.util.*,javax.mail.*"%>
<%@ page import="javax.mail.internet.*"%>
<html>
<head>
<title>发送成功</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="pragma" content="no-cache">
</head>
<body>
<%
try{
//从html表单中获取邮件信息
String tto=request.getParameter("to");
String ttitle=request.getParameter("title");
String tcontent=request.getParameter("content");
Properties props=new Properties();//也可用Properties props = System.getProperties();
props.put("mail.smtp.host","mail.EchoChina.net");//存储发送邮件服务器的信息
props.put("mail.smtp.auth","true");//同时通过验证
Session s=Session.getInstance(props);//根据属性新建一个邮件会话
s.setDebug(true);
MimeMessage message=new MimeMessage(s);//由邮件会话新建一个消息对象
//设置邮件
InternetAddress from=new InternetAddress("[email protected]");
message.setFrom(from);//设置发件人
InternetAddress to=new InternetAddress(tto);
message.setRecipient(Message.RecipientType.TO,to);//设置收件人,并设置其接收类型为TO
message.setSubject(ttitle);//设置主题
message.setText(tcontent);//设置信件内容
message.setSentDate(new Date());//设置发信时间
//发送邮件
message.saveChanges();//存储邮件信息
Transport transport=s.getTransport("smtp");
transport.connect("mail.163.net","[email protected]","password");//以smtp方式登录邮箱
transport.sendMessage(message,message.getAllRecipients());//发送邮件,其中第二个参数是所有
//已设好的收件人地址
transport.close();
%>
<div align="center">
<p><font color="#FF0000">发送成功!</font></p>
<p><a href="http://mail.163.net">去收邮件</a><br>
<br>
<a href="index.htm">再发一封</a> </p>
</div>
<%
}catch(MessagingException e){
out.println(e.toString());
e.printStackTrace();
}
%>
</body>
</html>
String host,
String from,
//Address[] toaddress,
String toaddress, String mailsubject,
//Address[] ccaddress,
//Address[] bccaddress,
String ccaddress,
String bccaddress, String content,
String account,
String password)
throws Exception {
boolean flag = false;
try {
Properties props = new Properties(); //获得系统属性
props.put("mail.smtp.host", host); //设置SMTP主机
props.put("mail.smtp.auth", "true"); //这样才能通过验证
if (props.getProperty("user.region") != null
&& props.getProperty("user.region").equals("TW")
&& props.getProperty("user.language") != null
&& props.getProperty("user.language").equals("zh")) {
props.setProperty("file.encoding", "BIG5");
}
//获得邮件会话对象
Session session = Session.getDefaultInstance(props, null);
session.setDebug(true);
//创建MIME邮件对象
MimeMessage mimeMsg = new MimeMessage(session);
//设置发信人
mimeMsg.setFrom(new InternetAddress(from));
//设置收信人
if (toaddress != null) {
mimeMsg.setRecipients(Message.RecipientType.TO, toaddress);
} //设置抄送人
if (ccaddress != null) {
mimeMsg.setRecipients(Message.RecipientType.CC, ccaddress);
} //设置暗送人
if (bccaddress != null) {
mimeMsg.setRecipients(Message.RecipientType.BCC, bccaddress);
} //设置邮件主题
String subject = MimeUtility.encodeText(mailsubject, "GBK", "B");
mimeMsg.setSubject(subject);
// 创建 Multipart 并放入每个 MimeBodyPart
Multipart mp = new MimeMultipart();
// 第一部分信息
MimeBodyPart mbp1 = new MimeBodyPart();
mbp1.setText(content, "GBK");
mp.addBodyPart(mbp1); mimeMsg.setContent(mp); //发送日期
mimeMsg.setSentDate(new Date());
//发送邮件
mimeMsg.saveChanges();
Transport transport = session.getTransport("smtp");
transport.connect(host, account, password);
//设置smtp认证
transport.sendMessage(mimeMsg, mimeMsg.getAllRecipients()); transport.close(); //Transport.send(mimeMsg);
flag = true;
} catch (SendFailedException e) {
//throw new OurException("邮件发送失败!");
System.out.println("发送邮件失败!");
} catch (MessagingException e) {
//throw new OurException("邮件发送失败!");
System.out.println("发送邮件失败!");
} catch (Exception e) {
//throw new OurException("邮件发送失败!");
System.out.println("发送邮件失败!");
} finally {
if (flag == false)
//throw new OurException("发送邮件失败!");
System.out.println("发送邮件失败!");
}
}
"回复:您好!我是昆山双叶软件科技有限公司!", "", "", leaveword, "bobshi", "12345678");
javax.activation.*
可以单独在这里下载activation.jar,
http://java.sun.com/products/javabeans/glasgow/jaf.html
或者整个下载J2EE,它的j2ee.jar里已经包含JAF 和JavaMail了;
http://java.sun.com/products/javabeans/glasgow/jaf.html
或者整个下载J2EE,它的j2ee.jar里已经包含JAF 和JavaMail