Sending an email with an attachment using javamail API

后端 未结 5 1009
遥遥无期
遥遥无期 2020-12-06 12:10

I am trying to send an email with an attachment file in Java.

When I send the email without an attachment I receive the email, but when I add the attachment I don\'t

5条回答
  •  难免孤独
    2020-12-06 12:25

    You can try something like:

    File f = new File(file);
    MimeBodyPart attachmentPart = new MimeBodyPart();
    attachmentPart.attachFile(f);
    multipart.addBodyPart(attachmentPart);
    

    See more details on: Send email via SMTP with attachment, plain/text, and text/hml

提交回复
热议问题