Java 发送邮件,
分享于 点击 11565 次 点评:62
Java 发送邮件,
使用Apache的Commons-email.jar 包进行邮件发送/接受的小测试。主要要注意以下几点:
1. 包要齐全,一共有四个包,他们分别为:javamail.jar, mail.jar, commons-email.jar, activation.jar
2. 在添加附件的时候,要将资源文件添加到Project中来
3. 如果要让附件显示您想要的格式,在别名中要写上后缀,如"逐梦令.mp3"
attachment.setPath("./source/4 in love - 命中注定.mp3"); // attachment.setName("destiny.mp3"); // if the suffix is added, then it can be displayed on what you want to see. attachment.setName("destiny.rmvb"); // if the suffix is added, then it can be displayed on what you want to see. attachment.setDescription(EmailAttachment.ATTACHMENT); email.attach(attachment);
File file = new File("./source/000.jpg"); StringBuffer emailContent = new StringBuffer(); emailContent.append("<html><body>"); emailContent.append("<img src=cid:").append(email.embed(file,"阿兰")).append("/>"); emailContent.append("<font color=\"red\">你好啊</font>"); emailContent.append("</body></html>"); email.setHtmlMsg(emailContent.toString()); email.setTextMsg("测试"); email.send();
相关文章
- 暂无相关文章
用户点评