try{
String tto=request.getParameter("to");
String ttitle=request.getParameter("title");
String tcontent=request.getParameter("content");
Properties props=new Properties();
props.put("mail.smtp.host","mail.EchoChina.net");
props.put("mail.smtp.auth","true");
Session s=Session.getInstance(props);
s.setDebug(true);
MimeMessage message=new MimeMessage(s);
//给消息对象设置发件人/收件人/主题/发信时间
InternetAddress from=new InternetAddress("[email protected]");
message.setFrom(from);
InternetAddress to=new InternetAddress(tto);
message.setRecipient(Message.RecipientType.TO,to);
message.setSubject(ttitle);
message.setSentDate(new Date());
//给消息对象设置内容
BodyPart mdp=new MimeBodyPart();//新建一个存放信件内容的BodyPart对象
mdp.setContent(tcontent,"text/html;charset=gb2312");//给BodyPart对象设置内容和格式/编码方式
Multipart mm=new MimeMultipart();//新建一个MimeMultipart对象用来存放BodyPart对象(事实上可以存放多个)
mm.addBodyPart(mdp);//将BodyPart加入到MimeMultipart对象中(可以加入多个BodyPart)
message.setContent(mm);//把mm作为消息对象的内容
message.saveChanges();
Transport transport=s.getTransport("smtp");
transport.connect("mail.EchoChina.net","[email protected]","password!!!");//以smtp方式登录邮箱
transport.sendMessage(message,message.getAllRecipients());
transport.close();
%>

解决方案 »

  1.   

    好像是没有认证,认证可以如下:
    SmtpAuthenticator sa = new SmtpAuthenticator(username, password);
    Session sess = Session.getInstance(props, sa);
    我也没有测试,楼主可以试试.
      

  2.   

    验证,吼吼.
    以前写过,不过忘记了.
    smtp有些是要验证的
    看看api吧,里边有例子
      

  3.   

    stmp的身份验证好像126不提供了,你可以去www.tom.com申请一个免费邮箱,他提供stmp身份验证