• 概述

  邮件功能模块在大多数网站中,都是必不可少的功能模块。无论是用户注册还是重置密码,邮件都是比较常用的一个方式。本文主要介绍 JavaMail 的简单使用,方便大家快速开发,供大家参考。完整的 demo,可以从我的 GitHub 上下载:https://github.com/RexFang/java_email

  • pom.xml 配置文件
  1. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  2. <modelVersion>4.0.0</modelVersion>
  3. <groupId>java_email</groupId>
  4. <artifactId>java_email</artifactId>
  5. <version>0.0.1-SNAPSHOT</version>
  6. <build>
  7. <sourceDirectory>src</sourceDirectory>
  8. <plugins>
  9. <plugin>
  10. <artifactId>maven-compiler-plugin</artifactId>
  11. <version>3.1</version>
  12. <configuration>
  13. <source>1.7</source>
  14. <target>1.7</target>
  15. </configuration>
  16. </plugin>
  17. </plugins>
  18. </build>
  19. <dependencies>
  20. <dependency>
  21. <groupId>log4j</groupId>
  22. <artifactId>log4j</artifactId>
  23. <version>1.2.17</version>
  24. </dependency>
  25.  
  26. <dependency>
  27. <groupId>javax.mail</groupId>
  28. <artifactId>mail</artifactId>
  29. <version>1.4.7</version>
  30. </dependency>
  31.  
  32. <dependency>
  33. <groupId>junit</groupId>
  34. <artifactId>junit</artifactId>
  35. <version>4.12</version>
  36. </dependency>
  37.  
  38. <dependency>
  39. <groupId>xerces</groupId>
  40. <artifactId>xercesImpl</artifactId>
  41. <version>2.11.0</version>
  42. </dependency>
  43.  
  44. <dependency>
  45. <groupId>org.apache.commons</groupId>
  46. <artifactId>commons-lang3</artifactId>
  47. <version>3.4</version>
  48. </dependency>
  49. </dependencies>
  50. </project>
  • log4j.properties  Maven 配置文件
  1. ### 设置###
  2. log4j.rootLogger = debug,stdout,D,E
  3.  
  4. ### 输出信息到控制抬 ###
  5. log4j.appender.stdout = org.apache.log4j.ConsoleAppender
  6. log4j.appender.stdout.Target = System.out
  7. log4j.appender.stdout.layout = org.apache.log4j.PatternLayout
  8. log4j.appender.stdout.layout.ConversionPattern = [%-5p] %d{yyyy-MM-dd HH:mm:ss,SSS} method:%l%n%m%n
  9.  
  10. ### 输出DEBUG 级别以上的日志到=D://work/logs/log.log ###
  11. log4j.appender.D = org.apache.log4j.DailyRollingFileAppender
  12. log4j.appender.D.File = D://work/logs/log.log
  13. log4j.appender.D.Append = true
  14. log4j.appender.D.Threshold = DEBUG
  15. log4j.appender.D.layout = org.apache.log4j.PatternLayout
  16. log4j.appender.D.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n
  17.  
  18. ### 输出ERROR 级别以上的日志到=D://work/logs/error.log ###
  19. log4j.appender.E = org.apache.log4j.DailyRollingFileAppender
  20. log4j.appender.E.File =D://work/logs/error.log
  21. log4j.appender.E.Append = true
  22. log4j.appender.E.Threshold = ERROR
  23. log4j.appender.E.layout = org.apache.log4j.PatternLayout
  24. log4j.appender.E.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n
  • email.properties 邮件配置文件
  1. #是否开启debug调试
  2. mail.debug=true
  3. #发送服务器是否需要身份验证
  4. mail.smtp.auth=true
  5. #邮件发送端口
  6. mail.smtp.port=25
  7. #邮件服务器主机名
  8. #mail.host=smtp.126.com
  9. #mail.host=smtp.yeah.net
  10. mail.host=smtp.sohu.com
  11. #发送邮件协议名称
  12. mail.transport.protocol=smtp
  13. #发送邮件用户名
  14. mail.user=java_email_test
  15. #mail.user=rex_test
  16. #发送邮件邮箱密码
  17. #mail.pass=java123
  18. mail.pass=test123
  19. #发送邮件发件人
  20. #mail.from=java_email_test@126.com
  21. mail.from=java_email_test@sohu.com
  22. #mail.from=rex_test@yeah.net
  • 邮件账户信息单例 EmailAuthenticator
  1. package email;
  2.  
  3. import javax.mail.Authenticator;
  4. import javax.mail.PasswordAuthentication;
  5.  
  6. /**
  7. * user:Rex
  8. * date:2016年12月25日 上午1:13:37
  9. * TODO 发送邮件账户信息
  10. */
  11. public class EmailAuthenticator extends Authenticator {
  12. //创建单例邮件账户信息
  13. private static EmailAuthenticator emailAuthenticator = new EmailAuthenticator();
  14.  
  15. /**
  16. * user:Rex
  17. * date:2016年12月25日 上午3:28:10
  18. * TODO 私有化构造函数
  19. */
  20. private EmailAuthenticator() {
  21.  
  22. }
  23.  
  24. /*
  25. * user: Rex
  26. * date: 2016年12月25日 上午3:33:36
  27. * @return 返回密码校验对象
  28. * TODO 重写获取密码校验对象方法
  29. * @see javax.mail.Authenticator#getPasswordAuthentication()
  30. */
  31. @Override
  32. protected PasswordAuthentication getPasswordAuthentication() {
  33. return new PasswordAuthentication(EmailConfig.getUser(), EmailConfig.getPass());
  34. }
  35.  
  36. public static EmailAuthenticator createEmailAuthenticator() {
  37. return emailAuthenticator;
  38. }
  39. }
  • 邮件配置信息工具类 EmailConfig
  1. package email;
  2.  
  3. import java.io.FileNotFoundException;
  4. import java.io.IOException;
  5. import java.io.InputStream;
  6. import java.util.Properties;
  7.  
  8. import org.apache.log4j.Logger;
  9.  
  10. /**
  11. * user:Rex
  12. * date:2016年12月25日 上午1:46:43
  13. * TODO 发送邮件配置信息
  14. */
  15. public class EmailConfig {
  16. private static final Logger logger = Logger.getLogger(EmailConfig.class);
  17.  
  18. public static final String MAIL_DEBUT = "mail.debug";
  19. public static final String MAIL_SMTP_AUTH = "mail.smtp.auth";
  20. public static final String MAIL_SMTP_PORT = "mail.smtp.port";
  21. public static final String MAIL_HOST = "mail.host";
  22. public static final String MAIL_TRANSPORT_PROTOCOL = "mail.transport.protocol";
  23. public static final String MAIL_USER = "mail.user";
  24. public static final String MAIL_PASS = "mail.pass";
  25. public static final String MAIL_FROM = "mail.from";
  26.  
  27. //是否开启debug调试
  28. private static String debug;
  29.  
  30. //发送服务器是否需要身份验证
  31. private static String auth;
  32.  
  33. //发送邮件端口
  34. private static String port;
  35.  
  36. //邮件服务器主机名
  37. private static String host;
  38.  
  39. //发送邮件协议名称
  40. private static String protocol;
  41.  
  42. //发送邮件用户名
  43. private static String user;
  44.  
  45. //发送邮件邮箱密码
  46. private static String pass;
  47.  
  48. //发送邮件发件人
  49. private static String from;
  50.  
  51. //创建单例Session配置信息
  52. private static Properties sessionProperties = new Properties();
  53.  
  54. //创建单例邮箱配置信息
  55. private static EmailConfig emailConfig = new EmailConfig();
  56.  
  57. /**
  58. * user:Rex
  59. * date:2016年12月25日 上午2:03:48
  60. * @throws IOException
  61. * TODO 从配置文件中读取邮箱配置信息(比较好的方式是让用户在管理后台配置,从数据库读取邮箱配置信息)
  62. */
  63. private EmailConfig() {
  64. try {
  65. InputStream fis = EmailConfig.class.getResourceAsStream("/email.properties");
  66. Properties prop = new Properties();
  67. prop.load(fis);
  68. EmailConfig.auth = prop.getProperty(EmailConfig.MAIL_SMTP_AUTH, "false").trim();
  69. EmailConfig.port = prop.getProperty(EmailConfig.MAIL_SMTP_PORT, "495").trim();
  70. EmailConfig.debug = prop.getProperty(EmailConfig.MAIL_DEBUT, "false").trim();
  71. EmailConfig.from = prop.getProperty(EmailConfig.MAIL_FROM, "java_email_test@126.com").trim();
  72. EmailConfig.host = prop.getProperty(EmailConfig.MAIL_HOST, "smtp.126.com").trim();
  73. EmailConfig.pass = prop.getProperty(EmailConfig.MAIL_PASS, "test123").trim();
  74. EmailConfig.protocol = prop.getProperty(EmailConfig.MAIL_TRANSPORT_PROTOCOL, "smtp").trim();
  75. EmailConfig.user = prop.getProperty(EmailConfig.MAIL_USER, "java_email_test").trim();
  76. fis.close();
  77.  
  78. sessionProperties.setProperty(EmailConfig.MAIL_SMTP_AUTH, EmailConfig.auth);
  79. sessionProperties.setProperty(EmailConfig.MAIL_SMTP_PORT, EmailConfig.port);
  80. sessionProperties.setProperty(EmailConfig.MAIL_DEBUT, EmailConfig.debug);
  81. sessionProperties.setProperty(EmailConfig.MAIL_HOST, EmailConfig.host);
  82. sessionProperties.setProperty(EmailConfig.MAIL_TRANSPORT_PROTOCOL, EmailConfig.protocol);
  83. } catch (FileNotFoundException e) {
  84. logger.error("邮箱配置信息初始化异常", e);
  85. } catch (IOException e) {
  86. logger.error("邮箱配置信息初始化异常", e);
  87. } catch (Exception e){
  88. logger.error("邮箱配置信息初始化异常", e);
  89. }
  90. }
  91.  
  92. public static String getDebug() {
  93. return debug;
  94. }
  95.  
  96. public static String getAuth() {
  97. return auth;
  98. }
  99.  
  100. public static String getHost() {
  101. return host;
  102. }
  103.  
  104. public static String getProtocol() {
  105. return protocol;
  106. }
  107.  
  108. public static String getUser() {
  109. return user;
  110. }
  111.  
  112. public static String getPass() {
  113. return pass;
  114. }
  115.  
  116. public static String getFrom() {
  117. return from;
  118. }
  119.  
  120. public static EmailConfig createEmailConfig() {
  121. return emailConfig;
  122. }
  123.  
  124. public static Properties getSessionProperties() {
  125. return sessionProperties;
  126. }
  127.  
  128. public static String getPort() {
  129. return port;
  130. }
  131. }
  • 邮件发送工具类 EmailUtil
  1. package email;
  2.  
  3. import java.io.File;
  4. import java.io.UnsupportedEncodingException;
  5. import java.util.Date;
  6. import java.util.List;
  7.  
  8. import javax.activation.DataHandler;
  9. import javax.activation.FileDataSource;
  10. import javax.mail.Message;
  11. import javax.mail.Message.RecipientType;
  12. import javax.mail.MessagingException;
  13. import javax.mail.Multipart;
  14. import javax.mail.Session;
  15. import javax.mail.Transport;
  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. import org.apache.commons.lang3.StringUtils;
  23.  
  24. /**
  25. * user:Rex
  26. * date:2016年12月25日 上午3:56:49
  27. * TODO 邮件工具类
  28. */
  29. public class EmailUtil {
  30. /**
  31. * user: Rex
  32. * date: 2016年12月25日 上午4:29:18
  33. * @param subject 邮件标题
  34. * @param content 邮件内容
  35. * @param to 收件人(多个收件人用英文逗号“,”隔开)
  36. * @throws Exception
  37. */
  38. public static void sendEmail(String subject, String content, String to) throws Exception{
  39. Message msg = createMessage(subject, content, to, null);
  40. // 连接邮件服务器、发送邮件
  41. Transport.send(msg);
  42. }
  43.  
  44. /**
  45. * user: Rex
  46. * date: 2016年12月25日 上午4:17:11
  47. * @param subject 邮件标题
  48. * @param content 邮件内容
  49. * @param to 收件人(多个收件人用英文逗号“,”隔开)
  50. * @param type
  51. * @param otherRecipient 抄送人或暗送人(多个抄送人或暗送人用英文逗号“,”隔开)
  52. * @return 邮箱对象
  53. * @throws Exception
  54. */
  55. public static void sendEmail(String subject, String content, String to, RecipientType type, String otherRecipient) throws Exception{
  56. Message msg = createMessage(subject, content, to, type, otherRecipient, null);
  57. // 连接邮件服务器、发送邮件
  58. Transport.send(msg);
  59. }
  60.  
  61. /**
  62. * user: Rex
  63. * date: 2016年12月25日 上午4:17:11
  64. * @param subject 邮件标题
  65. * @param content 邮件内容
  66. * @param to 收件人(多个收件人用英文逗号“,”隔开)
  67. * @param cc 抄送人(多个抄送人用英文逗号“,”隔开)
  68. * @param bcc 暗送人(多个暗送人用英文逗号“,”隔开)
  69. * @return 邮箱对象
  70. * @throws Exception
  71. */
  72. public static void sendEmail(String subject, String content, String to, String cc, String bcc) throws Exception{
  73. Message msg = createMessage(subject, content, to, cc, bcc, null);
  74. // 连接邮件服务器、发送邮件
  75. Transport.send(msg);
  76. }
  77.  
  78. /**
  79. * user: Rex
  80. * date: 2016年12月25日 上午7:04:02
  81. * @param subject 邮件标题
  82. * @param content 邮件内容
  83. * @param to 收件人(多个收件人用英文逗号“,”隔开)
  84. * @param fileList 附件
  85. * @throws Exception
  86. */
  87. public static void sendEmail(String subject, String content, String to, List<File> fileList) throws Exception{
  88. Message msg = createMessage(subject, content, to, fileList);
  89. // 连接邮件服务器、发送邮件
  90. Transport.send(msg);
  91. }
  92.  
  93. /**
  94. * user: Rex
  95. * date: 2016年12月25日 上午7:04:02
  96. * @param subject 邮件标题
  97. * @param content 邮件内容
  98. * @param to 收件人(多个收件人用英文逗号“,”隔开)
  99. * @param type
  100. * @param otherRecipient 抄送人或暗送人(多个抄送人或暗送人用英文逗号“,”隔开)
  101. * @param fileList 附件
  102. * @throws Exception
  103. */
  104. public static void sendEmail(String subject, String content, String to, RecipientType type, String otherRecipient, List<File> fileList) throws Exception{
  105. Message msg = createMessage(subject, content, to, type, otherRecipient, fileList);
  106. // 连接邮件服务器、发送邮件
  107. Transport.send(msg);
  108. }
  109.  
  110. /**
  111. * user: Rex
  112. * date: 2016年12月25日 上午7:04:02
  113. * @param subject 邮件标题
  114. * @param content 邮件内容
  115. * @param to 收件人(多个收件人用英文逗号“,”隔开)
  116. * @param cc 抄送人(多个抄送人用英文逗号“,”隔开)
  117. * @param bcc 暗送人(多个暗送人用英文逗号“,”隔开)
  118. * @param fileList 附件
  119. * @throws Exception
  120. */
  121. public static void sendEmail(String subject, String content, String to, String cc, String bcc, List<File> fileList) throws Exception{
  122. Message msg = createMessage(subject, content, to, cc, bcc, fileList);
  123. // 连接邮件服务器、发送邮件
  124. Transport.send(msg);
  125. }
  126.  
  127. /**
  128. * user: Rex
  129. * date: 2016年12月25日 上午7:02:07
  130. * @param subject 邮件标题
  131. * @param content 邮件内容
  132. * @param to 收件人(多个收件人用英文逗号“,”隔开)
  133. * @param cc 抄送人(多个抄送人用英文逗号“,”隔开)
  134. * @param bcc 暗送人(多个暗送人用英文逗号“,”隔开)
  135. * @param fileList 附件
  136. * @return 邮箱对象
  137. * @throws Exception
  138. */
  139. private static Message createMessage(String subject, String content, String to, String cc, String bcc, List<File> fileList) throws Exception{
  140. Message msg = createMessage(subject, content, to, RecipientType.CC, cc, fileList);
  141. msg.setRecipients(RecipientType.BCC, InternetAddress.parse(bcc));
  142. msg.setSentDate(new Date()); //设置信件头的发送日期
  143.  
  144. return msg;
  145. }
  146.  
  147. /**
  148. * user: Rex
  149. * date: 2016年12月25日 上午7:02:07
  150. * @param subject 邮件标题
  151. * @param content 邮件内容
  152. * @param to 收件人(多个收件人用英文逗号“,”隔开)
  153. * @param otherRecipient 抄送人或暗送人(多个抄送人或暗送人用英文逗号“,”隔开)
  154. * @param fileList 附件
  155. * @return 邮箱对象
  156. * @throws Exception
  157. */
  158. private static Message createMessage(String subject, String content, String to, RecipientType type, String otherRecipient, List<File> fileList) throws Exception{
  159. Message msg = createMessage(subject, content, to, fileList);
  160. msg.setRecipients(type, InternetAddress.parse(otherRecipient));
  161.  
  162. return msg;
  163. }
  164.  
  165. /**
  166. * user: Rex
  167. * date: 2016年12月25日 上午7:02:07
  168. * @param subject 邮件标题
  169. * @param content 邮件内容
  170. * @param to 收件人(多个收件人用英文逗号“,”隔开)
  171. * @param fileList 附件
  172. * @return 邮箱对象
  173. * @throws Exception
  174. */
  175. private static Message createMessage(String subject, String content, String to, List<File> fileList) throws Exception{
  176. checkEmail(subject, content, fileList);
  177. //邮件内容
  178. Multipart mp = createMultipart(content, fileList);
  179. Message msg = new MimeMessage(createSession());
  180. msg.setFrom(new InternetAddress(EmailConfig.getFrom()));
  181. msg.setSubject(subject);
  182. msg.setRecipients(RecipientType.TO, InternetAddress.parse(to));
  183. msg.setContent(mp); //Multipart加入到信件
  184. msg.setSentDate(new Date()); //设置信件头的发送日期
  185.  
  186. return msg;
  187. }
  188.  
  189. /**
  190. * user: Rex
  191. * date: 2016年12月25日 上午9:01:12
  192. * @param content 邮件正文内容
  193. * @param fileList 附件
  194. * @return 邮件内容对象
  195. * @throws MessagingException
  196. * @throws UnsupportedEncodingException
  197. * Multipart
  198. * TODO 创建邮件正文
  199. */
  200. private static Multipart createMultipart(String content, List<File> fileList) throws MessagingException, UnsupportedEncodingException{
  201. //邮件内容
  202. Multipart mp = new MimeMultipart();
  203. MimeBodyPart mbp = new MimeBodyPart();
  204. mbp.setContent(content, "text/html;charset=gb2312");
  205. mp.addBodyPart(mbp);
  206.  
  207. if(fileList!=null && fileList.size()>0){
  208. //附件
  209. FileDataSource fds;
  210. for(File file : fileList){
  211. mbp=new MimeBodyPart();
  212. fds = new FileDataSource(file);//得到数据源
  213. mbp.setDataHandler(new DataHandler(fds)); //得到附件本身并至入BodyPart
  214. mbp.setFileName(MimeUtility.encodeText(file.getName())); //得到文件名同样至入BodyPart
  215. mp.addBodyPart(mbp);
  216. }
  217. }
  218.  
  219. return mp;
  220. }
  221.  
  222. /**
  223. * user: Rex
  224. * date: 2016年12月25日 上午9:48:18
  225. * @param title 邮件标题
  226. * @param content 邮件正文
  227. * @param fileList 邮件附件
  228. * void
  229. * TODO 校验邮件内容合法性
  230. * @throws Exception
  231. */
  232. private static void checkEmail(String subject, String content, List<File> fileList) throws Exception{
  233. if(StringUtils.isEmpty(subject)){
  234. throw new Exception("邮件标题不能为空");
  235. }
  236.  
  237. if(StringUtils.isEmpty(content) && (fileList==null || fileList.size()==0)){
  238. throw new Exception("邮件内容不能为空");
  239. }
  240. }
  241.  
  242. /**
  243. * user: Rex
  244. * date: 2016年12月25日 上午4:01:47
  245. * @return
  246. * Session
  247. * TODO 创建邮箱上下文
  248. */
  249. private static Session createSession(){
  250. return Session.getDefaultInstance(EmailConfig.getSessionProperties(), EmailAuthenticator.createEmailAuthenticator());
  251. }
  252. }
  • 邮件发送测试类 EmailUtilTest
  1. package test;
  2.  
  3. import java.io.File;
  4. import java.util.ArrayList;
  5. import java.util.List;
  6.  
  7. import org.junit.Before;
  8. import org.junit.Test;
  9.  
  10. import email.EmailUtil;
  11.  
  12. public class EmailUtilTest {
  13.  
  14. @Before
  15. public void setUp() throws Exception {
  16.  
  17. }
  18.  
  19. @Test
  20. public void testSendEmail() {
  21. try {
  22. String title = "利比亚客机遭劫持6大疑问:劫机者怎样通过安检的(1)";
  23. String content = "当地时间23日,俄罗斯总统普京在莫斯科国际贸易中心举行年度记者会。记者会持续了近4个小时,普京一共回答了来自俄罗斯各个地区及全世界记者的47个问题。自2001年起,普京都会在每年12月中下旬举行年度记者会,这是他的第12次记者会。";
  24. List<File> fileList = new ArrayList<File>();
  25. fileList.add(new File("C:/Users/Rex/Desktop/log4j.properties"));
  26. EmailUtil.sendEmail(title, content, "rex_test@yeah.net", "123@qq.com", "456@qq.com", fileList);
  27. } catch (Exception e) {
  28. e.printStackTrace();
  29. }
  30. }
  31. }

  完整的 demo ,请查看我的 GitHub https://github.com/RexFang/java_email

