依赖的jar包

<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>javax.mail</artifactId>
<version>1.5.6</version>
</dependency>

邮件参数实体

import java.util.List;
import java.util.Properties; import com.sun.mail.util.MailSSLSocketFactory; /**
* 邮件发送配置参数信息
* @ClassName: MailSenderInfo
* @Description: TODO
* @author OnlyMate
* @Date 2018年5月8日 下午6:27:35
*
*/
public class MailSenderInfo {
// 发送邮件的服务器的IP
private String mailServerHost;
//发送邮件的服务器端口,该处暂时默认25
private String mailServerPort = "25";
// 邮件发送者的地址
private String fromAddress;
// 邮件接收者的地址
private String toAddress;
//邮件接收者的地址集合
private String[] toBatchAddress;
// 登陆邮件发送服务器的用户名
private String userName;
//登陆邮件发送服务器的密码
private String password;
// 是否需要身份验证 [默认false不认证]
private boolean validate = false;
// 邮件主题
private String subject;
// 邮件主题
private String[] subjects;
// 邮件的文本内容
private String content;
// 邮件的文本内容
private String[] contents;
// 邮件附件的文件名
private String[] attachFileNames;
// 邮件附件的文件名 针对一邮件带多个附件关系
private List<String[]> attachFileList; /**
* 获得邮件会话属性
*/
public Properties getProperties() {
Properties p = new Properties();
try {
p.put("mail.smtp.host", this.mailServerHost);
p.put("mail.smtp.port", this.mailServerPort);
p.put("mail.smtp.auth", validate ? "true" : "false");
p.setProperty("mail.transport.protocol", "smtp");
if("smtp.qq.com".equals(this.mailServerHost)) {
MailSSLSocketFactory sf = new MailSSLSocketFactory();
sf.setTrustAllHosts(true);
p.put("mail.smtp.ssl.enable", "true");
p.put("mail.smtp.ssl.socketFactory", sf);
}
}catch (Exception e) {
e.printStackTrace();
}
return p;
}
/**
* 发送邮件的服务器的IP 如:smtp.163.com
*/
public String getMailServerHost() {
return mailServerHost;
}
/**
* 发送邮件的服务器的IP 如:smtp.163.com
*/
public void setMailServerHost(String mailServerHost) {
this.mailServerHost = mailServerHost;
}
/**
* 发送邮件的服务器端口,如:网易邮箱默认25
*/
public String getMailServerPort() {
return mailServerPort;
}
/**
* 发送邮件的服务器端口,如:网易邮箱默认25
*/
public void setMailServerPort(String mailServerPort) {
this.mailServerPort = mailServerPort;
}
/**
* 是否需要身份验证 [默认false不认证]
*/
public boolean isValidate() {
return validate;
}
/**
* 是否需要身份验证 [默认false不认证]
*/
public void setValidate(boolean validate) {
this.validate = validate;
}
/**
* 邮件附件的文件名
*/
public String[] getAttachFileNames() {
return attachFileNames;
}
/**
* 邮件附件的文件名
*/
public void setAttachFileNames(String[] fileNames) {
this.attachFileNames = fileNames;
}
/**
* 邮件发送者的邮箱地址
*/
public String getFromAddress() {
return fromAddress;
}
/**
* 邮件发送者的邮箱地址
*/
public void setFromAddress(String fromAddress) {
this.fromAddress = fromAddress;
}
/**
* 邮件发送者的邮箱密码
*/
public String getPassword() {
return password;
}
/**
* 邮件发送者的邮箱密码
*/
public void setPassword(String password) {
this.password = password;
}
/**
* 邮件接收者的地址
*/
public String getToAddress() {
return toAddress;
}
/**
* 邮件接收者的地址
*/
public void setToAddress(String toAddress) {
this.toAddress = toAddress;
}
/**
* 邮件接收者的地址集合
* @return
*/
public String[] getToBatchAddress() {
return toBatchAddress;
}
/**
* 邮件接收者的地址集合
* @param toBatchAddress
*/
public void setToBatchAddress(String[] toBatchAddress) {
this.toBatchAddress = toBatchAddress;
}
/**
* 登陆邮件发送服务器的用户名
*/
public String getUserName() {
return userName;
}
/**
* 登陆邮件发送服务器的用户名
*/
public void setUserName(String userName) {
this.userName = userName;
}
/**
* 邮件主题
*/
public String getSubject() {
return subject;
}
/**
* 邮件主题
*/
public void setSubject(String subject) {
this.subject = subject;
}
/**
* 邮件主题
*/
public String[] getSubjects() {
return subjects;
}
/**
* 邮件主题
*/
public void setSubjects(String[] subjects) {
this.subjects = subjects;
}
/**
* 邮件的文本内容
*/
public String getContent() {
return content;
}
/**
* 邮件的文本内容
*/
public void setContent(String textContent) {
this.content = textContent;
}
/**
* 邮件的文本内容
*/
public String[] getContents() {
return contents;
}
/**
* 邮件的文本内容
*/
public void setContents(String[] contents) {
this.contents = contents;
}
/**
* 针对一邮件多附件
*/
public List<String[]> getAttachFileList() {
return attachFileList;
}
/**
* 针对一邮件多附件
*/
public void setAttachFileList(List<String[]> attachFileList) {
this.attachFileList = attachFileList;
} }

