天天看點

javaMail發送電子郵件

浣跨敤Javamail鍙戦€侀偖浠訛紝蹇呴渶鐨刯ar鍖咃紙璇蜂笅杞絡avamail鐨勬簮鏂囦歡锛夛細

  • mailapi.jar銆傚畾涔変簡鏀跺彂閭歡鎵€浣跨敤鍒扮殑鎺ュ彛API锛?/li>
  • smtp.jar銆傚寘鍚簡鍙戦€侀偖浠朵嬌鐢ㄥ埌鐨勭被锛?/li>
  • pop3.jar銆傚寘鍚簡鏀堕偖浠朵嬌鐢ㄥ埌鐨勭被锛?/li>

鎴戜滑閫氬父鍙戦€侀偖浠朵嬌鐢ㄧ殑鍗忚鏄痵mtp鍗忚锛屾帴鍙楅偖浠朵嬌鐢ㄧ殑鍗忚鏄痯op3鍗忚銆傛垨鑰咃紝鎴戜滑鐩存帴灏唌ail.jar鍔犲叆鍒闆伐绋嬶紝杩欎釜jar鍖呴噷杈瑰寘鍚簡java鏀跺彂閭歡鎵€鏈夌殑鎺ュ彛鍜岀被銆?

甯哥敤鐨勭被锛?

聽聽聽聽 javax.mail.Session;聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 聽 -------->淇濆瓨杩炴帴鏈嶅姟鍣ㄦ墍闇€瑕佺殑淇℃伅锛?

聽聽 聽 javax.mail.Message;聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽-------->閭歡浣擄紝淇濆瓨閭歡鐨勫唴瀹癸紱

聽聽聽聽 javax.mail.Transport;聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 -------->鍙戦€侀偖浠剁殑杞戒綋

聽聽聽聽 javax.mail.internet.InternetAddress;聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 -------->閭歡鐨勫湴鍧€淇℃伅

涓嬭竟锛屾垜鍏堝垪鍑轟嬌鐢↗ava鍙戦€侀偖浠剁殑鏈€绠€鍗曠殑涓€涓皬娴嬭瘯绀轟緥锛?

