Commit 51ea2333 by zhiwei

增加100M以下文件发送

parent 4b464581
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>com.zhiwei</groupId> <groupId>com.zhiwei</groupId>
<artifactId>sendmail</artifactId> <artifactId>sendmail</artifactId>
<version>0.0.3-SNAPSHOT</version> <version>0.0.4-SNAPSHOT</version>
<name>sendmail</name> <name>sendmail</name>
<description>发送邮件</description> <description>发送邮件</description>
......
...@@ -93,11 +93,11 @@ public class SimpleMailSender { ...@@ -93,11 +93,11 @@ public class SimpleMailSender {
mailMessage.setSubject(mailInfo.getSubject()); mailMessage.setSubject(mailInfo.getSubject());
// 设置邮件消息发送的时间 // 设置邮件消息发送的时间
mailMessage.setSentDate(new Date()); mailMessage.setSentDate(new Date());
// MiniMultipart类是一个容器类,包含MimeBodyPart类型的对象 // MiniMultipart类是一个容器类,包含MimeBodyPart类型的对象
Multipart multiPart = new MimeMultipart(); Multipart multiPart = new MimeMultipart();
// 创建一个包含HTML内容的MimeBodyPart // 创建一个包含HTML内容的MimeBodyPart
BodyPart bodyPart = new MimeBodyPart(); BodyPart bodyPart = new MimeBodyPart();
// 设置HTML内容 // 设置HTML内容
bodyPart.setContent(mailInfo.getContent(), "text/html; charset=utf-8"); bodyPart.setContent(mailInfo.getContent(), "text/html; charset=utf-8");
multiPart.addBodyPart(bodyPart); multiPart.addBodyPart(bodyPart);
...@@ -113,7 +113,8 @@ public class SimpleMailSender { ...@@ -113,7 +113,8 @@ public class SimpleMailSender {
} }
} }
// 发送邮件 // 发送邮件
Transport.send(mailMessage); mailMessage.saveChanges();
Transport.send(mailMessage, mailMessage.getAllRecipients());
return true; return true;
} }
......
...@@ -9,19 +9,19 @@ import com.zhiwei.sendmail.bean.MailInfo; ...@@ -9,19 +9,19 @@ import com.zhiwei.sendmail.bean.MailInfo;
public class SendMailTest { public class SendMailTest {
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
// 这个类主要是设置邮件 // 这个类主要是设置邮件
String mailServerHost = "smtp.ym.163.com"; String mailServerHost = "smtphz.qiye.163.com";
String mailServerPort = "25"; String mailServerPort = "25";
String fromAddress = "zhangzhiwei@zhiweidata.com"; String fromAddress = "zhangzhiwei@zhiweidata.com";
String fromName = "测试"; String fromName = "测试";
String toAddress = "859548429@qq.com"; String toAddress = "yuchengyi@zhiweidata.com";
String userName = "zhangzhiwei@zhiweidata.com"; String userName = "zhangzhiwei@zhiweidata.com";
String password = "olp1437z.."; String password = "olp1437z..";
boolean validate = true; boolean validate = true;
String subject = "带附件的邮件测试程序"; String subject = "带附件的邮件测试程序";
String content = "发送邮件测试"; String content = "发送邮件测试";
String copyAddress = "825290417@qq.com,chenweiyang@zhiweidata.com"; String copyAddress = "chenweiyang@zhiweidata.com";
List<String> attachFileNames = new ArrayList<String>(); List<String> attachFileNames = new ArrayList<String>();
attachFileNames.add("E://数据//2017年数据//9月份数据//南京组-美团日报数据//南京组-美团日报数据2017-09-28-微博.xlsx"); attachFileNames.add("C:\\Users\\admin\\Desktop\\质检数据-大词-2020-04-13.xlsx");
MailInfo mailInfo = new MailInfo(mailServerHost, mailServerPort, fromAddress,fromName, toAddress, userName, password, MailInfo mailInfo = new MailInfo(mailServerHost, mailServerPort, fromAddress,fromName, toAddress, userName, password,
validate, subject, content, copyAddress, attachFileNames); validate, subject, content, copyAddress, attachFileNames);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment