发送列表<string>使用javaMailSender

时间:2016-08-12 07:31:01

标签: java spring

@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]
  •   
  • 我想通过电子邮件发送名称产品:qwertyuio,Tomintoul,Alfa SUF。但我只收到了最后一款产品 - Alfa Suf。

0 个答案:

没有答案