使用Java尝试通过Outlook发送时,文件格式没有得到明确定义

我正在使用此代码通过使用Java的Outlook发送Excel文件。

excel是通过另一个Java代码生成的。它已经被正确地生成了。

当我使用这个代码,然后收件人收到未定义的格式附件。请帮助

try { msg.setFrom(); java.util.Date date=new java.util.Date(); fromAddress = new InternetAddress(from); msg.setFrom(fromAddress); //msg.addRecipient(Message.RecipientType.CC, to); msg.setSubject("For Testing Purpose "+date); //msg.setSentDate(new Date()); msg.setText("Attachment"); /* * ************************Test for * attachment************************* */ String fileAttachment = "D://testing.xlsx"; // create the message part MimeBodyPart messageBodyPart = new MimeBodyPart(); MimeBodyPart attachmentBodyPart = new MimeBodyPart(); String bodytext = "Hi,<br>"; bodytext = bodytext +"<br>"; bodytext = bodytext + "Please find Attachnment for last week Reviewr's "+date + "<br>"+"</Font><br><br><br>Thanks<br>Gulshan Raj"; messageBodyPart.setContent(bodytext , "text/html"); // Part two is attachment DataSource source = new FileDataSource(fileAttachment); attachmentBodyPart.setDataHandler(new DataHandler(source)); attachmentBodyPart.setFileName("Reviewers Data"); // Put parts in message Multipart multipart = new MimeMultipart(); multipart.addBodyPart(messageBodyPart); multipart.addBodyPart(attachmentBodyPart); msg.setContent(multipart); /* ******************************************************************** */ Transport.send(msg); System.out.println("2^^^^^^^fileAttachment "+fileNm); System.out.println("2^^^^^^^bodytext "+bodytext); } catch (MessagingException mex) { System.out.println("2^^^^^^^^^^^^^^^^^^^send failed, exception: "+ mex); }