您的位置:首页-> 技术开发-> JSP学院-> 邮件发送简单例子-bean文件

邮件发送简单例子-bean文件
作者:admin 时间:2000-12-10  来自:ASP教程  选择阅读文体:


SimpleSendMessage.java

import java.util.*;

import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;

public class SimpleSendMessage {

public static void main(String[] args) {

// Collect the necessary information to send a simple message
// Make sure to replace the values for host, to, and from with
// valid information.
// host - must be a valid smtp server that you currently have
// access to.
// to - whoever is going to get your email
// from - whoever you want to be. Just remember that many smtp
// servers will validate the domain of the from address
// before allowing the mail to be sent.
String host = "server.myhost.com";
String to = "YourFriend@somewhere.com";
String from = "MeMeMe@myhost.com";
String subject = "JSP Rules!";
String messageText = "I am sending a message using the"
+ " JavaMail API.\nI can include any text that I want.";
boolean sessionDebug = false;

// Create some properties and get the default Session.
Properties props = System.getProperties();
props.put("mail.host", host);
props.put("mail.transport.protocol", "smtp");

Session session = Session.getDefaultInstance(props, null);

// Set debug on the Session so we can see what is going on
// Passing false will not echo debug info, and passing true
// will.
session.setDebug(sessionDebug);

try {

// Instantiate a new MimeMessage and fill it with the
// required information.
Message msg = new MimeMessage(session);

msg.setFrom(new InternetAddress(from));
InternetAddress[] address = {new InternetAddress(to)};
msg.setRecipients(Message.RecipientType.TO, address);
msg.setSubject(subject);
msg.setSentDate(new Date());
msg.setText(messageText);

// Hand the message to the default transport service
// for delivery.
Transport.send(msg);
}
catch (MessagingException mex) {

mex.printStackTrace();
}
}
}



上一篇:邮件发送简单例子-html文件 下一篇:jsp源码实例5(cookie)

GoogLe中搜索“邮件发送简单例子-bean文件”相关内容...
百 度 中搜索“邮件发送简单例子-bean文件”相关内容...
一 搜 中搜索“邮件发送简单例子-bean文件”相关内容...

相关文章

.Net专栏
Script
ASP学院
PHP学院
Web服务器
CGI学院
XML学院
SQL学院
JSP学院
SMS学院
提升QQ等级 QQ挂机升级外挂
国内首发 韩国版QQ自定义头像
挖掘Windows XP系统安装盘中的神秘宝藏
初见photoshop8.0的庐山真面目!
BT下载速度之战:Bitcomet对决比特精灵
腾讯最新漏洞-------QQ红钻任你拿
Windows XP 的安装
如何制作万能DVD
浅谈Windows XP SP2补丁包的安装及使用
RM,RMVB转VCD
购物车的源程序
Eclipse中使用ANT
JAVA/JSP学习系列之一(JDK安装)
Windows下JSP开发环境的配置
Java学习的捷径
J2EE 开发购物网站 经验篇 - 建表
实战 J2EE 开发购物网站 - 创建数据库
实战 J2EE 开发购物网站 二
JSP开发前菜鸟设置篇
用Java实现HTTP文件队列下载