需要一份能够连接163 QQ等的JSP 或者 JAVA 代码,,使用javamail来开发的,我之前已经写了一写,但是无法验证163 QQ的,可以严整连接sina的帮修改能连接也得分代码如下:<%@ page language="java" import="java.util.*" contentType="text/html;charset=gbk" pageEncoding="gbk"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'email.jsp' starting page</title>
    
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">    
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->  </head>
  
  <body>
    This is my JSP page. <br>
    <form action="sendMail.jsp" method="post">
    <select name="stmpType">
     <option value="smtp.sina.com">新浪</option>
     <option value="smtp.163.com">网易</option>
     <option value="smtp.qq.com">qq</option>
    </select>
    <input type="file" name="lastFilename" size="20" />
     <table border="1" >
     <tr>
     <td>to:<input type="text" name="to"  value="[email protected]"/></td>
     <td>From:<input type="text" name="from" value="[email protected]" />password:<input type="text" name="password" value="systemresponse"/></td>
     </tr>
     <tr>
     <td>主题</td>
     <td><input type="text" name="subject" value="helloMe!" /></td>
     </tr>
     <tr>
     <td colspan="2">
     <textarea rows="10" cols="45" name="text"  />"hello world"</textarea>
     </td>
     </tr>
     <tr>
     <td colspan="2">
     <input type="submit" name="sub1" value="提交" />
     </td>
     </tr>
     </table>
    </form>
  </body>
</html>
<%@ page language="java" import="java.util.*" contentType="text/html;charset=gbk" pageEncoding="UTF-8"%>
<%@ page import="com.elan.mail.*"%>
<%@ page import="javax.mail.*"%>
<%@ page import="javax.mail.internet.*"%>
<%@ page import="java.text.*"%>
<%@ page import="javax.activation.*" %>
<%@ page import="com.jspsmart.upload.*" %>
<html>
<head> <title>My JSP 'sendMail.jsp' starting page</title> </head> <body>
支持smtp.sina.com<br>
郁闷多多!
<br>
<%
request.setCharacterEncoding("gbk");
out.print("to:");
out.print(request.getParameter("to") + "<br>");
out.print("from:");
out.print(request.getParameter("from") + "<br>"); out.print("text:");
out.print(request.getParameter("text") + "<br>");
%>
<%
SmartUpload mySmartUpload = new  SmartUpload();
//com.jspsmart.upload.Request  myRequest= mySmartUpload.getRequest();
//request.setCharacterEncoding("UTF-8");
String from = request.getParameter("from"); // 发邮件的出发地(发件人的信箱)
String to = request.getParameter("to"); // 发邮件的目的地(收件人信箱)
String password = request.getParameter("password");
String subject = request.getParameter("subject");
String text = request.getParameter("text");
String host = request.getParameter("stmpType");//发送服务器类型
out.println("host: " + host);
out.println("<br>password: " + password);
try {
String fullFilename = request.getParameter("lastFilename");
//String filename = config.getServletContext().getRealPath(fullFilename);
int lio = fullFilename.lastIndexOf('\\');
String filename = fullFilename.substring(lio + 1); 
out.println("<br>filename: " + filename);
//out.println(lio);
Session Sendsession =null;
// Get system properties
Properties props = System.getProperties();
//if(true)return ;
// Setup mail server
props.put("mail.smtp.host", host);

props.put("mail.smtp.auth", "true"); // 这样才能通过验证

MyAuthenticator myauth = new MyAuthenticator(from,
password);

Sendsession = Session.getInstance(props, myauth);
Sendsession.setDebug(false);
// session.setDebug(true); // Define message
MimeMessage message = new MimeMessage(Sendsession);
// Set the from address
message.setFrom(new InternetAddress(from)); // Set the to address
message.addRecipient(Message.RecipientType.TO, new InternetAddress(to)); // Set the subject
message.setSubject(subject); // Set the content
message.setText(text,"text/html;charset=utf-8");

///附件
Multipart ltp = new MimeMultipart();
MimeBodyPart messageBodyPart = new MimeBodyPart();
DataSource source = new FileDataSource(fullFilename);
messageBodyPart.setDataHandler(new DataHandler(source));
messageBodyPart.setFileName(filename);
ltp.addBodyPart(messageBodyPart);
message.setContent(ltp);

DateFormat df = new SimpleDateFormat("EEEE-MMMM-dd-yyyy-HH-mm-ss");
Date d = df.parse("星期二-八月-8-1985-8-8-8");
message.setSentDate(d); message.saveChanges(); //Transport.send(message);
Transport transport;
transport = Sendsession.getTransport("smtp");   
   transport.send(message);   
out.println("<br>send successly");
} catch (Exception e) {
out.println("发送失败");
out.println("不支持" + host);
out.println(e);
e.printStackTrace();
}
%>
</body>
</html>可以转附件.java 的代码 我就不写出来了,差不多的!

解决方案 »

  1.   

    163邮箱对于部分邮箱禁用POP3,可能是这个原因,你试试看foxmail能收163和QQ邮箱的不
      

  2.   

    用javaMail我试过,在本地开个服务器,发送消息到QQ,126都能发送,发送到126邮箱正常,发送到QQ上面,邮箱全部在垃圾邮件里面
      

  3.   

    163老的帐号是可以用javamail作出来的,新注册的帐号一般不能用的