我在做用javamail发邮件时,遇到一个难题,请大哥大姐帮忙,可以发送内部邮件,但发到sohu。163等外不网时 出错,说发送目标不知道;org.apache.jasper.JasperException: Invalid Addresses;
  nested exception is:
class com.sun.mail.smtp.SMTPAddressFailedException: 550 <[email protected]>, Recipient unknown
代码如下:
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<%@ page import="javax.mail.*"import="javax.mail.internet.*"import="javax.activation.*"import="java.util.*"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head><body>
<%String host = "mail.gxmie.net";
String username="[email protected]";
String password="3316122";
Session sendMailSession;
Transport transport;
// Get system propertiesProperties props = System.getProperties();
// Setup mail server
props.put("mail.smtp.host", host);
// Get session sendMailSession= Session.getDefaultInstance(props,null);
// Define message
MimeMessage message = new MimeMessage(sendMailSession); sendMailSession.setDebug(true);
message.setFrom(new InternetAddress("[email protected]"));
message.addRecipient(Message.RecipientType.TO,new InternetAddress("[email protected]"));
message.setSubject("Hello JavaMail");
message.setText("Welcome to JavaMail");
// Send messagemessage.saveChanges(); // implicit with send()
transport=sendMailSession.getTransport("smtp");
transport.connect(host, username, password);
transport.sendMessage(message, message.getAllRecipients());
transport.close();%>
</body>
</html>