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();


评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值