spring发送邮件

package com.lq56.util;

import java.util.List;
import java.util.Properties;

import org.apache.commons.lang.StringUtils;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSenderImpl;

public class SendEmail {
	
	public void send(List<String> toAddresss,String subject,String text){
		JavaMailSenderImpl mail = new JavaMailSenderImpl();
		Properties prop = new Properties();
		prop.setProperty("mail.smtp.auth", "true");
		mail.setHost("mail.test.com");
		mail.setPort(25);
		mail.setJavaMailProperties(prop);
		mail.setUsername("[email protected]");
		mail.setPassword("test.com");
		SimpleMailMessage smm = new SimpleMailMessage();
		smm.setFrom("[email protected]");
		smm.setSubject(subject);
		smm.setText(text);
		try {
			if(StringUtils.isNotEmpty(text)&&StringUtils.isNotEmpty(subject)){
			for(String toAddress:toAddresss){
				smm.setTo(toAddress);
				mail.send(smm);
			}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}

 

你可能感兴趣的:(spring)