邮件身份认证

import javax.mail.Authenticator;
import javax.mail.PasswordAuthentication; /**
* 邮箱参数
* @ClassName: MailAuthenticator
* @Description: TODO
* @author OnlyMate
* @Date 2018年5月8日 下午6:22:59
*
*/
public class MailAuthenticator extends Authenticator{
String userName=null;
String password=null; public MailAuthenticator(){
}
public MailAuthenticator(String username, String password) {
this.userName = username;
this.password = password;
}
protected PasswordAuthentication getPasswordAuthentication(){
return new PasswordAuthentication(userName, password);
}
}

邮件发送器

import java.io.UnsupportedEncodingException;
import java.util.Date;
import java.util.Properties; import javax.activation.DataHandler;
import javax.activation.FileDataSource;
import javax.mail.Address;
import javax.mail.BodyPart;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Multipart;
import javax.mail.NoSuchProviderException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
import javax.mail.internet.MimeUtility; /**
* 邮件发送器
* @ClassName: SimpleMailSender
* @Description: TODO
* @author OnlyMate
* @Date 2018年5月8日 下午6:23:20
*
*/
public class SimpleMailSender { /**
* 以文本格式发送邮件
*
* @param mailInfo
* 待发送的邮件的信息
*/
public boolean sendTextMail(MailSenderInfo mailInfo) {
// 判断是否需要身份认证
MailAuthenticator authenticator = null;
Properties pro = mailInfo.getProperties();
if (mailInfo.isValidate()) {
// 如果需要身份认证,则创建一个密码验证器
authenticator = new MailAuthenticator(mailInfo.getUserName(),
mailInfo.getPassword());
}
// 根据邮件会话属性和密码验证器构造一个发送邮件的session
Session sendMailSession = Session
.getDefaultInstance(pro, authenticator);
try {
// 根据session创建一个邮件消息
Message mailMessage = new MimeMessage(sendMailSession);
// 创建邮件发送者地址
Address from = new InternetAddress(mailInfo.getFromAddress());
// 设置邮件消息的发送者
mailMessage.setFrom(from);
// 创建邮件的接收者地址,并设置到邮件消息中
if (mailInfo.getToAddress() != null
&& mailInfo.getToAddress().length() > 0) {
Address to = new InternetAddress(mailInfo.getToAddress());
// Message.RecipientType.TO属性表示接收者的类型为TO
mailMessage.setRecipient(Message.RecipientType.TO, to);
} else if (mailInfo.getToBatchAddress() != null
&& mailInfo.getToBatchAddress().length > 0) {
final int size = mailInfo.getToBatchAddress().length;
Address[] to = new Address[size];
for (int i = 0; i < size; i++) {
to[i] = new InternetAddress(mailInfo.getToBatchAddress()[i]);
}
// Message.RecipientType.TO属性表示接收者的类型为TO
mailMessage.setRecipients(Message.RecipientType.TO, to);
}
// 设置邮件消息的主题
mailMessage.setSubject(mailInfo.getSubject());
// 设置邮件消息发送的时间
mailMessage.setSentDate(new Date());
// 设置邮件消息的主要内容
String mailContent = mailInfo.getContent();
mailMessage.setText(mailContent);
// 发送邮件
Transport.send(mailMessage);
return true;
} catch (MessagingException ex) {
ex.printStackTrace();
}
return false;
} /**
* 以HTML格式发送邮件
*
* @param mailInfo
* 待发送的邮件信息
*/
public boolean sendHtmlMail(MailSenderInfo mailInfo) {
// 判断是否需要身份认证
MailAuthenticator authenticator = null;
Properties pro = mailInfo.getProperties();
// 如果需要身份认证,则创建一个密码验证器
if (mailInfo.isValidate()) {
authenticator = new MailAuthenticator(mailInfo.getUserName(),
mailInfo.getPassword());
}
// 根据邮件会话属性和密码验证器构造一个发送邮件的session
Session sendMailSession = Session
.getDefaultInstance(pro, authenticator);
try {
sendMailSession.setDebug(true);
// 根据session创建一个邮件消息
Message mailMessage = new MimeMessage(sendMailSession);
// 创建邮件发送者地址
Address from = new InternetAddress(mailInfo.getFromAddress());
// 设置邮件消息的发送者
mailMessage.setFrom(from);
// 创建邮件的接收者地址,并设置到邮件消息中
if (mailInfo.getToAddress() != null
&& mailInfo.getToAddress().length() > 0) {
Address to = new InternetAddress(mailInfo.getToAddress());
// Message.RecipientType.TO属性表示接收者的类型为TO
mailMessage.setRecipient(Message.RecipientType.TO, to);
} else if (mailInfo.getToBatchAddress() != null
&& mailInfo.getToBatchAddress().length > 0) {
final int size = mailInfo.getToBatchAddress().length;
Address[] to = new Address[size];
for (int i = 0; i < size; i++) {
to[i] = new InternetAddress(mailInfo.getToBatchAddress()[i]);
}
// Message.RecipientType.TO属性表示接收者的类型为TO
mailMessage.setRecipients(Message.RecipientType.TO, to);
}
// 设置邮件消息的主题
mailMessage.setSubject(mailInfo.getSubject());
mailMessage.setSubject(MimeUtility.encodeText(mailInfo.getSubject(), "UTF-8", "B"));
// 设置邮件消息发送的时间
mailMessage.setSentDate(new Date());
// MiniMultipart类是一个容器类,包含MimeBodyPart类型的对象
Multipart mainPart = new MimeMultipart(); //-------------------------------beigin 文本---------------------//
// 创建一个包含HTML内容的MimeBodyPart
BodyPart html = new MimeBodyPart();
// 设置HTML内容
html.setContent(mailInfo.getContent(), "text/html; charset=utf-8");
mainPart.addBodyPart(html);
//----------------------------------end 文本---------------------// //-------------------------------beigin 附件---------------------//
if(mailInfo.getAttachFileList() != null && mailInfo.getAttachFileList().size() > 0){
for (String[] files : mailInfo.getAttachFileList()) {
for (String file : files) {
//邮件的附件
String fileName = file;
if(fileName != null&&!fileName.trim().equals("")) {
MimeBodyPart mbp = new MimeBodyPart();
FileDataSource fileSource = new FileDataSource(fileName);
mbp.setDataHandler(new DataHandler(fileSource));
try {
mbp.setFileName(MimeUtility.encodeText(fileSource.getName()));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
mainPart.addBodyPart(mbp);
}
}
}
} else {
if(mailInfo.getAttachFileNames() != null && mailInfo.getAttachFileNames().length > 0){
//邮件的附件
String fileName = mailInfo.getAttachFileNames()[0];
if(fileName != null&&!fileName.trim().equals("")) {
MimeBodyPart mbp = new MimeBodyPart();
FileDataSource fileSource = new FileDataSource(fileName);
mbp.setDataHandler(new DataHandler(fileSource));
try {
mbp.setFileName(MimeUtility.encodeText(fileSource.getName()));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
mainPart.addBodyPart(mbp);
}
}
} //----------------------------------end 附件---------------------// // 将MiniMultipart对象设置为邮件内容
mailMessage.setContent(mainPart);
// 发送邮件
Transport.send(mailMessage);
System.out.println("发送成功!");
return true;
} catch (MessagingException ex) {
ex.printStackTrace();
} catch (UnsupportedEncodingException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
return false;
} /**
* 以HTML格式发送多封邮件
*
* @param mailInfo
* 待发送的邮件信息
*/
public boolean sendBatchHtmlMail(MailSenderInfo mailInfo) {
// 判断是否需要身份认证
MailAuthenticator authenticator = null;
Properties pro = mailInfo.getProperties();
pro.setProperty("mail.transport.protocol", "smtp");
// 如果需要身份认证,则创建一个密码验证器
if (mailInfo.isValidate()) {
authenticator = new MailAuthenticator(mailInfo.getUserName(),
mailInfo.getPassword());
}
// 根据邮件会话属性和密码验证器构造一个发送邮件的session
Session sendMailSession = Session.getInstance(pro, authenticator);
try {
// 发送邮件
sendMailSession.setDebug(true);
Transport transport = sendMailSession.getTransport();
transport.connect(mailInfo.getMailServerHost(),Integer.parseInt(mailInfo.getMailServerPort()),
mailInfo.getUserName(), mailInfo.getPassword());
// 创建邮件的接收者地址,并设置到邮件消息中
if (mailInfo.getToBatchAddress() != null
&& mailInfo.getToBatchAddress().length > 0) {
final int size = mailInfo.getToBatchAddress().length;
for (int i = 0; i < size; i++) {
// 根据session创建一个邮件消息
Message mailMessage = new MimeMessage(sendMailSession);
// 创建邮件发送者地址
Address from = new InternetAddress(mailInfo.getFromAddress());
// 设置邮件消息的发送者
mailMessage.setFrom(from); // 设置邮件消息的主题
mailMessage.setSubject(mailInfo.getSubjects()[i]);
mailMessage.setSubject(MimeUtility.encodeText(mailInfo.getSubjects()[i], "UTF-8", "B"));
// 设置邮件消息发送的时间
mailMessage.setSentDate(new Date());
// MiniMultipart类是一个容器类,包含MimeBodyPart类型的对象
Multipart mainPart = new MimeMultipart(); //-------------------------------beigin 文本---------------------//
// 创建一个包含HTML内容的MimeBodyPart
BodyPart html = new MimeBodyPart();
// 设置HTML内容
html.setContent(mailInfo.getContents()[i], "text/html; charset=utf-8");
mainPart.addBodyPart(html);
//----------------------------------end 文本---------------------// //-------------------------------beigin 附件---------------------//
if(mailInfo.getAttachFileList() != null && mailInfo.getAttachFileList().size() > 0){
String[] files = mailInfo.getAttachFileList().get(i);
for (String file : files) {
//邮件的附件
String fileName = file;
if(fileName != null&&!fileName.trim().equals("")) {
MimeBodyPart mbp = new MimeBodyPart();
FileDataSource fileSource = new FileDataSource(fileName);
mbp.setDataHandler(new DataHandler(fileSource));
try {
mbp.setFileName(MimeUtility.encodeText(fileSource.getName()));
//System.out.println("ceshi2: " + MimeUtility.encodeText(fileSource.getName(),"utf-8",null));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
mainPart.addBodyPart(mbp);
}
}
} else {
if(mailInfo.getAttachFileNames() != null && mailInfo.getAttachFileNames().length > 0){
//邮件的附件
String fileName = mailInfo.getAttachFileNames()[i];
if(fileName != null&&!fileName.trim().equals("")) {
MimeBodyPart mbp = new MimeBodyPart();
FileDataSource fileSource = new FileDataSource(fileName);
mbp.setDataHandler(new DataHandler(fileSource));
try {
mbp.setFileName(MimeUtility.encodeText(fileSource.getName()));
//System.out.println("ceshi: " + MimeUtility.encodeText(fileSource.getName(),"utf-8",null));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
mainPart.addBodyPart(mbp);
}
}
}
//----------------------------------end 附件---------------------// // 将MiniMultipart对象设置为邮件内容
mailMessage.setContent(mainPart); Address[] to = new Address[]{new InternetAddress(mailInfo.getToBatchAddress()[i])};
mailMessage.setRecipient(Message.RecipientType.TO, to[0]);
transport.sendMessage(mailMessage, to);
}
}
transport.close();
System.out.println("发送成功!");
return true;
} catch (AddressException e) {
e.printStackTrace();
} catch (NoSuchProviderException e) {
e.printStackTrace();
} catch (MessagingException e) {
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} return false;
}
}

测试

import java.util.Date;
import java.util.Properties; import javax.mail.Address;
import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage; import com.only.mate.email.MailAuthenticator;
import com.only.mate.email.MailSenderInfo;
import com.only.mate.email.SimpleMailSender;
import com.sun.mail.util.MailSSLSocketFactory; public class EmailTest {
private MailSenderInfo mailSenderInfo; public static void main(String[] args) throws Exception {
EmailTest test = new EmailTest();
// test.sendTextEmail1();
// test.sendTextEmail();
test.sendHtmlEmail();
} {
mailSenderInfo = new MailSenderInfo();
mailSenderInfo.setMailServerHost("smtp.qq.com");
mailSenderInfo.setMailServerPort("465");
mailSenderInfo.setUserName("*********@qq.com");
mailSenderInfo.setPassword("***********");
mailSenderInfo.setFromAddress("********@qq.com");
mailSenderInfo.setToAddress("********@qq.com"); mailSenderInfo.setValidate(true); mailSenderInfo.setSubject("主题-你猜猜?");
Date date = new Date();
String content = String.format(
"<!DOCTYPE html>"+
"<html lang=\"en\">"+
"<head>"+
"<meta charset=\"UTF-8\" />"+
"<title></title>"+
"</head>"+
"<style type=\"text/css\">heml,body{margin: 0;padding: 0;font-size: 14px;}.container{width: 880px;margin:0 auto;background: #e7f5ff;height:800px;padding-top: 80px;margin-top: 20px;}.container-con{width:680px;margin:0 auto;background:#fff;height:600px;padding:20px;}.eamil-top{font-size: 14px;}.eamil-top>span{color:#000;font-weight: bold;}.eamil-top2{font-size: 14px;padding-left: 16px;margin-bottom: 30px;}.eamil-con{padding:20px;}.eamil-con>p{line-height: 20px;}.top-img{background:url(\"images/tt0_03.png\") no-repeat;background-size: cover; width:722px;height:100px;margin:0 auto;}.fpptwe{line-height: 30px;}.footer{float: right;}.jingao{font-size: 12px;color:#888}</style>"+
"<body>"+
"<div class=\"container\">"+
"<div class=\"top-img\"></div>"+
"<div class=\"container-con\">"+
"<p class=\"eamil-top\">"+
"尊敬的XX女士"+
"</p>"+
"<p class=\"eamil-top2\">您好!</p>"+
"<div class=\"eamil-con\">"+
"<p>您所提交“XXX”的申请,已通过。</p>"+
"<p>"+
"请及时前往去享受!<span>%s</span>"+
"</p>"+
"<img src='http://img.mp.itc.cn/upload/20160326/73a64c935e7d4c9594bdf86d76399226_th.jpg' />"+
"</div>"+
"<p class=\"jingao\">(这是一封系统自动发送的邮件,请不要直接回复。)</p>"+
"<div class=\"footer\">"+
"<p>爱的港湾</p>"+
"<span>%tF %tT</span>"+
"</div>"+
"</p>"+
"</div>"+
"</div>"+
"</body>"+
"</html>", "❤☻☻☻☻❤", date, date);
mailSenderInfo.setContent(content);
// mailSenderInfo.setContent("其实只是好玩而已"); mailSenderInfo.setAttachFileNames(new String[] {"C:/Users/OnlyMate/Pictures/MyPhoneTheme.jpg"});
}
public void sendTextEmail() throws Exception {
SimpleMailSender sender = new SimpleMailSender();
sender.sendTextMail(mailSenderInfo);
}
public void sendHtmlEmail() throws Exception {
SimpleMailSender sender = new SimpleMailSender();
sender.sendHtmlMail(mailSenderInfo);
}
public void sendTextEmail1() throws Exception {
Properties props = new Properties(); // 开启debug调试
props.setProperty("mail.debug", "false");
// 发送服务器需要身份验证
props.setProperty("mail.smtp.auth", "true");
// 使用 STARTTLS安全连接
props.put("mail.smtp.starttls.enable", "true");
// 设置邮件服务器主机名
props.setProperty("mail.smtp.host", mailSenderInfo.getMailServerHost());
// 设置邮件服务器端口
props.put("mail.smtp.port", mailSenderInfo.getMailServerPort());
// 发送邮件协议名称
props.setProperty("mail.transport.protocol", "smtp"); MailSSLSocketFactory sf = new MailSSLSocketFactory();
sf.setTrustAllHosts(true);
props.put("mail.smtp.ssl.enable", "true");
props.put("mail.smtp.ssl.socketFactory", sf); // 如果需要身份认证,则创建一个密码验证器
MailAuthenticator authenticator = new MailAuthenticator(mailSenderInfo.getUserName(),
mailSenderInfo.getPassword());
// 根据邮件会话属性和密码验证器构造一个发送邮件的session
Session session = Session.getDefaultInstance(props, authenticator); Message msg = new MimeMessage(session);
msg.setSubject("主题-你猜猜?");
StringBuilder builder = new StringBuilder();
builder.append("测试邮件: 我用Java代码给你发送了一份邮件!我的❤你收到了吗?");
msg.setText(builder.toString());
msg.setFrom(new InternetAddress(mailSenderInfo.getUserName()));
Address to = new InternetAddress(mailSenderInfo.getToAddress());
// Message.RecipientType.TO属性表示接收者的类型为TO
msg.setRecipient(Message.RecipientType.TO, to); Transport.send(msg);
/*Transport transport = session.getTransport("smtp");
transport.connect(mailSenderInfo.getMailServerHost(),mailSenderInfo.getUserName(), "irfydcgrkxembbii"); transport.sendMessage(msg, new Address[] { new InternetAddress("*****@qq.com") });
transport.close();*/
}
}

说明:QQ普通用户只用使用:

  mail.smtp.host = "smtp.qq.com";
  mail.smtp.port = "465";

  要开启SSL

  QQ企业用户只能使用:

  mail.smtp.host = "smtp.exmail.qq.com";
  mail.smtp.port = "25";

  不开启SSL

Java后端发送email实现的更多相关文章

  1. 使用Java程序发送Email

        目前很多大型的网站忘记登录密码常见的一种形式是使用邮箱找回密码  最近做项目也有这个需求  现在总结一下  以便以后查看 使用到的包有 mailapi.jar smtp.jar   封装发送邮 ...

  2. java后端发送请求

    package com.ty.mapapisystem.util; import java.io.BufferedReader;import java.io.FileInputStream;impor ...

  3. java后端发送请求并获取响应

    URL wsUrl = new URL(url); HttpURLConnection conn = (HttpURLConnection) wsUrl.openConnection(); conn. ...

  4. java后台发送请求并获取返回值(续)

    在java后端发送请求给另一个平台,从而给前端实现 "透传"的过程中,出现:数据请求到了并传到了前端,但是控制台打印时中文显示Unicode码而前端界面中中文显示不出来!!!开始怀 ...

  5. java发送email

    package com.assess.util; import java.io.File; import java.util.ArrayList; import java.util.List; imp ...

  6. java mail实现Email的发送,完整代码

    java mail实现Email的发送,完整代码 1.对应用程序配置邮件会话 首先, 导入jar <dependencies> <dependency> <groupId ...

  7. 使用spring 并加载模板发送Email 发邮件 java 模板

    以下例子是使用spring发送email,然后加载到固定的模板,挺好的,大家可以试试 需要使用到spring-context 包 和 com.springsource.org.apache.veloc ...

  8. java发送email一般步骤

    java发送email一般步骤 一.引入javamail的jar包: 二.创建一个测试类,实现将要发送的邮件内容写入到计算机本地,查看是否能够将内容写入: public static void mai ...

  9. Java发送email的端口问题

    Could not connect to SMTP host: smtp.***.com, port: 465, response: -1 使用Java发送email 的端口问题.一般使用25端口即可 ...

随机推荐

  1. Resteasy集成Spring

    很简单,都用最新的版本就可以了.之前在网上找的教程都是用resteasy2.x和spring3集成,但是resteasy2.x和spring4是不行的,弄了很久.最后换成最新的resteasy3.x好 ...

  2. try...except包含try...finally方法

    def f(): try: try: f = open(raw_input('>')) print f.readlines() finally: f.close() #1/0 except Ex ...

  3. python 除法

  4. Java [Leetcode 167]Two Sum II - Input array is sorted

    题目描述: Given an array of integers that is already sorted in ascending order, find two numbers such th ...

  5. HDU - 5942 :Just a Math Problem (莫比乌斯)

    题意:略. 思路:问题转化为1到N,他们的满足mu[d]!=0的因子d个数.  即1到N的因子的莫比乌斯系数平方和. (经验:累加符号是累加的个数,我们把常数提到前面,然后用杜教筛累加个数即可. ht ...

  6. BZOJ4547 Hdu5171 小奇的集合 【矩阵快速幂优化递推】

    BZOJ4547 Hdu5171 小奇的集合 Description 有一个大小为n的可重集S,小奇每次操作可以加入一个数a+b(a,b均属于S),求k次操作后它可获得的S的和的最大值.(数据保证这个 ...

  7. 20179223《Linux内核原理与分析》第二周学习笔记

    第二周实验 本周学习情况: 学习了X86 cpu的几个寄存器及X86汇编指令: movl %eax,%edx edx=eax %表示一个寄存器,把eax内容放入edx,等号相当于把eax赋值给edx, ...

  8. ssh连接至Ubuntu服务器时,提示以下错误:REMOTE HOST IDENTIFICATION HAS CHANGED!

    今天在使用Ubuntu搭建自己的git仓库的时候,搭建完成后clone时出现以下错误 经过搜索问题出现原因的描述如下:第一次使用SSH连接时,会生成一个认证,储存在客户端的known_hosts中. ...

  9. 洛谷 P1098 字符串的展开

    题目描述 在初赛普及组的“阅读程序写结果”的问题中,我们曾给出一个字符串展开的例子:如果在输入的字符串中,含有类似于“d-h”或者“4-8”的字串,我们就把它当作一种简写,输出时,用连续递增的字母或数 ...

  10. 40+个对初学者非常有用的PHP技巧

    1.不要使用相对路径,要定义一个根路径 这样的代码行很常见: require_once('../../lib/some_class.php'); 这种方法有很多缺点: 它首先搜索php包括路径中的指定 ...