[java]聽 view plain copy

  1. import聽java.util.Properties;聽聽
  2. 聽聽
  3. import聽javax.mail.Address;聽聽
  4. import聽javax.mail.Message;聽聽
  5. import聽javax.mail.MessagingException;聽聽
  6. import聽javax.mail.Session;聽聽
  7. import聽javax.mail.Transport;聽聽
  8. import聽javax.mail.internet.InternetAddress;聽聽
  9. import聽javax.mail.internet.MimeMessage;聽聽
  10. 聽聽
  11. 聽聽
  12. public聽class聽Demo1聽{聽聽
  13. 聽聽
  14. 聽聽聽聽聽聽
  15. 聽聽聽聽public聽static聽void聽main(String[]聽args)聽throws聽MessagingException聽{聽聽
  16. 聽聽聽聽聽聽聽聽聽聽
  17. 聽聽聽聽聽聽聽聽String聽sendUserName聽=聽"[email聽protected]";聽聽
  18. 聽聽聽聽聽聽聽聽String聽sendPassword聽=聽"pwd"; 聽瀵嗙爜杩欎釜鍦版柟闇€瑕佺暀鎰忥細涓嶆槸缃戦〉閭鐧誨綍瀵嗙爜锛岃€屾槸瀹㈡埛鐨勬巿鏉冨瘑鐮侊紝瑙佹湯灏劇ず渚嬪浘銆?
  19. 聽聽聽聽聽聽聽聽聽聽
  20. 聽聽聽聽聽聽聽聽Properties聽properties聽=聽new聽Properties();聽聽
  21. 聽聽聽聽聽聽聽聽properties.setProperty("mail.smtp.auth",聽"true");//鏈嶅姟鍣ㄩ渶瑕佽璇伮犅?
  22. 聽聽聽聽聽聽聽聽properties.setProperty("mail.transport.protocol",聽"smtp");//澹版槑鍙戦€侀偖浠朵嬌鐢ㄧ殑绔彛聽聽
  23. 聽聽聽聽聽聽聽聽聽聽
  24. 聽聽聽聽聽聽聽聽Session聽session聽=聽Session.getInstance(properties);聽聽
  25. 聽聽聽聽聽聽聽聽session.setDebug(true);//鍚屾剰鍦ㄥ綋鍓嶇嚎绋嬬殑鎺у埗鍙版墦鍗頒笌鏈嶅姟鍣ㄥ璇濅俊鎭犅?
  26. 聽聽聽聽聽聽聽聽聽聽
  27. 聽聽聽聽聽聽聽聽Message聽message聽=聽new聽MimeMessage(session);//鏋勫緩鍙戦€佺殑淇℃伅聽聽
  28. 聽聽聽聽聽聽聽聽message.setText("浣犲ソ锛屾垜鏄疌hampion.Wong锛?);//淇℃伅鍐呭聽聽
  29. 聽聽聽聽聽聽聽聽message.setFrom(new聽InternetAddress("[email聽protected]"));//鍙戜歡浜郝犅?
  30. 聽聽聽聽聽聽聽聽聽聽
  31. 聽聽聽聽聽聽聽聽Transport聽transport聽=聽session.getTransport();聽聽
  32. 聽聽聽聽聽聽聽聽transport.connect("smtp.126.com",聽25,聽sendUserName,聽sendPassword);//杩炴帴鍙戜歡浜轟嬌鐢ㄥ彂浠剁殑鏈嶅姟鍣犅?
  33. 聽聽聽聽聽聽聽聽transport.sendMessage(message,聽new聽Address[]{new聽InternetAddress("[email聽protected]")});//鎺ュ彈閭歡聽聽
  34. 聽聽聽聽聽聽聽聽transport.close();聽聽
  35. 聽聽聽聽}聽聽
  36. 聽聽
  37. }聽聽

涓€鑸殑锛屾垜浠嬌鐢ˋuthenticator鎶婄敤鎴峰悕鍜屽瘑鐮佸皝瑁呰搗鏉ワ紝涓嶉€忔槑锛佹墍浠ワ細

[java]聽 view plain copy

  1. import聽javax.mail.Authenticator;聽聽
  2. import聽javax.mail.Message;聽聽
  3. import聽javax.mail.MessagingException;聽聽
  4. import聽javax.mail.PasswordAuthentication;聽聽
  5. import聽javax.mail.Session;聽聽
  6. import聽javax.mail.Transport;聽聽
  7. import聽javax.mail.internet.AddressException;聽聽
  8. import聽javax.mail.internet.InternetAddress;聽聽
  9. import聽javax.mail.internet.MimeMessage;聽聽
  10. 聽聽
  11. import聽junit.framework.TestCase;聽聽
  12. 聽聽
  13. 聽聽
  14. public聽class聽Demo2聽extends聽TestCase聽{聽聽
  15. 聽聽
  16. 聽聽聽聽private聽static聽final聽String聽sendUserName聽=聽"[email聽protected]";//聽鍙戦€侀偖浠堕渶瑕佽繛鎺ョ殑鏈嶅姟鍣ㄧ殑鐢ㄦ埛鍚嵚犅?
  17. 聽聽
  18. 聽聽聽聽private聽static聽final聽String聽sendPassword聽=聽"pwd";//聽鍙戦€侀偖浠堕渶瑕佽繛鎺ョ殑鏈嶅姟鍣ㄧ殑瀵嗙爜聽聽
  19. 聽聽
  20. 聽聽聽聽private聽static聽final聽String聽sendProtocol聽=聽"smtp";//聽鍙戦€侀偖浠朵嬌鐢ㄧ殑绔彛聽聽
  21. 聽聽
  22. 聽聽聽聽private聽static聽final聽String聽sendHostAddress聽=聽"smtp.126.com";//聽鍙戦€侀偖浠朵嬌鐢ㄧ殑鏈嶅姟鍣ㄧ殑鍦闆潃聽聽
  23. 聽聽
  24. 聽聽聽聽public聽void聽test()聽throws聽AddressException,聽MessagingException聽{聽聽
  25. 聽聽
  26. 聽聽聽聽聽聽聽聽Properties聽properties聽=聽new聽Properties();聽聽
  27. 聽聽聽聽聽聽聽聽properties.setProperty("mail.smtp.auth",聽"true");//聽鏈嶅姟鍣ㄩ渶瑕佽璇伮犅?
  28. 聽聽聽聽聽聽聽聽properties.setProperty("mail.transport.protocol",聽sendProtocol);//聽澹版槑鍙戦€侀偖浠朵嬌鐢ㄧ殑绔彛聽聽
  29. 聽聽聽聽聽聽聽聽properties.setProperty("mail.host",聽sendHostAddress);//聽鍙戦€侀偖浠剁殑鏈嶅姟鍣ㄥ湴鍧€聽聽
  30. 聽聽
  31. 聽聽聽聽聽聽聽聽Session聽session聽=聽Session.getInstance(properties,聽new聽Authenticator()聽{聽聽
  32. 聽聽聽聽聽聽聽聽聽聽聽聽protected聽PasswordAuthentication聽getPasswordAuthentication()聽{聽聽
  33. 聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽return聽new聽PasswordAuthentication(sendUserName,聽sendPassword);聽聽
  34. 聽聽聽聽聽聽聽聽聽聽聽聽}聽聽
  35. 聽聽聽聽聽聽聽聽});聽聽
  36. 聽聽聽聽聽聽聽聽session.setDebug(true);//鍦ㄥ悗鍙版墦鍗闆彂閫侀偖浠剁殑瀹炴椂淇℃伅聽聽
  37. 聽聽
  38. 聽聽聽聽聽聽聽聽Message聽message聽=聽new聽MimeMessage(session);聽聽
  39. 聽聽聽聽聽聽聽聽message.setFrom(new聽InternetAddress("[email protected]"));聽聽
  40. 聽聽聽聽聽聽聽聽message.setSubject("Demo2JavaCode鍙戦€侀偖浠舵祴璇曪紝閲囩敤Authenticator");//聽璁劇疆涓婚聽聽
  41. 聽聽聽聽聽聽聽聽message.setRecipients(Message.RecipientType.TO,聽InternetAddress聽聽
  42. 聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽.parse("[email protected],[email protected]"));//聽鍙戦€伮犅?
  43. 聽聽聽聽聽聽聽聽message.setRecipients(Message.RecipientType.CC,聽InternetAddress聽聽
  44. 聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽.parse("[email protected]"));//聽鎶勯€伮犅?
  45. 聽聽聽聽聽聽聽聽message聽聽
  46. 聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽.setContent(聽聽
  47. 聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽"<span聽style="font-size:20px;聽color:#FFCCFF"聽mce_style="font-size:20px;聽color:#FFCCFF">濡傛灉鎮ㄧ湅鍒幫紝璇佹槑娴嬭瘯鎴愬姛浜嗭紒</span>",聽聽
  48. 聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽"text/html;charset=gbk");聽聽
  49. 聽聽
  50. 聽聽聽聽聽聽聽聽Transport.send(message);//鍙戦€侀偖浠堵犅?
  51. 聽聽聽聽}聽聽
  52. }聽聽

鎴戜滑鍙戦€佷竴涓瘮杈冨鏉傜殑閭歡锛屽寘鎷檮浠訛紝鍥炬枃锛?

[java]聽 view plain copy

  1. import聽java.io.FileNotFoundException;聽聽
  2. import聽java.io.FileOutputStream;聽聽
  3. import聽java.io.IOException;聽聽
  4. import聽java.io.OutputStream;聽聽
  5. import聽java.util.Properties;聽聽
  6. 聽聽
  7. import聽javax.activation.DataHandler;聽聽
  8. import聽javax.activation.DataSource;聽聽
  9. import聽javax.activation.FileDataSource;聽聽
  10. import聽javax.mail.Authenticator;聽聽
  11. import聽javax.mail.MessagingException;聽聽
  12. import聽javax.mail.PasswordAuthentication;聽聽
  13. import聽javax.mail.Session;聽聽
  14. import聽javax.mail.Transport;聽聽
  15. import聽javax.mail.Message.RecipientType;聽聽
  16. import聽javax.mail.internet.InternetAddress;聽聽
  17. import聽javax.mail.internet.MimeBodyPart;聽聽
  18. import聽javax.mail.internet.MimeMessage;聽聽
  19. import聽javax.mail.internet.MimeMultipart;聽聽
  20. import聽javax.mail.internet.MimeUtility;聽聽
  21. 聽聽
  22. 聽聽
  23. public聽class聽Demo3_test聽{聽聽
  24. 聽聽
  25. 聽聽聽聽public聽static聽void聽main(String[]聽args)聽throws聽Exception聽{聽聽
  26. 聽聽聽聽聽聽聽聽聽聽
  27. 聽聽聽聽聽聽聽聽Properties聽properties聽=聽new聽Properties();聽聽
  28. 聽聽聽聽聽聽聽聽properties.setProperty("mail.smtp.auth",聽"true");//聽鏈嶅姟鍣ㄩ渶瑕佽璇伮犅?
  29. 聽聽聽聽聽聽聽聽properties.setProperty("mail.transport.protocol",聽"smtp");//聽澹版槑鍙戦€侀偖浠朵嬌鐢ㄧ殑绔彛聽聽
  30. 聽聽聽聽聽聽聽聽properties.setProperty("mail.host",聽"smtp.126.com");//聽鍙戦€侀偖浠剁殑鏈嶅姟鍣ㄥ湴鍧€聽聽
  31. 聽聽聽聽聽聽聽聽聽聽
  32. 聽聽聽聽聽聽聽聽Session聽session聽=聽Session.getInstance(properties,聽new聽Authenticator()聽{聽聽
  33. 聽聽聽聽聽聽聽聽聽聽聽聽String聽sendUserName聽=聽"[email protected]";聽聽
  34. 聽聽聽聽聽聽聽聽聽聽聽聽String聽sendPassword聽=聽"pwd";聽聽
  35. 聽聽聽聽聽聽聽聽聽聽聽聽protected聽PasswordAuthentication聽getPasswordAuthentication()聽{聽聽
  36. 聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽return聽new聽PasswordAuthentication(sendUserName,聽聽
  37. 聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽sendPassword);聽聽
  38. 聽聽聽聽聽聽聽聽聽聽聽聽}聽聽
  39. 聽聽聽聽聽聽聽聽});聽聽
  40. 聽聽聽聽聽聽聽聽session.setDebug(true);聽聽
  41. 聽聽聽聽聽聽聽聽聽聽
  42. 聽聽聽聽聽聽聽聽MimeMessage聽msg聽=聽new聽MimeMessage(session);//聽澹版槑涓€涓偖浠朵綋聽聽
  43. 聽聽聽聽聽聽聽聽msg.setFrom(new聽InternetAddress("/""+MimeUtility.encodeText("Mr聽XP.Wang")+"/"<[email protected]>"));聽聽
  44. 聽聽聽聽聽聽聽聽msg.setSubject("杩欐槸鎴戠殑绗竴浠藉鏉傞偖浠?);//璁劇疆閭歡涓婚聽聽
  45. 聽聽聽聽聽聽聽聽msg.setRecipients(MimeMessage.RecipientType.TO,聽InternetAddress.parse(MimeUtility.encodeText("濮撳悕")+"<[email protected]>,"+MimeUtility.encodeText("涓夋瘺")+"<[email protected]>"));聽聽
  46. 聽聽
  47. 聽聽聽聽聽聽聽聽MimeMultipart聽msgMultipart聽=聽new聽MimeMultipart("mixed");//聽鏍囨槑閭歡鐨勭粍鍚堝叧绯夥紝娣峰悎鐨勫叧绯宦犅?
  48. 聽聽聽聽聽聽聽聽msg.setContent(msgMultipart);//聽璁劇疆閭歡浣撀犅?
  49. 聽聽聽聽聽聽聽聽聽聽
  50. 聽聽
  51. 聽聽聽聽聽聽聽聽MimeBodyPart聽attch1聽=聽new聽MimeBodyPart();//聽闄勪歡1聽聽
  52. 聽聽聽聽聽聽聽聽MimeBodyPart聽attch2聽=聽new聽MimeBodyPart();//聽闄勪歡2聽聽
  53. 聽聽聽聽聽聽聽聽MimeBodyPart聽content聽=聽new聽MimeBodyPart();//聽閭歡鐨勬鏂囷紝娣峰悎浣擄紙鍥劇墖+鏂囧瓧锛壜犅?
  54. 聽聽
  55. 聽聽聽聽聽聽聽聽//聽灏嗛檮浠跺拰姝f枃璁劇疆鍒拌繖涓偖浠朵綋涓犅?
  56. 聽聽聽聽聽聽聽聽msgMultipart.addBodyPart(attch1);聽聽
  57. 聽聽聽聽聽聽聽聽msgMultipart.addBodyPart(attch2);聽聽
  58. 聽聽聽聽聽聽聽聽msgMultipart.addBodyPart(content);聽聽
  59. 聽聽聽聽聽聽聽聽聽聽
  60. 聽聽
  61. 聽聽聽聽聽聽聽聽//聽璁劇疆绗竴涓檮浠堵犅?
  62. 聽聽聽聽聽聽聽聽DataSource聽ds1聽=聽new聽FileDataSource("F:/ACCP5.0/鏂囦歡/ssh閰嶇疆.txt");//聽鎸囧畾闄勪歡鐨勬暟鎹簮聽聽
  63. 聽聽聽聽聽聽聽聽DataHandler聽dh1聽=聽new聽DataHandler(ds1);//聽闄勪歡鐨勪俊鎭犅?
  64. 聽聽聽聽聽聽聽聽attch1.setDataHandler(dh1);//聽鎸囧畾闄勪歡聽聽
  65. 聽聽聽聽聽聽聽聽attch1.setFileName("ssh.txt");聽聽
  66. 聽聽
  67. 聽聽聽聽聽聽聽聽//聽璁劇疆绗簩涓檮浠堵犅?
  68. 聽聽聽聽聽聽聽聽DataSource聽ds2聽=聽new聽FileDataSource("resource/48.jpg");//聽鎸囧畾闄勪歡鐨勬暟鎹簮聽聽
  69. 聽聽聽聽聽聽聽聽DataHandler聽dh2聽=聽new聽DataHandler(ds2);//聽闄勪歡鐨勪俊鎭犅?
  70. 聽聽聽聽聽聽聽聽attch2.setDataHandler(dh2);//聽鎸囧畾闄勪歡聽聽
  71. 聽聽聽聽聽聽聽聽attch2.setFileName("48.jpg");聽聽
  72. 聽聽
  73. 聽聽聽聽聽聽聽聽//璁劇疆閭歡鐨勬鏂嚶犅?
  74. 聽聽聽聽聽聽聽聽MimeMultipart聽bodyMultipart聽=聽new聽MimeMultipart("related");//渚濊禆鍏崇郴聽聽
  75. 聽聽聽聽聽聽聽聽content.setContent(bodyMultipart);//鎸囧畾姝f枃聽聽
  76. 聽聽聽聽聽聽聽聽MimeBodyPart聽htmlPart聽=聽new聽MimeBodyPart();聽聽
  77. 聽聽聽聽聽聽聽聽MimeBodyPart聽gifPart聽=聽new聽MimeBodyPart();聽聽
  78. 聽聽聽聽聽聽聽聽bodyMultipart.addBodyPart(htmlPart);聽聽
  79. 聽聽聽聽聽聽聽聽bodyMultipart.addBodyPart(gifPart);聽聽
  80. 聽聽聽聽聽聽聽聽聽聽
  81. 聽聽聽聽聽聽聽聽聽聽
  82. 聽聽聽聽聽聽聽聽DataSource聽gifds聽=聽new聽FileDataSource("resource/48.jpg");//姝f枃鐨勫浘鐗嚶犅?
  83. 聽聽聽聽聽聽聽聽DataHandler聽gifdh聽=聽new聽DataHandler(gifds);聽聽
  84. 聽聽聽聽聽聽聽聽gifPart.setHeader("Content-Location",聽"http://mimg.126.net/logo/126logo.gif");聽聽
  85. 聽聽聽聽聽聽聽聽gifPart.setDataHandler(gifdh);//璁劇疆姝f枃鐨勫浘鐗嚶犅?
  86. 聽聽聽聽聽聽聽聽聽聽
  87. 聽聽聽聽聽聽聽聽htmlPart.setContent("鎴戝彧鏄潵鎵撻叡娌圭殑锛岃繖鏄垜鐨勫艦璞$収锛?lt;img聽src="/"聽mce_src="/""http://mimg.126.net/logo/126logo.gif/">",聽"text/html;charset=gbk");//璁劇疆姝f枃鏂囧瓧聽聽
  88. 聽聽聽聽聽聽聽聽聽聽
  89. 聽聽聽聽聽聽聽聽msg.saveChanges();//淇濆瓨閭歡聽聽
  90. 聽聽聽聽聽聽聽聽聽聽
  91. 聽聽聽聽聽聽聽聽//灏嗛偖浠朵繚瀛樻垚鏂囦歡聽聽
  92. 聽聽聽聽聽聽聽聽OutputStream聽ops聽=聽new聽FileOutputStream("C:/Users/Administrator/Desktop/test.eml");聽聽
  93. 聽聽聽聽聽聽聽聽msg.writeTo(ops);聽聽
  94. 聽聽聽聽聽聽聽聽ops.close();聽聽
  95. 聽聽聽聽聽聽聽聽聽聽
  96. 聽聽聽聽聽聽聽聽Transport.send(msg); 聽
  97. 聽聽聽聽}聽聽
  98. 聽聽
  99. } 聽
    javaMail發送電子郵件
javaMail發送電子郵件
javaMail發送電子郵件

JAVA聽MAIL聽閰嶇疆椤矽缁嗚鏄?

Name 								Type 												Description									          
mail.smtp.user 聽聽      
String      
Default user name for SMTP.      
mail.smtp.host      
String      
The SMTP server to connect to.      
mail.smtp.port      
int      
The SMTP server port to connect to, if the connect() method doesn't explicitly specify one. Defaults to 25.      
mail.smtp.connectiontimeout      
int      
Socket connection timeout value in milliseconds. Default is infinite timeout.      
mail.smtp.timeout      
int      
Socket I/O timeout value in milliseconds. Default is infinite timeout.      
mail.smtp.from      
String      
Email address to use for SMTP MAIL command. This sets the envelope return address. Defaults to msg.getFrom() or InternetAddress.getLocalAddress(). NOTE: mail.smtp.user was previously used for this.      
mail.smtp.localhost      
String      
Local host name used in the SMTP HELO or EHLO command. Defaults to聽         InetAddress.getLocalHost().getHostName()                聽. Should not normally need to be set if your JDK and your name service are configured properly.      
mail.smtp.localaddress      
String      
Local address (host name) to bind to when creating the SMTP socket. Defaults to the address picked by the Socket class. Should not normally need to be set, but useful with multi-homed hosts where it's important to pick a particular local address to bind to.      
mail.smtp.localport      
int      
Local port number to bind to when creating the SMTP socket. Defaults to the port number picked by the Socket class.      
mail.smtp.ehlo      
boolean      
If false, do not attempt to sign on with the EHLO command. Defaults to true. Normally failure of the EHLO command will fallback to the HELO command; this property exists only for servers that don't fail EHLO properly or don't implement EHLO properly.      
mail.smtp.auth      
boolean      
If true, attempt to authenticate the user using the AUTH command. Defaults to false.      
mail.smtp.auth.mechanisms      
String      
If set, lists the authentication mechanisms to consider, and the order in which to consider them. Only mechanisms supported by the server and supported by the current implementation will be used. The default is聽         "LOGIN PLAIN DIGEST-MD5"                聽, which includes all the authentication mechanisms supported by the current implementation.      
mail.smtp.submitter      
String      
The submitter to use in the AUTH tag in the MAIL FROM command. Typically used by a mail relay to pass along information about the original submitter of the message. See also the聽         setSubmitter                聽method of聽         SMTPMessage                聽. Mail clients typically do not use this.      
mail.smtp.dsn.notify      
String      
The NOTIFY option to the RCPT command. Either NEVER, or some combination of SUCCESS, FAILURE, and DELAY (separated by commas).      
mail.smtp.dsn.ret      
String      
The RET option to the MAIL command. Either FULL or HDRS.      
mail.smtp.allow8bitmime      
boolean      
If set to true, and the server supports the 8BITMIME extension, text parts of messages that use the "quoted-printable" or "base64" encodings are converted to use "8bit" encoding if they follow the RFC2045 rules for 8bit text.      
mail.smtp.sendpartial      
boolean      
If set to true, and a message has some valid and some invalid addresses, send the message anyway, reporting the partial failure with a SendFailedException. If set to false (the default), the message is not sent to any of the recipients if there is an invalid recipient address.      
mail.smtp.sasl.realm      
String      
The realm to use with DIGEST-MD5 authentication.      
mail.smtp.quitwait      
boolean      
If set to false, the QUIT command is sent and the connection is immediately closed. If set to true (the default), causes the transport to wait for the response to the QUIT command.      
mail.smtp.reportsuccess      
boolean      
If set to true, causes the transport to include an         SMTPAddressSucceededException                聽for each address that is successful. Note also that this will cause a         SendFailedException                聽to be thrown from the聽         sendMessage                method of聽         SMTPTransport                聽even if all addresses were correct and the message was sent successfully.      
mail.smtp.socketFactory      
SocketFactory      
If set to a class that implements the         javax.net.SocketFactory                聽interface, this class will be used to create SMTP sockets. Note that this is an instance of a class, not a name, and must be set using the聽         put                聽method, not the聽         setProperty                聽method.      
mail.smtp.socketFactory.class      
String      
If set, specifies the name of a class that implements the         javax.net.SocketFactory                聽interface. This class will be used to create SMTP sockets.      
mail.smtp.socketFactory.fallback      
boolean      
If set to true, failure to create a socket using the specified socket factory class will cause the socket to be created using the聽         java.net.Socket                聽class. Defaults to true.      
mail.smtp.socketFactory.port      
int      
Specifies the port to connect to when using the specified socket factory. If not set, the default port will be used.      
mail.smtp.ssl.enable      
boolean      
If set to true, use SSL to connect and use the SSL port by default. Defaults to false for the "smtp" protocol and true for the "smtps" protocol.      
mail.smtp.ssl.checkserveridentity      
boolean      
If set to true, check the server identity as specified by聽RFC 2595聽. These additional checks based on the content of the server's certificate are intended to prevent man-in-the-middle attacks. Defaults to false.      
mail.smtp.ssl.socketFactory      
SSLSocketFactory      
If set to a class that extends the         javax.net.ssl.SSLSocketFactory                聽class, this class will be used to create SMTP SSL sockets. Note that this is an instance of a class, not a name, and must be set using the         put                聽method, not the聽         setProperty                聽method.      
mail.smtp.ssl.socketFactory.class      
String      
If set, specifies the name of a class that extends the         javax.net.ssl.SSLSocketFactory                聽class. This class will be used to create SMTP SSL sockets.      
mail.smtp.ssl.socketFactory.port      
int      
Specifies the port to connect to when using the specified socket factory. If not set, the default port will be used.      
mail.smtp.ssl.protocols      
string      
Specifies the SSL protocols that will be enabled for SSL connections. The property value is a whitespace separated list of tokens acceptable to the         javax.net.ssl.SSLSocket.setEnabledProtocols                聽method.      
mail.smtp.ssl.ciphersuites      
string      
Specifies the SSL cipher suites that will be enabled for SSL connections. The property value is a whitespace separated list of tokens acceptable to the         javax.net.ssl.SSLSocket.setEnabledCipherSuites                method.      
mail.smtp.mailextension      
String      
Extension string to append to the MAIL command. The extension string can be used to specify standard SMTP service extensions as well as vendor-specific extensions. Typically the application should use the聽         SMTPTransport                method聽         supportsExtension                聽to verify that the server supports the desired service extension. See聽RFC 1869聽and other RFCs that define specific extensions.      
mail.smtp.starttls.enable      
boolean      
If true, enables the use of the聽         STARTTLS                聽command (if supported by the server) to switch the connection to a TLS-protected connection before issuing any login commands. Note that an appropriate trust store must configured so that the client will trust the server's certificate. Defaults to false.      
mail.smtp.starttls.required      
boolean      
If true, requires the use of the聽         STARTTLS                聽command. If the server doesn't support the STARTTLS command, or the command fails, the connect method will fail. Defaults to false.      
mail.smtp.userset      
boolean      
If set to true, use the RSET command instead of the NOOP command in the聽         isConnected                聽method. In some cases sendmail will respond slowly after many NOOP commands; use of RSET avoids this sendmail issue. Defaults to false.