try{
Calendar cal = Calendar.getInstance();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
File f=new File(((new BufferedReader(new FileReader((new File("").getAbsoluteFile().getAbsolutePath()).replaceAll("\\\\", "/") + "/SET/disAttachmentspath.txt"))).readLine().trim()));
cal.setTimeInMillis(f.lastModified());
String mDateTime=formatter.format(cal.getTime());
MailSendHtml sendmail = new MailSendHtml("23.6.4.8","","");
sendmail.setSubject(((new BufferedReader(new FileReader((new File("").getAbsoluteFile().getAbsolutePath()).replaceAll("\\\\", "/")+"/SET/disSubject.txt"))).readLine().trim()) + " "+ time1);
sendmail.setSendDate(new Date());
String head = "<head>";
String style01 = "<!--.style1 {color: #FF0000}.style2 {color: #0000FF;font-weight: bold;}body {background-color: #CCCCFF;}-->";
String style02 = "<!--.style1 {color: #FF0000}.style2 {color: #0000FF;font-weight: bold;}body {background-color: #CCCCCC;}-->";
head = head + "<style type=\"text/css\">" + style01 + "</style>";
head = head + "</head>";
String htmlText11 = head + " <table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
htmlText11 = htmlText11 + "<tr>";
htmlText11 = htmlText11 + "<p class=\"style2\">"+ "Dear all," + "</p>" + "<p>" + "</p>" + "<td> "+ "附檔為:" + ((new BufferedReader(new FileReader((new File("").getAbsoluteFile().getAbsolutePath()).replaceAll("\\\\", "/")+ "/SET/disSubject.txt"))).readLine().trim()) + "。 使用," + "<p class=\"style1\">" + mDateTime +" 的標准數據" + "</p>" + "</td> " ;
htmlText11 = htmlText11 + "</tr >";
htmlText11 = htmlText11 + "</table>" + "<p>" + "</p>";
sendmail.setMailContent(htmlText11);
//***問題在這兒***下面是發送附件為Test.html********//
sendmail.setAttachments("Test.html");
String [] toAddress = ((new BufferedReader(new FileReader((new File("").getAbsoluteFile().getAbsolutePath()).replaceAll("\\\\", "/")+"/SET/disReceiveEmailAddress.txt"))).readLine().trim()).split(",");
sendmail.setMailTo(toAddress,"to");
sendmail.sendMail();
} catch (Exception e1) {
e1.printStackTrace();上面是以html的方式發送郵件,並且附件為Test.html。
問題:
現在我想把附件Test.html的內容直接在郵件正文中顯示出來(就是說收件者一打開郵件,郵件正文就顯示出Test.html的內容,收件者不必再去看附件)。
請問可做到嗎?謝謝
Calendar cal = Calendar.getInstance();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
File f=new File(((new BufferedReader(new FileReader((new File("").getAbsoluteFile().getAbsolutePath()).replaceAll("\\\\", "/") + "/SET/disAttachmentspath.txt"))).readLine().trim()));
cal.setTimeInMillis(f.lastModified());
String mDateTime=formatter.format(cal.getTime());
MailSendHtml sendmail = new MailSendHtml("23.6.4.8","","");
sendmail.setSubject(((new BufferedReader(new FileReader((new File("").getAbsoluteFile().getAbsolutePath()).replaceAll("\\\\", "/")+"/SET/disSubject.txt"))).readLine().trim()) + " "+ time1);
sendmail.setSendDate(new Date());
String head = "<head>";
String style01 = "<!--.style1 {color: #FF0000}.style2 {color: #0000FF;font-weight: bold;}body {background-color: #CCCCFF;}-->";
String style02 = "<!--.style1 {color: #FF0000}.style2 {color: #0000FF;font-weight: bold;}body {background-color: #CCCCCC;}-->";
head = head + "<style type=\"text/css\">" + style01 + "</style>";
head = head + "</head>";
String htmlText11 = head + " <table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
htmlText11 = htmlText11 + "<tr>";
htmlText11 = htmlText11 + "<p class=\"style2\">"+ "Dear all," + "</p>" + "<p>" + "</p>" + "<td> "+ "附檔為:" + ((new BufferedReader(new FileReader((new File("").getAbsoluteFile().getAbsolutePath()).replaceAll("\\\\", "/")+ "/SET/disSubject.txt"))).readLine().trim()) + "。 使用," + "<p class=\"style1\">" + mDateTime +" 的標准數據" + "</p>" + "</td> " ;
htmlText11 = htmlText11 + "</tr >";
htmlText11 = htmlText11 + "</table>" + "<p>" + "</p>";
sendmail.setMailContent(htmlText11);
//***問題在這兒***下面是發送附件為Test.html********//
sendmail.setAttachments("Test.html");
String [] toAddress = ((new BufferedReader(new FileReader((new File("").getAbsoluteFile().getAbsolutePath()).replaceAll("\\\\", "/")+"/SET/disReceiveEmailAddress.txt"))).readLine().trim()).split(",");
sendmail.setMailTo(toAddress,"to");
sendmail.sendMail();
} catch (Exception e1) {
e1.printStackTrace();上面是以html的方式發送郵件,並且附件為Test.html。
問題:
現在我想把附件Test.html的內容直接在郵件正文中顯示出來(就是說收件者一打開郵件,郵件正文就顯示出Test.html的內容,收件者不必再去看附件)。
請問可做到嗎?謝謝
帮你顶一下!