我是Spring的新手,做个邮件发送遇到问题了,大家帮忙看看
代码如下:
1.beans.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<bean id="mailSender" class="cn.com.action.Senders">
<property name="mailSender"><ref bean="mailSend"/> </property>
</bean>   
<bean id="mailSend" class="org.springframework.mail.javamail.JavaMailSenderImpl">
        <property name="host" value="smtp.sina.com"/>
        <property name="username" value="itsavour"/>
        <property name="password" value="110110"/>
         <property name="javaMailProperties">
            <props>
                <prop key="mail.smtp.auth">true</prop>
            </props>
        </property>
        
    </bean>
</beans> 
2.Senders.javapackage cn.com.action;import javax.mail.Message;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.mail.MailException;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessagePreparator;public class Senders{    private JavaMailSender mailSender;
    
    public JavaMailSender getMailSender() {
return mailSender;
}
public void setMailSender(JavaMailSender mailSender) {
        this.mailSender = mailSender;
    }
    public void placeOrder() {        // Do the business calculations...        // Call the collaborators to persist the order...
        
        MimeMessagePreparator preparator = new MimeMessagePreparator() {
        
            public void prepare(MimeMessage mimeMessage) throws Exception {
        
                mimeMessage.setRecipient(Message.RecipientType.TO, 
                        new InternetAddress("[email protected]"));
                mimeMessage.setFrom(new InternetAddress("[email protected]"));
                mimeMessage.setText("thank you for placing order. Your order number is");
                }
        };
        try {
            this.mailSender.send(preparator);
        }
        catch (MailException ex) {
            // simply log it and go on...
            System.err.println(ex.getMessage());            
        }
    }
    public static void main(String[] args) {
     ApplicationContext cxt = new ClassPathXmlApplicationContext("beans.xml");
     Senders s = (Senders)cxt.getBean("mailSender");
//Senders s = new Senders();
s.placeOrder();
}
}
我在Senders.java中写了个main方法来做测验。但是运行出错啦
错误如下:
Mail server connection failed; nested exception is javax.mail.MessagingException: Could not connect to SMTP host: smtp.sina.com, port: 25;
  nested exception is:
java.net.ConnectException: Connection timed out: connect
大家帮忙看看 谢谢啦
分数不多 只为求知 再次谢谢了

解决方案 »

  1.   

    错误如下:
    Mail server connection failed; nested exception is javax.mail.MessagingException: Could not connect to SMTP host: smtp.sina.com, port: 25;
      nested exception is:
    java.net.ConnectException: Connection timed out: connect---------------
    连接超时,在自己机器上连接这个端口看看,xp下的命令为: telnet smtp.sina.com 25
    先确定自己本机是否可以访问这个地址的25端口。
    如果不可以,尝试关闭下防火墙看看。
      

  2.   

    连接新浪邮件服务器smtp.sina.com, port: 25超时。先看一下sina邮件服务器是这样的吗?还有端口。
    telnet 测试一下
      

  3.   

    我在命令行下输入了连接命令,结果如下:只有一行
    220 irxd5-183.sinamail.sina.com.cn ESMTP
    是不是没连接上啊
      

  4.   

    sina的smtp服务器我查了 是对的 smtp.sina.com 端口新浪没要求 我用的是默认的
    命令行连接sina 连接不上 怎么办??
    继续求助中