消息-邮件springMail

IO

Email :: Spring Framework

依赖

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-mail</artifactId>
</dependency>

The Spring Framework provides an abstraction for sending email by using the JavaMailSender interface, and Spring Boot provides auto-configuration for it as well as a starter module.

🔝See the reference documentation for a detailed explanation of how you can use JavaMailSender.

SimpleMailMessage

public class SimpleMailMessage implements MailMessage, Serializable {

    @Nullable
    private String from;

    @Nullable
    private String replyTo;

    @Nullable
    private String[] to;

    //抄送
    @Nullable
    private String[] cc;

    //密送
    @Nullable
    private String[] bcc;

    @Nullable
    private Date sentDate;

    @Nullable
    private String subject;

    @Nullable
    private String text;
spring:
  mail:
    host: smtp.163.com #SMTP服务器地址
    username: 1524 #登陆账号
    password: HIOIT   #登陆密码(或授权码)   
    properties:
#      mail.smtp.auth: true
#      mail.smtp.starttls.enable: true
      mail.smtp.connectiontimeout: 5000
      mail.smtp.timeout: 3000
      mail.smtp.writetimeout: 5000
  servlet:
    multipart:
      max-file-size: 10MB #限制单个文件大小
      max-request-size: 50MB #限制请求总量
@Service
public class EmailService {

    @Resource
    private JavaMailSender mailSender;

    public void sendEmail(String to, String subject, String text) {
        SimpleMailMessage message = new SimpleMailMessage();
        message.setTo(to);
        message.setSubject(subject);
        message.setText(text);
        message.setCc();
        mailSender.send(message);
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值