---
title: "spring发送邮件"
author: "yanlp"
date: "2011-09-16T11:57:21Z"
tags: []
categories: ["编程语言"]
slug: "spring"
draft: false
lastmod: "2011-09-16T11:57:21Z"
id: 1173343
url: "https://yanlp.iteye.com/blog/1173343"
---

```
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("test@test.com");
		mail.setPassword("test.com");
		SimpleMailMessage smm = new SimpleMailMessage();
		smm.setFrom("test@test.com");
		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();
		}
	}

}
```