1 Star 6 Fork 6

皮球爸爸 / emailutil

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

emailutil

登陆163邮箱、读取收件箱的邮件信息、发送邮件. 后期扩展到其他邮件服务器。

感谢:主要源码来自github的emailutil项目,在此基础上增加了将邮箱中的pdf和ofd同步到本地的方法

How to use

类路径下配置 emailServerConfig.properties

# POP 邮件服务器的地址
mailServer_POP3Host = pop.163.com
# SMTP 邮件服务器的地址
mailServer_SMTPHost = smtp.163.com
# 邮箱地址
myEmailAddress = xxxxxx@163.com
# 邮箱用户名
userName = xxxxxx
# 注意使用的是开通 SMTP、 POP、IMAP 协议的授权码
password = xxxxxx
# 是否需要验证
validate = true

Fetching Emails

@Test
public void testReadEmail() throws FileNotFoundException {

	// 获取配置的登陆邮件服务器的信息
	EmailServerInfo emailServerInfo = EmailTemplateUtil.getConfigEmailServerInfo();
	
	// 读取最近的一份邮件
	ReadEmailInfo emailInfo = EmailTemplateUtil.getLatestOneEmailInfo(emailServerInfo);
	// 获取所有邮件
	// List<EmailInfo> emailInfos = EmailTemplateUtil.getAllEmailInfos(emailServerInfo);
	System.out.println(emailInfo.toString());
}

Sending Emails

@Test
public void testSendEmailTemplate() throws FileNotFoundException {

	// 获取配置的登陆邮件服务器的信息
	EmailServerInfo emailServerInfo = EmailTemplateUtil.getConfigEmailServerInfo();
	
	// 构建邮件 email
	EmailInfo email = new EmailInfo();
	String[] toes = {"xxxxxx@qq.com", "xxxxxx@qq.com"}; // change accordingly
	email.setToAddress(toes);
	email.setSubject("test 主题2");
	
	StringBuffer content = new StringBuffer();
	
	// 发送链接有的邮箱服务器可能将此邮件识别为垃圾邮件。
	content.append("<h2><font color=red>Header标题</font></h2><br/>")
    .append("<span class=\"test\">this is content!内容</span>")  
	email.setContent(content.toString());
	
	// 设置上传的附件
	email.getAttachmentFiles().add("E:\\Photos\\bob.jpeg");
	email.getAttachmentFiles().add("E:\\heartocat.png");
	email.getAttachmentFiles().add("E:\\Music\\Alison Krauss - When You Say Nothing At All.mp3");
	
	EmailTemplateUtil.sendEmail(emailServerInfo, email);
}

Deleting Emails

@Test
public void testDeleteEmail() throws FileNotFoundException {

	// 获取配置的登陆邮件服务器的信息
	EmailServerInfo emailServerInfo = EmailTemplateUtil.getConfigEmailServerInfo();
	
	// 删除第一份邮件
	if (EmailTemplateUtil.deleteEmailByMsgNum(emailServerInfo, 1)) {
		System.out.println("删除成功!");
	} else {
		System.out.println("删除失败!");
	}
}

Replying Emails

@Test
public void testDeleteEmail() throws FileNotFoundException {

	// 获取配置的登陆邮件服务器的信息
	EmailServerInfo emailServerInfo = EmailTemplateUtil.getConfigEmailServerInfo();
	
	String content = "这是回复内容";
	String[] attachmentFiles = {"E:\\Photos\\bob.jpeg"}; // 设置回复的附件
	
	// 回复第一份邮件
	if (EmailTemplateUtil.replyEmail(emailServerInfo, 1, content, attachmentFiles)) {
		System.out.println("回复成功!");
	} else {
		System.out.println("回复失败!");
	}
}

Forwarding Emails

@Test
public void testForwardEmail() throws FileNotFoundException {

	// 获取配置的登陆邮件服务器的信息
	EmailServerInfo emailServerInfo = EmailTemplateUtil.getConfigEmailServerInfo();
	
	String content = "这是转发的附加内容";
	String[] attachmentFiles = {"E:\\Photos\\bob.jpeg"};  // 设置附件
	// 设置转发的地址
	String[] forwardAddress = {"xxxxxx@qq.com", "xxxxxx@qq.com"};
	
	if (EmailTemplateUtil.forwardEmail(emailServerInfo, 61, content, attachmentFiles, forwardAddress)) {
		System.out.println("转发成功!");
	} else {
		System.out.println("转发失败!");
	}
}
MIT License Copyright (c) 2020 皮球爸爸 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

邮件工具,邮件的收取、发送等,目前支持163邮箱(含163.下的企业邮箱,其他家的邮箱可参考进行修改) 获取邮箱中邮件包含的pdf和ofd附件见com.hanmanyi.demo.ReadHasPdfOrOfdEmailTest 其他功能读源码吧 展开 收起
Java
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Java
1
https://gitee.com/kanen/emailutil.git
git@gitee.com:kanen/emailutil.git
kanen
emailutil
emailutil
master

搜索帮助