| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 576 人关注过本帖
标题:JavaMail问题
取消只看楼主 加入收藏
zhanglinkai
Rank: 1
等 级:新手上路
帖 子:87
专家分:0
注 册:2006-11-25
收藏
 问题点数:0 回复次数:0 
JavaMail问题

index.jsp
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Java Mail</title>
</head>
<body>
<div align="center">
<br><br>
<font color="blue" style="楷书"><h1>利用JavaMail来发送电子邮件</h1></font>
<br>
<br>
<form action="JavaMail.jsp" name="form1">
<p>寄信人: <input type="text" name="From" value="" size="30" /></p>
<p>收件人: <input type="text" name="To" value="" size="30" /></p>
<p>主 &nbsp;&nbsp;题: <input type="text" name="Subject" value="" size="30" /></p>
<p>内 &nbsp;容:</p>
<p><textarea name="Message" rows="8" cols="40">
</textarea></p>
<p><input type="submit" value="发送"/> &nbsp;&nbsp;<input type="reset" value="清除" /></p>
</form>
</div>
</body>
</html>
JavaMail.jsp
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@ page import="javax.mail.*" %>
<%@ page import="javax.mail.internet.*" %>
<%@ page import="javax.activation.*" %>
<%@ page import="java.io.*,java.util.*" %>
<%--
The taglib directive below imports the JSTL library. If you uncomment it,
you must also add the JSTL library to the project. The Add Library... action
on Libraries node in Projects view can be used to add the JSTL 1.1 library.
--%>
<%--
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
--%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Java Mail</title>
</head>
<body>
<center>
<h2>利用JavaMail来传送电子邮件</h2>
<%
request.setCharacterEncoding("GB2312");
InternetAddress[] address=null;
String mailserver="smtp.126.com";
String From=request.getParameter("From");
String To=request.getParameter("To");
String Subject=request.getParameter("Subject");
String message=request.getParameter("Message");
boolean sessionDebug=false;
try{
//设定服务器和传输协议
java.util.Properties props=System.getProperties();
props.put("mail.smtp.host",mailserver);
props.put("mail.transport.protocol","smtp");

//产生新的Session
javax.mail.Session mailSession=javax.mail.Session.getInstance(props,null);
mailSession.setDebug(sessionDebug);
javax.mail.Message msg=new MimeMessage(mailSession);

//设定传送邮件的发件人
msg.setFrom(new InternetAddress(From));
address=InternetAddress.parse(To,false);
msg.setRecipients(javax.mail.Message.RecipientType.TO,address);
msg.setSubject(Subject);

msg.setSentDate(new Date());
msg.setText(message);
Transport transport =mailSession.getTransport("smtp");
transport.send(msg);
out.println("邮件已顺利传送");}
catch(MessagingException mex){
mex.printStackTrace();}
%>
</center>


<%--
This example uses JSTL, uncomment the taglib directive above.
To test, display the page like this: index.jsp?sayHello=true&name=Murphy
--%>
<%--
<c:if test="${param.sayHello}">
<!-- Let's welcome the user ${param.name} -->
Hello ${param.name}!
</c:if>
--%>

</body>
</html>
用JAVAMAIL作了个邮件传送的例子却怎么也实现不了,填写了信息后到JavaMail.jsp就什么也不显示了也没有错误提示。我用的126的油箱。是不是写的有问题请高手指教以下。 本人万分感激!!!谢谢

搜索更多相关主题的帖子: JavaMail 
2007-04-29 22:26
快速回复:JavaMail问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.023167 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved