欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

javamail在jsp中调用

程序员文章站 2022-06-22 13:46:06
javamail在(sun企业级应用的首选)中调用 一
javamail在(sun企业级应用的首选)中调用 一
<html>
<body>
<form action="sendmail.jsp(sun企业级应用的首选)" method="post">
<table align="center">
<tr>
<td width="50%">
to:<br><input name="to" size="25">
</td>
<td width="50%">
from:<br><input name="from" size="25">
</td>
</tr>
<tr>
<td colspan="2">
subject:<br><input name="subject" size="50">
</td>
</tr>
<tr>
<td colspan="2">
<p>message:<br><textarea name="text" rows=25 cols=85></textarea></p>
</td>
</tr>
</table>
<input type="submit" name="cb_submit" value=" send ">
<input type="reset" name="cb_reset" value=" clear ">
</form>
</body>
</html>

javamail在jsp(sun企业级应用的首选)中调用 二
<%@ page
import=" javax.mail.*, javax.mail.internet.*, javax.activation.*,java.util.*"
%>
<html>
<head>
<title>jsp(sun企业级应用的首选) meets javamail, what a sweet combo.</title>
</head>
<body>
<%

try{
properties props = new properties();
session sendmailsession;
store store;
transport transport;


sendmailsession = session.getinstance(props, null);

props.put("mail.smtp.host", "smtp.jsp(sun企业级应用的首选)insider.com");

message newmessage = new mimemessage(sendmailsession);
newmessage.setfrom(new internetaddress(request.getparameter("from")));
newmessage.setrecipient(message.recipienttype.to, new internetaddress(request.getparameter("to")));
newmessage.setsubject(request.getparameter("subject"));
newmessage.setsentdate(new date());
newmessage.settext(request.getparameter("text"));

transport = sendmailsession.gettransport("smtp");
transport.send(newmessage);
%>
<p>your mail has been sent.</p>
<%
}
catch(messagingexception m)
{
out.println(m.tostring());
}
%>
</body>
</html>