content: package com.smilcool.server.core.service.impl;
  
  import com.smilcool.server.common.exception.SmilcoolException;
  import com.smilcool.server.core.service.MailService;
  import lombok.extern.slf4j.Slf4j;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.beans.factory.annotation.Value;
  import org.springframework.mail.SimpleMailMessage;
  import org.springframework.mail.javamail.JavaMailSender;
  import org.springframework.stereotype.Service;
  
  /**
   * @author Angus
   * @date 2019/5/27
   */
  @Slf4j
  @Service
  public class MailServiceImpl implements MailService {
  
      @Autowired
      private JavaMailSender mailSender;
  
      @Value("${spring.mail.username}")
      private String from;
  
      @Override
      public void sendSimpleMail(String to, String subject, String content) {
          SimpleMailMessage mailMessage = new SimpleMailMessage();
          mailMessage.setFrom(from);
          mailMessage.setTo(to);
          mailMessage.setSubject(subject);
          mailMessage.setText(content);
          try {
              mailSender.send(mailMessage);
              log.info("简单邮件：{} 发送成功", mailMessage);
          } catch (Exception e) {
              e.printStackTrace();
              throw new SmilcoolException("简单邮件发送失败");
          }
      }
  }
  