javamail,发送邮件(急,急,急!!) 我也是这样调试过来的,刚才!呵呵transport.sendMessage(msg,msg.getRecipients(Message.RecipientType.TO)); 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 因为smtp服务器需要认证,你把认证信息添进去就可以了 Properties props = new Properties();props.put("mail.smtp.auth","true"); //smtp认证 Session s = Session.getInstance(props,null); 这是本人写的一个Java MailBean,绝对好用!//------------------------------------------------------------------------------// Copyright 2002//// Owner: 吴继勇//// Class: MailBean//------------------------------------------------------------------------------// 邮件发送Bean//package at.bean;import at.dao.*;import at.pub.*;import java.util.*;import java.text.SimpleDateFormat;import javax.mail.*;import javax.mail.internet.*;import javax.activation.*;public class MailBean { private static MailBean instance; protected String sHost = ""; // 发送邮件的SMTP服务器 protected String sFrom = ""; // 邮件发送者 protected String sUserName = ""; // 发送者的用户名 protected String sPassword = ""; // 发送者的用户密码 /** * 发送邮件 * */ public void sendMail( String sTo, String sSubject, String sBody ) { try { //Properties props = new Properties(); Properties props = System.getProperties(); // Setup mail server props.put("mail.smtp.host", sHost); props.put("mail.smtp.auth", "true"); // Get session Session session = Session.getDefaultInstance(props); // watch the mail commands go by to the mail server session.setDebug(false); // Define message MimeMessage message = new MimeMessage( session ); message.setFrom( new InternetAddress( sFrom ) ); message.addRecipient( Message.RecipientType.TO, new InternetAddress( sTo ) ); message.setSubject( sSubject ); message.setText( sBody ); // Send message message.saveChanges(); Transport transport = session.getTransport("smtp"); transport.connect( sHost, sUserName, sPassword ); transport.sendMessage( message, message.getAllRecipients() ); transport.close(); } catch ( Exception e ) { LogBean logBean = LogBean.getInstance(); logBean.outError( sTo + ":" + e.getMessage() ); } } /** * 实例 */ public static synchronized MailBean getInstance() { if(instance == null) instance = new MailBean(); return instance; } /** * 初始化 */ private MailBean() { // 参数管理器 ParameterFactory paraFactory = ParameterFactory.getInstance(); sHost = paraFactory.getMailName( "host" ); sFrom = paraFactory.getMailName( "from" ); sUserName = paraFactory.getMailName( "username" ); sPassword = paraFactory.getMailName( "password" ); }} 再附上JSP中调用的方法: MailBean mailBean = MailBean.getInstance(); mailBean.sendMail( sToMail, sEmailSubject, sEmailBody ); 应用间跳转,原来应用的session值会不会丢失。 请教动态在一张图片上生成热点,并且想把这些热点的边框都显示出来 在JSP中打开本地电脑中的文件(如pdf,word,txt等) jsp连接sql2000出现的问题 日期显示问题? 静态网页怎么在两个页面间传递静态图片参数 扩展标签库及struts 关于JSP的图例,毕业答辩用的.给100分 最近发现大家对jsp、servlet程序员,有点不屑的感觉,你怎么认为呢? 两个项目互相之间的跳转 关于数据库(oracle)数据查询的问题,困惑我很久了,请高手指点!! 拿分问题,关于if语句
props.put("mail.smtp.auth","true"); //smtp认证
Session s = Session.getInstance(props,null);
// Copyright 2002
//
// Owner: 吴继勇
//
// Class: MailBean
//------------------------------------------------------------------------------// 邮件发送Bean
//package at.bean;import at.dao.*;
import at.pub.*;
import java.util.*;
import java.text.SimpleDateFormat;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;public class MailBean {
private static MailBean instance; protected String sHost = ""; // 发送邮件的SMTP服务器
protected String sFrom = ""; // 邮件发送者
protected String sUserName = ""; // 发送者的用户名
protected String sPassword = ""; // 发送者的用户密码 /**
* 发送邮件
*
*/
public void sendMail( String sTo, String sSubject, String sBody ) {
try {
//Properties props = new Properties();
Properties props = System.getProperties();
// Setup mail server
props.put("mail.smtp.host", sHost);
props.put("mail.smtp.auth", "true");
// Get session
Session session = Session.getDefaultInstance(props); // watch the mail commands go by to the mail server
session.setDebug(false);
// Define message
MimeMessage message = new MimeMessage( session );
message.setFrom( new InternetAddress( sFrom ) );
message.addRecipient( Message.RecipientType.TO, new InternetAddress( sTo ) );
message.setSubject( sSubject );
message.setText( sBody );
// Send message
message.saveChanges();
Transport transport = session.getTransport("smtp");
transport.connect( sHost, sUserName, sPassword );
transport.sendMessage( message, message.getAllRecipients() );
transport.close();
}
catch ( Exception e ) {
LogBean logBean = LogBean.getInstance();
logBean.outError( sTo + ":" + e.getMessage() );
}
} /**
* 实例
*/
public static synchronized MailBean getInstance() {
if(instance == null)
instance = new MailBean();
return instance;
} /**
* 初始化
*/
private MailBean() {
// 参数管理器
ParameterFactory paraFactory = ParameterFactory.getInstance();
sHost = paraFactory.getMailName( "host" );
sFrom = paraFactory.getMailName( "from" );
sUserName = paraFactory.getMailName( "username" );
sPassword = paraFactory.getMailName( "password" );
}
}
mailBean.sendMail( sToMail, sEmailSubject, sEmailBody );