日韩天天综合网_野战两个奶头被亲到高潮_亚洲日韩欧美精品综合_av女人天堂污污污_视频一区**字幕无弹窗_国产亚洲欧美小视频_国内性爱精品在线免费视频_国产一级电影在线播放_日韩欧美内地福利_亚洲一二三不卡片区

用Java發(fā)送圖文并茂的HTML郵件_.Net教程

編輯Tag賺U幣
教程Tag:暫無Tag,歡迎添加,賺取U幣!

推薦:用在JavaScript的RequestHelper
碰到一個小小的需求,就是要根據(jù)傳入的錨(也就是url中#后面的東西啦)來顯示不同的內(nèi)容,記得以前寫了的,不知道被我丟到哪去了,又要重新寫一個,順便把功能整理加強了一些,加入了取QueryString

  1. package com.syj;
  2. import java.io.ByteArrayOutputStream;
  3. import java.io.FileInputStream;
  4. import java.io.IOException;
  5. import java.util.Arrays;
  6. import java.util.Date;
  7. import java.util.Properties;
  8. import javax.activation.DataHandler;
  9. import javax.activation.FileDataSource;
  10. import javax.mail.Authenticator;
  11. import javax.mail.Message;
  12. import javax.mail.PasswordAuthentication;
  13. import javax.mail.Session;
  14. import javax.mail.Transport;
  15. import javax.mail.internet.InternetAddress;
  16. import javax.mail.internet.MimeMessage;
  17. import javax.mail.BodyPart;
  18. import javax.mail.Multipart;
  19. import javax.mail.internet.MimeBodyPart;
  20. import javax.mail.internet.MimeMultipart;
  21. import com.sun.istack.internal.ByteArrayDataSource;
  22. /**
  23. * <P>
  24. * Title:用java發(fā)送郵件的例子
  25. * </P>
  26. *
  27. * <P>
  28. * Description:發(fā)送圖片附件并在html中使用該圖片
  29. * </P>
  30. *
  31. * <P>
  32. * Copyright: Copyright (c) 2007
  33. * </P>
  34. *
  35. * @author 孫鈺佳
  36. * @main [email protected]
  37. * @date Jun 10, 2008 12:35:26 AM
  38. */
  39. public class SendMail {
  40. private static String username = "xxxx";
  41. private static String password = "xxxx";
  42. private static String smtpServer = "smtp.163.com";
  43. private static String fromMailAddress = "[email protected]";
  44. private static String toMailAddress = "[email protected]";
  45. public static void main(String[] args) throws Exception {
  46. Properties props = new Properties();
  47. props.put("mail.smtp.auth", "true");
  48. props.put("mail.smtp.host", smtpServer);
  49. // 獲得郵件會話對象
  50. Session session = Session.getDefaultInstance(props,
  51. new SmtpAuthenticator(username, password));
  52. /** *************************************************** */
  53. // 創(chuàng)建MIME郵件對象
  54. MimeMessage mimeMessage = new MimeMessage(session);
  55. mimeMessage.setFrom(new InternetAddress(fromMailAddress));// 發(fā)件人
  56. mimeMessage.setRecipient(Message.RecipientType.TO, new InternetAddress(
  57. toMailAddress));// 收件人
  58. mimeMessage.setSubject("主題");
  59. mimeMessage.setSentDate(new Date());// 發(fā)送日期
  60. Multipart mp = new MimeMultipart("related");// related意味著可以發(fā)送html格式的郵件
  61. /** *************************************************** */
  62. BodyPart bodyPart = new MimeBodyPart();// 正文
  63. bodyPart.setDataHandler(new DataHandler("測<img src="cid:IMG1" />試",
  64. "text/html;charset=GBK"));// 網(wǎng)頁格式
  65. /** *************************************************** */
  66. BodyPart attachBodyPart = new MimeBodyPart();// 普通附件
  67. FileDataSource fds = new FileDataSource("c:/boot.ini");
  68. attachBodyPart.setDataHandler(new DataHandler(fds));
  69. attachBodyPart.setFileName("=?GBK?B?"
  70. new sun.misc.BASE64Encoder().encode(fds.getName().getBytes())
  71. "?=");// 解決附件名中文亂碼
  72. mp.addBodyPart(attachBodyPart);
  73. /** *************************************************** */
  74. MimeBodyPart imgBodyPart = new MimeBodyPart(); // 附件圖標
  75. byte[] bytes = readFile("C:/button.gif");
  76. ByteArrayDataSource fileds = new ByteArrayDataSource(bytes,
  77. "application/octet-stream");
  78. imgBodyPart.setDataHandler(new DataHandler(fileds));
  79. imgBodyPart.setFileName("button.gif");
  80. imgBodyPart.setHeader("Content-ID", "<IMG1></IMG1>");// 在html中使用該圖片方法src="cid:IMG1"
  81. mp.addBodyPart(imgBodyPart);
  82. /** *************************************************** */
  83. mp.addBodyPart(bodyPart);
  84. mimeMessage.setContent(mp);// 設(shè)置郵件內(nèi)容對象
  85. Transport.send(mimeMessage);// 發(fā)送郵件
  86. }
  87. /**
  88. * 讀取文件
  89. *
  90. * @param file
  91. * 文件路徑
  92. * @return 返回二進制數(shù)組
  93. */
  94. public static byte[] readFile(String file) {
  95. FileInputStream fis = null;
  96. ByteArrayOutputStream bos = null;
  97. try {
  98. fis = new FileInputStream(file);
  99. bos = new ByteArrayOutputStream();
  100. int bytesRead;
  101. byte buffer[] = new byte[1024 * 1024];
  102. while ((bytesRead = fis.read(buffer)) != -1) {
  103. bos.write(buffer, 0, bytesRead);
  104. Arrays.fill(buffer, (byte) 0);
  105. }
  106. } catch (IOException e1) {
  107. e1.printStackTrace();
  108. } finally {
  109. try {
  110. if (bos != null)
  111. bos.close();
  112. } catch (IOException e) {
  113. e.printStackTrace();
  114. }
  115. }
  116. return bos.toByteArray();
  117. }
  118. }
  119. /**
  120. * Smtp認證
  121. */
  122. class SmtpAuthenticator extends Authenticator {
  123. String username = null;
  124. String password = null;
  125. // SMTP身份驗證
  126. public SmtpAuthenticator(String username, String password) {
  127. this.username = username;
  128. this.password = password;
  129. }
  130. public PasswordAuthentication getPasswordAuthentication() {
  131. return new PasswordAuthentication(this.username, this.password);
  132. }
  133. }

分享:ASP.NET2.0中控件的簡單異步回調(diào)
雖然已經(jīng)有了ASP.NET AJAX了,最近學(xué)習(xí)ASP.NET控件的時候,逐步理解了原始的控件異步回調(diào)(代碼取自《ASP.NET 2.0 高級編程》): 首先,在Render事件中添加好一個事件

來源:模板無憂//所屬分類:.Net教程/更新時間:2008-08-22
相關(guān).Net教程