| | |
| | | package com.doumee.service.common; |
| | | |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.context.annotation.AnnotationConfigApplicationContext; |
| | |
| | | import java.util.Map; |
| | | |
| | | @Service |
| | | @Slf4j |
| | | public class EmailService { |
| | | @Autowired |
| | | private JavaMailSender javaMailSender;//注入JavaMailSender |
| | |
| | | } |
| | | } |
| | | public boolean sendEmailWithImages(String toEmail, String title, Map<String,String> contentForm, List<String> imgList) { |
| | | log.error("邮件开始发送============"+toEmail); |
| | | try { |
| | | AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); |
| | | context.refresh(); |
| | |
| | | content += "<div style='display:block;'> "; |
| | | for (String f : imgList){ |
| | | // 设置附件 |
| | | content += "<img style='width:200px;margin:5px' src='"+f+"'/>"; |
| | | content += "<a href='"+f+"' target='blank'><img style='width:200px;margin:5px' src='"+f+"'/></a>"; |
| | | } |
| | | } |
| | | content += "</div></body><html>"; |
| | | helper.setText(content,true); |
| | | javaMailSender.send(message); |
| | | System.out.println("邮件发送成功!"); |
| | | return true; |
| | | content += "</div></body><html>"; |
| | | helper.setText(content,true); |
| | | log.error("邮件内容============"+content); |
| | | javaMailSender.send(message); |
| | | log.error("邮件发生成功============"); |
| | | return true; |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | log.error("邮件发生成功============"+e.getMessage()); |
| | | return false; |
| | | } |
| | | } |