计算机二级:使用javamail发送html格式邮件计算机二级考试
文章作者 100test 发表时间 2009:05:10 17:20:57
来源 100Test.Com百考试题网
2009年下半年全国计算机等级考试你准备好了没?考计算机等级考试的朋友,2009年下半年全国计算机等级考试时间是2009年9月19日至23日。更多优质资料尽在百考试题论坛 百考试题在线题库
实例代码如下:
package test.
/*****************************************************
*
*
* @since May 6, 2009
*
* 该测试例子演示了使用javamail发送html格式邮件,
*
* 分别以发送带附件和不带附件两种形式演示
*
* 同时实现了向多人发邮件
*****************************************************/
import java.util.Date.
import java.util.Properties.
import javax.activation.DataHandler.
import javax.activation.DataSource.
import javax.activation.FileDataSource.
import javax.mail.BodyPart.
import javax.mail.Message.
import javax.mail.MessagingException.
import javax.mail.Multipart.
import javax.mail.Session.
import javax.mail.Transport.
import javax.mail.internet.InternetAddress.
import javax.mail.internet.MimeBodyPart.
import javax.mail.internet.MimeMessage.
import javax.mail.internet.MimeMultipart.
public class SandMail{
@SuppressWarnings("static-access")
public void SendMail2(String title, String attachment){
// 获得属性,并生成Session对象
Properties props = new Properties().
Session sendsession.
Transport transport.
MimeMessage message = null.
BodyPart messageBodyPart = new MimeBodyPart().
Multipart multipart = new MimeMultipart().
String from = "[email protected]".
String to[]={"[email protected]"}.
String cc[] = {"[email protected]"}.
String bcc[] = {"[email protected]"}.
String content = "测试格式化内容测试