欢迎转载,转载必须标明出处

JavaMail 的简单使用的更多相关文章

  1. 使用javaMail发送简单邮件

    参考网页:http://blog.csdn.net/xietansheng/article/details/51673073package com.bfd.ftp.utils; import java ...

  2. (一)JavaMail发送简单邮件

    1,导入依赖 <dependency> <groupId>com.sun.mail</groupId> <artifactId>jakarta.mail ...

  3. JavaMail发送简单邮件

    非常简单的发送邮件实现,网上有很多啦,但还是自己写写记录下吧. package cn.jmail.test; import java.util.Properties; import javax.mai ...

  4. JavaMail的简单使用(自测可以发邮件)

    在很多项目中我们都会遇到发送邮件的功能,发送邮件其实还是很实用的,正好今天做项目需要实现,现在来简单的整理一下发送邮件的实现. 建立邮件与服务器之间的会话 Properties props = new ...

  5. JavaMail(一):利用JavaMail发送简单邮件

    JavaMail,提供给开发者处理电子邮件相关的编程接口.它是Sun发布的用来处理email的API.它可以方便地执行一些常用的邮件传输.但它并没有包含在JDK中,要使用JavaMail首先要下载ja ...

  6. 使用javaMail实现简单邮件发送

    一.首先你要用来发送邮件的qq邮箱需要开通pop3/smtp服务,这个可以百度一下就知道了 二.导入所需要的jar包,我使用的是maven添加依赖 <dependency> <gro ...

  7. Android JavaMail

    一.简介 JavaMail API提供了一种与平台无关和协议独立的框架来构建邮件和消息应用程序. JavaMail API提供了一组抽象类定义构成一个邮件系统的对象.它是阅读,撰写和发送电子信息的可选 ...

  8. 邮件实现详解(四)------JavaMail 发送(带图片和附件)和接收邮件

    好了,进入这个系列教程最主要的步骤了,前面邮件的理论知识我们都了解了,那么这篇博客我们将用代码完成邮件的发送.这在实际项目中应用的非常广泛,比如注册需要发送邮件进行账号激活,再比如OA项目中利用邮件进 ...

  9. javaMail 邮件发送和接收示例,支持正文图片、html、附件(转)

    转自:https://blog.csdn.net/star_fly4/article/details/52037587 一.RFC882文档简单说明 RFC882文档规定了如何编写一封简单的邮件(纯文 ...

