当前位置:   article > 正文

springboot集成邮件功能_simplemailmessage port

simplemailmessage port

在yml文件中进行配置

mail:
  #    host不配置会注入失败
  debug: true
  host: xxxxx
  port: 25
  username: xxxx
  password: xxxx
  #default-encoding: UTF-8
  #protocol: smtp
  properties:
    mail:
      smtp:
        auth: true
        ssl:
          enable: true
#              required: true

注意mail一定要配置在

spring:下面,否则装配的时候会报找不到这个bean
@Service
public class MailServiceImpl implements MailService {
    @Autowired
    JavaMailSender javaMailSender;
    @Autowired
    AppNoticeDetailRepository appNoticeDetailRepository;

    //简单邮件发送
    @Override
    public void sendSimpleSender(String from,String[] to,String cc,String subject,String content){
        SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
        simpleMailMessage.setFrom(from);
        simpleMailMessage.setTo(to);
        simpleMailMessage.setCc(cc);
        simpleMailMessage.setSubject(subject);
        simpleMailMessage.setText(content);
        javaMailSender.send(simpleMailMessage);
    }

    @Override
    public void sendMail(MailVo mailVo){
        SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
        simpleMailMessage.setFrom(mailVo.getFromMail());
        simpleMailMessage.setTo(mailVo.getToMail());
        simpleMailMessage.setSubject(mailVo.getTitle());
        simpleMailMessage.setText(mailVo.getContent());
        javaMailSender.send(simpleMailMessage);
    }
    @Override
    public void sendMailByNoticeDetailId(Long noticeDetailId){
        AppNoticeDetail appNoticeDetail=appNoticeDetailRepository.searchById(noticeDetailId);
        SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
        String personId=appNoticeDetail.getPersonId();
        simpleMailMessage.setFrom(TaskStatus.NOTICE_NOTREAD);
        simpleMailMessage.setTo(personId.split(","));
        simpleMailMessage.setSubject("通知");
        simpleMailMessage.setText(appNoticeDetail.getContent());
        javaMailSender.send(simpleMailMessage);
    }
}

 

当发送给多个人邮件的时候,默认为密送模式,可以采用数组的方式进行邮件的发送

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/weixin_40725706/article/detail/608205
推荐阅读
相关标签
  

闽ICP备14008679号