我用jsp做好的邮件发送 在windows上面运行得好好的 移植到linux上面就不能运行了 请问下 移植到javamail发送邮件 移植到linux上 一般要注意什么啊?
我已经将mail.jar和activation.jar放到了java的lib下面 tomcat的lib下面 和工程文件的WEB-INF的lib下面 我做了一个简单的测试程序<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<jsp:useBean id="JavaBean" scope="page" class="JavaBean.Bean" />
<%@ page import="javax.mail.*" %>
<%@ page import="javax.mail.internet.*" %>
<%@ page import="javax.activation.*" %>
<%@ page import="java.util.*" %>
<%@ page import="java.io.*" %>
<%@ page import="java.sql.*" %>
<%
try{
request.setCharacterEncoding("UTF-8");
String strHost="smtp.sohu.com";
String strUserName = "[email protected]";
String strPassWord = "1985113";
String strForm = "[email protected]";
String strToList =request.getParameter("mail");
String strSubject =request.getParameter("user");
String strMessage = request.getParameter("company"); Properties props = new Properties();
props.put("mail.smtp.host", strHost);
props.put("mail.smtp.auth", "true");
Session MailSession = Session.getDefaultInstance(props, null);
MailSession.setDebug(true);
Message msg = new MimeMessage(MailSession);
InternetAddress from = new InternetAddress(strForm);
msg.setFrom(from);
if (strToList!=null && strToList.length()>0){
InternetAddress[] to = { new InternetAddress(strToList) };
msg.setRecipients(Message.RecipientType.TO, to);
}
else{
out.println ("Get send to addresses failed!");
}
if (strSubject != null)
msg.setSubject(strSubject);
msg.setSentDate(new java.util.Date());
if (strMessage!=null && strMessage.trim().length()>0){
msg.setText("111,"+strToList+strMessage +"\r\n"+ strSubject +"\r\n"+ "2222");
}
else{
out.println("No message to be send!");
}
///////////////////////////////////////////////
msg.saveChanges();
Transport transport = MailSession.getTransport("smtp");
transport.connect(strHost, strUserName, strPassWord);
transport.sendMessage(msg, msg.getAllRecipients());
transport.close();
out.println("<script language='javascript'>alert('mail has been sent,Please check your mail for Entrance!!');</script>");
}
catch(AuthenticationFailedException ae){
ae.printStackTrace();
}
catch(SendFailedException sf){
Address[] invalid = sf.getInvalidAddresses();
Address[] valid = sf.getValidSentAddresses();
Address[] unsend = sf.getValidUnsentAddresses();
sf.printStackTrace();
}
catch(Exception e){
e.printStackTrace();
}
%>`程序到///////////////////////////////////////就不往下运行了 哪位在linux下面做过邮件发送的帮忙看看 谢谢了
我已经将mail.jar和activation.jar放到了java的lib下面 tomcat的lib下面 和工程文件的WEB-INF的lib下面 我做了一个简单的测试程序<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<jsp:useBean id="JavaBean" scope="page" class="JavaBean.Bean" />
<%@ page import="javax.mail.*" %>
<%@ page import="javax.mail.internet.*" %>
<%@ page import="javax.activation.*" %>
<%@ page import="java.util.*" %>
<%@ page import="java.io.*" %>
<%@ page import="java.sql.*" %>
<%
try{
request.setCharacterEncoding("UTF-8");
String strHost="smtp.sohu.com";
String strUserName = "[email protected]";
String strPassWord = "1985113";
String strForm = "[email protected]";
String strToList =request.getParameter("mail");
String strSubject =request.getParameter("user");
String strMessage = request.getParameter("company"); Properties props = new Properties();
props.put("mail.smtp.host", strHost);
props.put("mail.smtp.auth", "true");
Session MailSession = Session.getDefaultInstance(props, null);
MailSession.setDebug(true);
Message msg = new MimeMessage(MailSession);
InternetAddress from = new InternetAddress(strForm);
msg.setFrom(from);
if (strToList!=null && strToList.length()>0){
InternetAddress[] to = { new InternetAddress(strToList) };
msg.setRecipients(Message.RecipientType.TO, to);
}
else{
out.println ("Get send to addresses failed!");
}
if (strSubject != null)
msg.setSubject(strSubject);
msg.setSentDate(new java.util.Date());
if (strMessage!=null && strMessage.trim().length()>0){
msg.setText("111,"+strToList+strMessage +"\r\n"+ strSubject +"\r\n"+ "2222");
}
else{
out.println("No message to be send!");
}
///////////////////////////////////////////////
msg.saveChanges();
Transport transport = MailSession.getTransport("smtp");
transport.connect(strHost, strUserName, strPassWord);
transport.sendMessage(msg, msg.getAllRecipients());
transport.close();
out.println("<script language='javascript'>alert('mail has been sent,Please check your mail for Entrance!!');</script>");
}
catch(AuthenticationFailedException ae){
ae.printStackTrace();
}
catch(SendFailedException sf){
Address[] invalid = sf.getInvalidAddresses();
Address[] valid = sf.getValidSentAddresses();
Address[] unsend = sf.getValidUnsentAddresses();
sf.printStackTrace();
}
catch(Exception e){
e.printStackTrace();
}
%>`程序到///////////////////////////////////////就不往下运行了 哪位在linux下面做过邮件发送的帮忙看看 谢谢了
你的linux那台服务器能上网发送邮件吗?
javax.mail.NoSuchProviderException: smtp
这个问题 请问又该怎么解决啊
你的linux有没有装XWindow? 如果有, 那一般会带收发邮件的软件(CentOS上带的是Evoution),你用这个配置一个邮箱发送邮件试一下,如果这个能发,那可能是你的程序有问题了.如果这个也不能发,估计是网络或防火墙问题.
telnet smtp.21cn.com 25
如果能连接则会返回这样的文字:
220 aisp5-smtp@dg KBAS is ready否则肯定是你的网络或防火墙有问题