随机推荐

  1. 类关系/self/特殊成员

    1.依赖关系 在方法中引入另一个类的对象 2.关联关系.聚合关系.组合关系 #废话少说 直接上代码===>选课系统 # coding:utf-8 class Student(object): d ...

  2. ubuntu开机自启动服务管理

    安装sysv-rc-conf sudo apt-get install sysv-rc-conf 执行下面,查看服务情况 sudo sysv-rc-conf 启动服务有以下两种方式 update-rc ...

  3. Python条件与循环

    1.条件语句: 形式: if 判断语句 : 执行语句1elif 判断语句2: 执行语句2elif 判断语句3: 执行语句3#...else: 执行语句4    占位符 pass 2.循环语句 1.wh ...

  4. apache htaccess 一个 例子

    <Files ~ "^.(htaccess|htpasswd)$"> deny from all </Files> DirectoryIndex index ...

  5. 最长上升子序列问题(O(n^2)算法)

    [题目描述] 给定N个数,求这N个数的最长上升子序列的长度. [样例输入] 7 2 5 3 4 1 7 6 [样例输出] 4 什么是最长上升子序列? 就是给你一个序列,请你在其中求出一段不断严格上升的 ...

  6. C#工具类之字典扩展类

    using System; using System.Collections; using System.Collections.Generic; using System.Linq; using S ...

  7. vue学习—组件的定义注册

    组件的定义注册 效果: 方法一: <div id="box"> <v-header></v-header> <hr /> <b ...

  8. dedecms 的采集

    http://www.360doc.com/content/14/0521/09/13870710_379547377.shtml http://www.360doc.com/content/14/0 ...

  9. Go语言基础练习题系列2

    1.练习1 生成一个随机数,让一个用户去猜这个数是多少? 代码示例如下: package main import ( "fmt" "math/rand" //m ...

  10. centos7安装与卸载软件

    安装 yum install 服务名 查看服务名 rpm -qa |grep -i aerospike 或者 yum list installed | grep aerospike 卸载 yum re ...