解决ss3ex中mail集成bug

java1.4时发邮件是好的,由于ss3ex用的是java5的平台,集成spring2.5发邮件发不了,解决办法:先删后加
先删2个jar:geronimo-activation_1.1_spec-1.0.2.jar 和 geronimo-javamail_1.4_spec-1.3.jar
后加2个jar:activation.jar 和 mail.jar

附简单完整的代码:
1、建一个spring_mail.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"
	default-lazy-init="true">

	<description>Email配置</description>

	<!-- 邮件发送器 -->
	 <bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">  
         <property name="host" value="smtp.sina.com" />  
         <property name="port" value="25" />  
         <property name="username" value="sanshang" />  
         <property name="password" value="sanshang" />  
         <property name="javaMailProperties">  
             <props>  
                 <prop key="mail.smtp.auth">true</prop>  
                 <!-- gmail smtp server必须参数 -->
				<prop key="mail.smtp.starttls.enable">true</prop>
             </props>  
         </property>  
     </bean>  

</beans>

2、写个EmailService.java
package com.service.email;

import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.stereotype.Service;
/**
 * Email service
 */
@Service
public class EmailService {
	@Autowired
	private JavaMailSender mailSender;

	public void sendEmail(String text) {
		MimeMessage mailMessage = mailSender.createMimeMessage();
		try {
			MimeMessageHelper mail = new MimeMessageHelper(mailMessage, true,
					"GBK");
			mail.setFrom("[email protected]");
			mail.setTo("[email protected]");
			mail.setSubject("三上的来信");
			mail.setText("<html><head></head>"
									+ "<body><h1>Hello! 三上!<img src=http://www.baidu.com/img/baidu_logo.gif>"
									+ "</h1></body></html>", true);
			mailSender.send(mailMessage);
			System.out.println("发送OK...");
		} catch (MessagingException e) {
			e.printStackTrace();
		}
	}
}

你可能感兴趣的:(spring,xml,qq,Gmail)