package com.jkcredit.invoice.component;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.stereotype.Component;

import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;

@Component
@Slf4j
/**
 * @Description 发送邮箱
 * @Author mashengyi
 * @Date 2022/2/8 18:07
 * @Param
 * @Return
 * @Exception
 *
 */
public class SendMailService {

    @Value("${spring.mail.username}")
    String user;
    @Autowired
    private JavaMailSenderImpl javaMailSender;

    public void sendMail(String email, String contents, String company) throws MessagingException {
        MimeMessage message = javaMailSender.createMimeMessage();
        MimeMessageHelper helper = new MimeMessageHelper(message);
        helper.setFrom(user);
        String[] emailStr = email.split("#");
        helper.setTo(emailStr);
        helper.setSubject(company + "备案提交");
        helper.setText(contents, true);
        log.info("before send emil");
        javaMailSender.send(message);
        log.info("send emil");
    }
}
