⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 0043.htm

📁 JspServlet教程专栏 对javaservlet讲述的非常详细
💻 HTM
字号:
<html>

<head>
<title>新时代软件教程:操作系统 主页制作 服务器 设计软件 网络技术 编程语言 文字编辑</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style>
<!--
body, table {font-size: 9pt; font-family: 宋体}
a {text-decoration:none}
a:hover {color: red;text-decoration:underline}
.1  {background-color: rgb(245,245,245)}
-->
</style>
</head>
<p align="center"><script src="../../1.js"></script></a>
    <p align="center"><big><strong>jsp发送邮件实例(高手必读)</strong></big></p>

<div align="right">(文/blackwhites)</div>

&nbsp;看看我从老外那骗到的<br>
vishal_donth gave this response on 10/18/2000: <br>
//these are the pakages to be imported from<br>
// Java Mail<br>
//The Java Mail PAckage either be dowloaded <br>
//seperately<br>
//or else is Available in the J2sdkee1.2 <br>
// (Java Enterprise Edition)<br>
<br>
import javax.mail.*;<br>
import javax.mail.internet.*;<br>
import java.util.*;<br>
<br>
<br>
//This function can be used to send the mail <br>
// with the parameters given to it<br>
//U have to specify the smtp server through <br>
//which u have to send the mail<br>
//since i was trying with a homenetmail <br>
//account i directly sent the mail its server<br>
//For sending this mail u need a mail server <br>
//which lets u to relay the messages<br>
//Try this thing for sending to a <br>
//www.homenetmail.com account because it lets <br>
//u send <br>
//mails to the accounts like example try <br>
//sending it to a &quot;abc@homenetmail.com&quot; <br>
//account.Create the mail account in homenet <br>
//mail first. If u get any other server which <br>
//supports relaying u can try this on that <br>
//also.<br>
<br>
//Use this function in ur Servlet to send <br>
//mail by calling the function with the <br>
//parameters<br>
<br>
public void sendMail(String toAddr, String subject, String body, String fromAddr)throws RemoteException{<br>
try{<br>
Properties props = new Properties();<br>
props.put(&quot;mail.smtp.host&quot;,&quot;mail.homenetmail.com&quot;);<br>
//Here we specify the SMTP server through <br>
//which the mail should be delivered<br>
Session session = Session.getDefaultInstance(props, null);<br>
Message msg = new MimeMessage(session);<br>
msg.setFrom(new InternetAddress(fromAddr)); <br>
//Specify the From Address<br>
InternetAddress[] tos =InternetAddress.parse(toAddr); <br>
//Specify the To Address<br>
msg.setRecipients(Message.RecipientType.TO,tos);<br>
msg.setSubject(subject);<br>
//Specify the Subject<br>
msg.setText(body); <br>
//Specify the Body <br>
Transport.send(msg);<br>
System.out.println(&quot;Message is Sent&quot;);<br>
}<br>
catch(Exception e){<br>
System.out.println(e);<br>
}<br>
}<br>
<br>
// U have to run this function on a computer <br>
//which is directly connected<br>
// to internet but not through a <br>
//proxy......or else use a proxy which <br>
//supports SMTP<br>

  </table>
<p align="center"><script src="../../2.js"></script></a>
</body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -