Tchart画的2个jpg图,发送到outlook正文,第一张显示不出来,

yanji2007 2013-06-21 11:44:31
java里面Tchart画的2个jpg图,发送到outlook正文,第一张显示不出来,显示是红叉,不知道咋回事,但是第二章正常显示,如下图,哪位大神能指个方向吗?谢谢!
public boolean send(String[] to, String[] cc, String[] bcc, String subject, String content, String mailType, String[] attachments, String[] attachmentpic) throws MessagingException

{

Properties props = new Properties();

props.put("mail.smtp.host", host);

props.put("mail.smtp.auth", auth);

Session session = Session.getInstance(props);

MimeMessage message = new MimeMessage(session);

InternetAddress from = new InternetAddress(username);

message.setFrom(from);



// Set Mail To

InternetAddress[] Toaddress = new InternetAddress[to.length];

for (int i = 0; i < to.length; i++)

{

Toaddress[i] = new InternetAddress(to[i]);

}

message.setRecipients(Message.RecipientType.TO, Toaddress);



// Set Mail Cc

if (cc != null)

{

InternetAddress[] Ccaddress = new InternetAddress[cc.length];

for (int i = 0; i < cc.length; i++)

{

Ccaddress[i] = new InternetAddress(cc[i]);

}

message.setRecipients(Message.RecipientType.CC, Ccaddress);

}



// Set Mail Bcc

if (bcc != null)

{

InternetAddress[] Bccaddress = new InternetAddress[bcc.length];

for (int i = 0; i < bcc.length; i++)

{

Bccaddress[i] = new InternetAddress(bcc[i]);

}

message.setRecipients(Message.RecipientType.BCC, Bccaddress);

}



// Set Mail Subject

message.setSubject(subject);



// Set Mail Sent Date

message.setSentDate(new Date());



// Text Content Only

if (attachments == null && attachmentpic == null)

{

// Set Mail Content

if (mailType != null && "text".equals(mailType.trim()))

{

// mail_type is "text" -> for send message

message.setText(content);

}

else

{

BodyPart mdp = new MimeBodyPart();

mdp.setContent(content, "text/html;charset=utf-8");

Multipart mm = new MimeMultipart();

mm.addBodyPart(mdp);

message.setContent(mm);

}

}

// With Attachment or Picture Content

else

{

// Set format mixed

MimeMultipart msgMultipart= new MimeMultipart("mixed");

// Create content with pictures

MimeBodyPart contentPart = createContent(content,attachmentpic);

// Set Attachments

if (attachments != null)

{

for(int i=0;i<attachments.length;i++)

msgMultipart.addBodyPart(createAttachment(attachments[i]));

}

msgMultipart.addBodyPart(contentPart);

message.setContent(msgMultipart);

}

message.saveChanges();

Transport transport = session.getTransport("smtp");

transport.connect(host, (null == domainUser) ? username : domainUser, password);

transport.sendMessage(message, message.getAllRecipients());

transport.close();

return true;

}

//create attachment according to file path

public MimeBodyPart createAttachment(String fileName) throws MessagingException{

MimeBodyPart attachment = new MimeBodyPart();

FileDataSource fds = new FileDataSource(fileName);

attachment.setDataHandler(new DataHandler(fds));

attachment.setFileName(fds.getName());

return attachment;

}

//create content with picture attachment

public MimeBodyPart createContent(String body, String[] fileName) throws MessagingException{

MimeBodyPart contentBody = new MimeBodyPart();

MimeMultipart contentMulti = new MimeMultipart("related");

//content text

MimeBodyPart htmlPart = new MimeBodyPart();

htmlPart.setContent(body, "text/html;charset=utf-8");

contentMulti.addBodyPart(htmlPart);



//content picture

if(fileName != null)

{

MimeBodyPart jpgBody = new MimeBodyPart();

for(int i=0; i<fileName.length;i++){
FileDataSource fds = new FileDataSource(fileName[i]);
jpgBody.setDataHandler(new DataHandler(fds));
//jpgBody.setContentID(Integer.toString(i));
jpgBody.setContentID("<"+"IMG"+new Integer(i).toString()+">");
contentMulti.addBodyPart(jpgBody);
}
}
contentBody.setContent(contentMulti);
return contentBody;
}

}



mafan麻烦看看这部分代码哪有问题啊,2张图片第一张显示不出来
...全文
158 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
yanji2007 2013-06-26
  • 打赏
  • 举报
回复
meiyuo没有人吗?java板块一个人牛人都没有,版主麻烦帮忙置顶啊。
yanji2007 2013-06-24
  • 打赏
  • 举报
回复
ding顶起来
yanji2007 2013-06-22
  • 打赏
  • 举报
回复
youren有人吗??

81,091

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