@Service
public class SendingMailWhenDoOrder {
@Value("${img.imageMail.path}")
private String imagePath;
@Value("${spring.mail.username}")
private String emailFrom;
@Autowired
private JavaMailSender javaMailSender;
public void sendingMessage(
List<String> list) throws MessagingException {
MimeMessage mimeMessage = javaMailSender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true);
String toAddress = "mail@mail.com";
helper.setTo(toAddress);
String subject = "Oder on our Site is:";
helper.setSubject(subject);
for (String properties : list) {
String[] split = properties.split("_");
String name = split[0];
Integer quantity = Integer.valueOf(split[1]);
String photo = split[2];
helper.setSentDate(new Date());
helper.setText(name);
FileSystemResource file = new FileSystemResource(new File(imagePath));
helper.addAttachment(photo, file);
}
helper.setFrom(emailFrom);
javaMailSender.send(mimeMessage);
}
}
在列表中我反复思考:
- [qwertyuio_5_whisky / alfaSml.jpg,Tomintoul_3_whisky / Tomintoul.jpg,Alfa Suf_5_whisky / OldPulteney.jpg]