package com.jit.mail.Utils;
import com.jit.mail.domain.Mail;
import com.jit.mail.service.MailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import javax.mail.*;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeUtility;
import javax.validation.constraints.Min;
import java.io.*;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Properties;
public class ReceiveMail {
public MimeMessage mimeMessage = null;
// @Value("${test.attach}")
public String saveAttachPath;//附件下载后存放目录
public StringBuffer bodytext = new StringBuffer();//存放邮件内容
// public StringBuffer bodyhtml = new StringBuffer(5000);
public String dateformat = "yyyy-MM-dd HH:mm";
public ReceiveMail() {
}
public ReceiveMail(MimeMessage mimeMessage) {
this.mimeMessage = mimeMessage;
System.out.println("create a PraseMimeMessage object........");
}
public void setMimeMessage(MimeMessage mimeMessage) {
this.mimeMessage = mimeMessage;
}
public static List<Mail> receiveMail(String host, String username, String password) throws Exception {
// 初始化主机
// String host = "luwei.com";
// String username = "test1";
// String password = "test1";
// 配置服务器属性
List<Mail> mailList = new ArrayList<>();
Properties props = new Properties();
props.put("mail.smtp.host", host); // smtp服务器
props.put("mail.smtp.auth", "true"); // 是否smtp认证
props.put("mail.smtp.port", "25"); // 设置smtp端口
props.put("mail.transport.protocol", "smtp"); // 发邮件协议
props.put("mail.store.protocol", "pop3"); // 收邮件协议
// 获取会话
Session session = Session.getDefaultInstance(props, null);
// 获取Store对象,使用POP3协议,也可能使用IMAP协议
try {
Store store = session.getStore("pop3");
// 接到邮件服务器
store.connect(host, username, password);
// 获取该用户Folder对象,并以只读方式打开
Folder folder = store.getFolder("inbox");
folder.open(Folder.READ_ONLY);
// 检索所有邮件,按需填充
Message message[] = folder.getMessages();
ReceiveMail pmm = null;
for (int i = 0; i < message.length; i++) {
Mail mail = new Mail();
pmm = new ReceiveMail((MimeMessage) message[i]);
mail.setSmtpServer(host);
mail.setFromUser(pmm.getFrom());
System.out.println("Message " + i + " form: " + pmm.getFrom());
mail.setSubject(pmm.getSubject());
System.out.println("Message " + i + " subject: " + pmm.getSubject());
mail.setSentDate(pmm.getSentDate());
mail.setReceiveDate(pmm.getReceiveDate());
System.out.println("Message " + i + " sentdate: " + pmm.getSentDate());
mail.setHasRead(pmm.isNew());
System.out.println("Message " + i + " 是否已读: " + pmm.isNew());
System.out.println("Message " + i + " 是否包含附件: " + pmm.isContainAttach((Part) message[i]));
mail.setToUser(pmm.getMailAddress("to"));
mail.setCc(pmm.getMailAddress("cc"));
mail.setBcc(pmm.getMailAddress("bcc"));
System.out.println("Message " + i + " to: " + pmm.getMailAddress("to"));
System.out.println("Message " + i + " cc: " + pmm.getMailAddress("cc"));
mail.setMessageId(pmm.getMessageId());
System.out.println("Message " + i + " Message-ID: " + pmm.getMessageId());
// mail.setReplyTo(pmm.getReplyToEmail());
// System.out.println("Message " + i + " 回复邮件: " + pmm.getReplyToEmail());
pmm.getMailContent((Part) message[i]);
mail.setContent(pmm.getBodyText());
System.out.println("Message " + i + " bodycontent(文本内容):" + pmm.getBodyText());
// if(pmm.getBodyHtml() != null){
// System.out.println("Message "+i+" bodycontent(超文本内容):"+pmm.getBodyText());
// }
pmm.setAttachPath("c:\\mail_attach");
if (pmm.isContainAttach((Part) message[i])) {
String filenameList = pmm.saveAttachMent((Part) message[i]);
mail.setAttachName(filenameList);
mail.setAttachPath(pmm.saveAttachPath);
System.out.println("文件名的列表:" + filenameList);
} else {
mail.setAttachPath(null);
mail.setAttachName(null);
System.out.println("没有附件");
}
mailList.add(mail);
}
// for (int i = 0; i < message.length; i++) {
// Mail mail = new Mail();
//
//// mail.setSubject(message[i].getSubject());
//// mail.setContent(message[i].getContent().toString());
// // 打印出每个邮件的发件人和主题
// System.out.println(message[i]);
// System.out.println(i + ":" + message[i].getFrom()[0] + "\t"
// + message[i].getSubject());
//
// System.out.println("内容类别:"+message[i].getContentType());
// }
folder.close(false);
store.close();
} catch (NoSuchProviderException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (MessagingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return mailList;
}
/**
* 获得发件人的地址和姓名
*/
public String getFrom() throws Exception {
InternetAddress address[] = (InternetAddress[]) mimeMessage.getFrom();
String from = address[0].getAddress();
if (from == null) from = "";
String personal = address[0].getPersonal();
if (personal == null) personal = "";
// String fromaddr = personal+"<"+from+">";
return from;
}
// public String getReplyToEmail() throws Exception{
// String replyToUser = "";
// Message message = mimeMessage.reply(false);
// String address = message
// }
/**
* 获得邮件的收件人,抄送,和密送的地址和姓名,根据所传递的参数的不同
* "to"----收件人 "cc"---抄送人地址 "bcc"---密送人地址
*/
public String getMailAddress(String type) throws Exception {
String mailaddr = "";
String addtype = type.toUpperCase();
InternetAddress[] address = null;
if (addtype.equals("TO") || addtype.equals("CC") || addtype.equals("BCC")) {
if (addtype.equals("TO")) {
address = (InternetAddress[]) mimeMessage.getRecipients(Message.RecipientType.TO);
} else if (addtype.equals("CC")) {
address = (InternetAddress[]) mimeMessage.getRecipients(Message.RecipientType.CC);
} else {
address = (InternetAddress[]) mimeMessage.getRecipients(Message.RecipientType.BCC);
}
if (address != null) {
for (int i = 0; i < address.length; i++) {
String email = address[i].getAddress();
if (email == null)
没有合适的资源?快使用搜索试试~ 我知道了~
java项目,课程设计-商务安全邮箱邮件收发.zip
共1531个文件
png:368个
js:266个
gif:160个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 56 浏览量
2024-11-26
11:17:11
上传
评论
收藏 163.05MB ZIP 举报
温馨提示
随着社会的发展,社会的方方面面都在利用信息化时代的优势。计算机的优势和普及使得商务安全邮箱的开发成为必需。 本文以实际运用为开发背景,运用软件工程原理和开发方法,采用jsp技术构建一个商务安全邮箱系统。整个开发过程首先对系统进行需求分析,得出系统主要功能。接着对系统进行总体设计和详细设计。总体设计主要包括系统功能设计,系统总体结构设计,系统数据结构设计和系统安全设计等;详细设计主要包括系统数据库访问的实现,主要功能模块的具体实现,模块实现关键代码等。最后对系统进行了功能测试,并对测试结果进行了分析总结,得出系统的不足及需要改进的地方,为以后的系统维护提供了方便,同时也为今后开发类似系统提供了借鉴和帮助。 本系统的开发使用户能够更加方便快捷的商务安全邮箱 ,同时也促使商务安全邮箱变的更加系统化、有序化。
资源推荐
资源详情
资源评论
收起资源包目录
java项目,课程设计-商务安全邮箱邮件收发.zip (1531个子文件)
MailController.class 14KB
MailController.class 13KB
ReceiveMail.class 12KB
ReceiveMail.class 12KB
SpamCollection.class 9KB
SpamCollection.class 9KB
SkinController.class 6KB
SkinController.class 6KB
DeleteMailController.class 5KB
DeleteMailController.class 5KB
UserController.class 5KB
SpamController.class 5KB
SpamController.class 5KB
UserRelationController.class 5KB
UserRelationController.class 5KB
IndexController.class 5KB
IndexController.class 5KB
SendMailUt.class 4KB
UserController.class 4KB
DigestUtil.class 4KB
DigestUtil.class 4KB
SendMailUt.class 4KB
ChosenSkinController.class 4KB
ChosenSkinController.class 4KB
DeleteMail.class 3KB
DeleteMail.class 3KB
Spam.class 3KB
Mail.class 3KB
Mail.class 3KB
Spam.class 3KB
Skin.class 3KB
Skin.class 3KB
SendMail.class 3KB
SendMail.class 3KB
UserRelationServiceImpl.class 2KB
UserRelationServiceImpl.class 2KB
MailServiceImpl.class 2KB
MailServiceImpl.class 2KB
UeditorController.class 2KB
UeditorController.class 2KB
SpamServiceImpl.class 2KB
SpamServiceImpl.class 2KB
CommonInterceptor.class 2KB
User.class 2KB
CommonInterceptor.class 2KB
User.class 2KB
DeleteMailServiceImpl.class 2KB
DeleteMailServiceImpl.class 2KB
SendMailServiceImpl.class 2KB
SendMailServiceImpl.class 2KB
ChosenSkinServiceImpl.class 2KB
ChosenSkinServiceImpl.class 2KB
SkinServiceImpl.class 2KB
SkinServiceImpl.class 2KB
ChosenSkin.class 2KB
ChosenSkin.class 2KB
UserServiceImpl.class 2KB
UserServiceImpl.class 2KB
UserRelation.class 1KB
UserRelation.class 1KB
CommonInterceptorConfig.class 1KB
CommonInterceptorConfig.class 1KB
KeywordCount.class 1KB
KeywordCount.class 1KB
MailRepository.class 1KB
MailRepository.class 1KB
SmtpAuth.class 1KB
SmtpAuth.class 1KB
FileUtilss.class 1KB
FileUtilss.class 1KB
MailApplication.class 696B
MailApplication.class 696B
UserRelationService.class 674B
UserRelationService.class 674B
UserRelationRepository.class 640B
UserRelationRepository.class 640B
SpamRepository.class 615B
SpamRepository.class 615B
MailApplicationTests.class 614B
SpamService.class 609B
SpamService.class 609B
MailService.class 603B
DeleteMailService.class 603B
DeleteMailService.class 603B
MailService.class 603B
ChosenSkinRepository.class 580B
ChosenSkinRepository.class 580B
DeleteMailRepository.class 579B
DeleteMailRepository.class 579B
ChosenSkinService.class 558B
ChosenSkinService.class 558B
SendMailService.class 525B
SendMailService.class 525B
SendMailRepository.class 519B
SendMailRepository.class 519B
SkinService.class 448B
SkinService.class 448B
UserService.class 447B
UserService.class 447B
UserRepository.class 410B
共 1531 条
- 1
- 2
- 3
- 4
- 5
- 6
- 16
资源评论
ItKevin爱java
- 粉丝: 1380
- 资源: 452
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- Simulink&Stateflow
- selective-scan-0.0.2-cp310-cp310-win-amd64.whl.zip(包含core)
- Lazarus,FPC 的 DirectX 示例.zip
- SPI软件模拟读写W25Q128
- springboot入门.docx
- selective-scan-0.0.2-cp310-cp310-win-amd64.whl.zip(不含core)
- KatanaZero DirectX MFC工具.zip
- 捕食者直升机无人机3D
- Johnny Chung Lee 的 Wii Remote Head Tracking 代码的 git 存储库(不是我的项目).zip
- 离线下,给用户机器封U盘口 可以自定义密码,原始密码6个1 该工具权限>本地组策略等
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功