使用的maven依赖:
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>javax.mail</artifactId>
<version>1.4.7</version>
</dependency>
配置文件mail.properties如下:
# 邮箱配置
email.username=your-email@example.com
email.password=your-email-password
email.server=smtp.example.com
email.auth=true
email.port=465
在Foxmail的配置如下:
代码如下:
import org.springframework.stereotype.Component;
import javax.activation.DataHandler;
import javax.mail.*;
import javax.mail.internet.*;
import javax.mail.util.ByteArrayDataSource;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutput