Java Mail, sending multiple attachments not working

后端 未结 3 1422
陌清茗
陌清茗 2021-01-01 19:02

I looked at many entries on the internet without having luck.

Here is my code:

import java.io.IOException;
import java.util.Properties;

import javax         


        
3条回答
  •  时光取名叫无心
    2021-01-01 19:51

    Multipart multipart = new MimeMultipart("mixed");
    for (String str : attachment_PathList) {
        MimeBodyPart messageBodyPart = new MimeBodyPart();
        DataSource source = new FileDataSource(str);
        messageBodyPart.setDataHandler(new DataHandler(source));
        messageBodyPart.setFileName(source.getName());
        multipart.addBodyPart(messageBodyPart);
    }
    msg.setContent(multipart);
    Transport.send(msg);
    

提交回复
热议问题