- 浏览: 2551835 次
- 性别:
- 来自: 成都
文章分类
最新评论
-
nation:
你好,在部署Mesos+Spark的运行环境时,出现一个现象, ...
Spark(4)Deal with Mesos -
sillycat:
AMAZON Relatedhttps://www.godad ...
AMAZON API Gateway(2)Client Side SSL with NGINX -
sillycat:
sudo usermod -aG docker ec2-use ...
Docker and VirtualBox(1)Set up Shared Disk for Virtual Box -
sillycat:
Every Half an Hour30 * * * * /u ...
Build Home NAS(3)Data Redundancy -
sillycat:
3 List the Cron Job I Have>c ...
Build Home NAS(3)Data Redundancy
Mail Server Solution(5)gmail API and Download Attachment
1. List all the Messages based on Query
// List all the messages related to keywords
ListMessagesResponse listMessageResponse = service.users().messages()
.list(user).setQ("job.craigslist.org").execute();
List<Message> messages = new ArrayList<Message>();
while (listMessageResponse.getMessages() != null) {
messages.addAll(listMessageResponse.getMessages());
if (listMessageResponse.getNextPageToken() != null) {
String pageToken = listMessageResponse.getNextPageToken();
listMessageResponse = service.users().messages().list(user).setQ("job.craigslist.org")
.setPageToken(pageToken).execute();
} else {
break;
}
}
for (Message message : messages) {
System.out.println(message.toPrettyString());
}
2. Get the Message Attach Info
//Get the Message Attach Info
Message message = service.users().messages().get(user, "14eda36adbc0789e").execute();
System.out.println("Message snippet: " + message.getSnippet());
List<MessagePart> parts = null;
if(message.getPayload() != null){
parts = message.getPayload().getParts();
if(parts != null && parts.size() > 0){
for(int i = 0; i< parts.size();i++){
MessagePart part = parts.get(i);
System.out.println("====== part " + i + "==========");
System.out.println("filename: " + part.getFilename());
System.out.println("mimetype: " + part.getMimeType());
if(part.getMimeType().equalsIgnoreCase("application/pdf")){
System.out.println("attachmentId : " + part.getBody().getAttachmentId());
}
}
}
}
3. Get the Attachment File
//Get the attachment file
String attachmentId = "ANGjdJ-T4bVPdCT3gQSW-iuq8Txjofxjo3eNjk5qFawdotTon6Rkv2mjH-8EUehiH71OZJsN_mTFA5cHj05JGvuN3_Ev05_26bxUXvO4NaYxw-aExinNWZbUdpgSYqHq5NmS6QVnOKBbsrwdTau1kGzB5JC1qYNuXMKVRuPvrL49RcYEfBR8iIzHDvskqY8bVcyUHPTSCu0mycCf32-eogP7muMu7TO2MjF1HIYv50kCGG2edaSKrBD_miQU6aTqQJVhDJ4BVP7LiEB2bwkZssRuF8esb1Obu7N702e6Gw";
MessagePartBody attachPart = service.users().messages().attachments().get(user, "14eda36adbc0789e", attachmentId).execute();
byte[] fileByteArray = Base64.decodeBase64(attachPart.getData());
FileOutputStream fileOutFile =
new FileOutputStream("/Users/carl/data/" + "attach1.pdf");
fileOutFile.write(fileByteArray);
fileOutFile.close();
It will query my own email and find the attachment files and save to /Users/carl/data/ Directory.
The output on the console will be:
- SPAM
{
"id" : "14eda36adbc0789e",
"threadId" : "14eda360b8f81792"
}
{
"id" : "14eda365e1ab3916",
"threadId" : "14eda365e1ab3916"
}
{
"id" : "14eda363378de6ba",
"threadId" : "14eda363378de6ba"
}
{
"id" : "14eda360b8f81792",
"threadId" : "14eda360b8f81792"
}
Message snippet: From: Amber Link [mailto:amber@jobs2careers.com] Sent: Wednesday, July 29, 2015 9:27 AM To: Suong Luu
====== part 0==========
filename:
mimetype: multipart/alternative
====== part 1==========
filename: JMRES12.ADB.aptx.cc.aus.pdf
mimetype: application/pdf
attachmentId : ANGjdJ-qQ-YVPp8li1c9UG1_dDZcLVIGi44z2wWsz8wOl9Ic3Y9z5yBrlGw-xXW1QIoCmQNHlltmj-AvwlrqvwR9IofMDCJJbQS43VZSRg71raq3vHpPBu_5gFRZnQMd_SSHsWs_duBtrHFXfpPjc_wu-aoxEqLl-HcaCFn3cRMwj2wa1MrpoDKpyzXlGQiKb4Y8afvbHTPa63wVYgNtnBlVlQVl3z1JDADTYazKS8_E0D0Kajktdnc5ezq0E8wMAS6OOBM-fOYm09_NGoEzKCb9zD3q93CnkhvCh49A2g
BUILD SUCCESSFUL
About the Oauth authentication Part
private static final List<String> SCOPES = Arrays.asList(
GmailScopes.GMAIL_READONLY);
References:
https://developers.google.com/gmail/api/v1/reference/users/messages/list
1. List all the Messages based on Query
// List all the messages related to keywords
ListMessagesResponse listMessageResponse = service.users().messages()
.list(user).setQ("job.craigslist.org").execute();
List<Message> messages = new ArrayList<Message>();
while (listMessageResponse.getMessages() != null) {
messages.addAll(listMessageResponse.getMessages());
if (listMessageResponse.getNextPageToken() != null) {
String pageToken = listMessageResponse.getNextPageToken();
listMessageResponse = service.users().messages().list(user).setQ("job.craigslist.org")
.setPageToken(pageToken).execute();
} else {
break;
}
}
for (Message message : messages) {
System.out.println(message.toPrettyString());
}
2. Get the Message Attach Info
//Get the Message Attach Info
Message message = service.users().messages().get(user, "14eda36adbc0789e").execute();
System.out.println("Message snippet: " + message.getSnippet());
List<MessagePart> parts = null;
if(message.getPayload() != null){
parts = message.getPayload().getParts();
if(parts != null && parts.size() > 0){
for(int i = 0; i< parts.size();i++){
MessagePart part = parts.get(i);
System.out.println("====== part " + i + "==========");
System.out.println("filename: " + part.getFilename());
System.out.println("mimetype: " + part.getMimeType());
if(part.getMimeType().equalsIgnoreCase("application/pdf")){
System.out.println("attachmentId : " + part.getBody().getAttachmentId());
}
}
}
}
3. Get the Attachment File
//Get the attachment file
String attachmentId = "ANGjdJ-T4bVPdCT3gQSW-iuq8Txjofxjo3eNjk5qFawdotTon6Rkv2mjH-8EUehiH71OZJsN_mTFA5cHj05JGvuN3_Ev05_26bxUXvO4NaYxw-aExinNWZbUdpgSYqHq5NmS6QVnOKBbsrwdTau1kGzB5JC1qYNuXMKVRuPvrL49RcYEfBR8iIzHDvskqY8bVcyUHPTSCu0mycCf32-eogP7muMu7TO2MjF1HIYv50kCGG2edaSKrBD_miQU6aTqQJVhDJ4BVP7LiEB2bwkZssRuF8esb1Obu7N702e6Gw";
MessagePartBody attachPart = service.users().messages().attachments().get(user, "14eda36adbc0789e", attachmentId).execute();
byte[] fileByteArray = Base64.decodeBase64(attachPart.getData());
FileOutputStream fileOutFile =
new FileOutputStream("/Users/carl/data/" + "attach1.pdf");
fileOutFile.write(fileByteArray);
fileOutFile.close();
It will query my own email and find the attachment files and save to /Users/carl/data/ Directory.
The output on the console will be:
- SPAM
{
"id" : "14eda36adbc0789e",
"threadId" : "14eda360b8f81792"
}
{
"id" : "14eda365e1ab3916",
"threadId" : "14eda365e1ab3916"
}
{
"id" : "14eda363378de6ba",
"threadId" : "14eda363378de6ba"
}
{
"id" : "14eda360b8f81792",
"threadId" : "14eda360b8f81792"
}
Message snippet: From: Amber Link [mailto:amber@jobs2careers.com] Sent: Wednesday, July 29, 2015 9:27 AM To: Suong Luu
====== part 0==========
filename:
mimetype: multipart/alternative
====== part 1==========
filename: JMRES12.ADB.aptx.cc.aus.pdf
mimetype: application/pdf
attachmentId : ANGjdJ-qQ-YVPp8li1c9UG1_dDZcLVIGi44z2wWsz8wOl9Ic3Y9z5yBrlGw-xXW1QIoCmQNHlltmj-AvwlrqvwR9IofMDCJJbQS43VZSRg71raq3vHpPBu_5gFRZnQMd_SSHsWs_duBtrHFXfpPjc_wu-aoxEqLl-HcaCFn3cRMwj2wa1MrpoDKpyzXlGQiKb4Y8afvbHTPa63wVYgNtnBlVlQVl3z1JDADTYazKS8_E0D0Kajktdnc5ezq0E8wMAS6OOBM-fOYm09_NGoEzKCb9zD3q93CnkhvCh49A2g
BUILD SUCCESSFUL
About the Oauth authentication Part
private static final List<String> SCOPES = Arrays.asList(
GmailScopes.GMAIL_READONLY);
References:
https://developers.google.com/gmail/api/v1/reference/users/messages/list
发表评论
-
Stop Update Here
2020-04-28 09:00 316I will stop update here, and mo ... -
NodeJS12 and Zlib
2020-04-01 07:44 476NodeJS12 and Zlib It works as ... -
Docker Swarm 2020(2)Docker Swarm and Portainer
2020-03-31 23:18 369Docker Swarm 2020(2)Docker Swar ... -
Docker Swarm 2020(1)Simply Install and Use Swarm
2020-03-31 07:58 370Docker Swarm 2020(1)Simply Inst ... -
Traefik 2020(1)Introduction and Installation
2020-03-29 13:52 337Traefik 2020(1)Introduction and ... -
Portainer 2020(4)Deploy Nginx and Others
2020-03-20 12:06 431Portainer 2020(4)Deploy Nginx a ... -
Private Registry 2020(1)No auth in registry Nginx AUTH for UI
2020-03-18 00:56 436Private Registry 2020(1)No auth ... -
Docker Compose 2020(1)Installation and Basic
2020-03-15 08:10 374Docker Compose 2020(1)Installat ... -
VPN Server 2020(2)Docker on CentOS in Ubuntu
2020-03-02 08:04 455VPN Server 2020(2)Docker on Cen ... -
Buffer in NodeJS 12 and NodeJS 8
2020-02-25 06:43 385Buffer in NodeJS 12 and NodeJS ... -
NodeJS ENV Similar to JENV and PyENV
2020-02-25 05:14 478NodeJS ENV Similar to JENV and ... -
Prometheus HA 2020(3)AlertManager Cluster
2020-02-24 01:47 423Prometheus HA 2020(3)AlertManag ... -
Serverless with NodeJS and TencentCloud 2020(5)CRON and Settings
2020-02-24 01:46 337Serverless with NodeJS and Tenc ... -
GraphQL 2019(3)Connect to MySQL
2020-02-24 01:48 247GraphQL 2019(3)Connect to MySQL ... -
GraphQL 2019(2)GraphQL and Deploy to Tencent Cloud
2020-02-24 01:48 451GraphQL 2019(2)GraphQL and Depl ... -
GraphQL 2019(1)Apollo Basic
2020-02-19 01:36 328GraphQL 2019(1)Apollo Basic Cl ... -
Serverless with NodeJS and TencentCloud 2020(4)Multiple Handlers and Running wit
2020-02-19 01:19 314Serverless with NodeJS and Tenc ... -
Serverless with NodeJS and TencentCloud 2020(3)Build Tree and Traverse Tree
2020-02-19 01:19 318Serverless with NodeJS and Tenc ... -
Serverless with NodeJS and TencentCloud 2020(2)Trigger SCF in SCF
2020-02-19 01:18 294Serverless with NodeJS and Tenc ... -
Serverless with NodeJS and TencentCloud 2020(1)Running with Component
2020-02-19 01:17 312Serverless with NodeJS and Tenc ...
相关推荐
**Macallan Mail Solution** 是一个综合性的邮件服务器软件,专为个人和企业用户提供高效、安全的邮件通信服务。这款软件支持多种邮件协议,包括POP3、IMAP、SMTP以及HTTP,这意味着用户可以通过传统的邮件客户端...
亲测好用,挺不错的资源,大家快来下载吧!挺有用的!需要的话可以来下载哦!网上大部分后面没有答案,这个是很全的 ...(Solution Manual)Probability and Statistics,4th Edition by Morris H. Degroot
Instructions on how to download and install the JavaMail API are contained in the course. In addition, you will need a development environment such as the JDK 1.1.6+ or the Java 2 Platform, Standard...
这一部分详细介绍了MD5、SHA-1、SHA-2等哈希算法以及相关的MAC算法,如HMAC,它们在数字签名和完整性检查中发挥关键作用。 第13章:数字签名与认证协议 数字签名提供了非对称加密的签名功能,本章探讨了其工作原理...
Macallan Mail Solution 是一款 POP3 、IMAP、SMTP、HTTP (webMail) 邮件服务器软件 ,它还包括了防垃圾邮件机制。 Macallan Mail Solution 免费邮件服务器 (SMTP/POP3/IMAP/HTTP/NEWS/SSL/Tunnel) 支持 ...
Solution to Complex Variables and Applications, 8th Edition by Brown, James; Churchill, Ruel Publisher: McGraw-Hill Higher Education Copyright Year: 2009 Course: Complex Analysis Pages: 176
3-D Surface Solution Using Structured Light and Constraint Propagation(PDF文件)一篇比较老的文献,欢迎下载。
HP Server Solution for SAP (work processes).pdf
including improvements to the Visual Studio Report Designer (SQL Server Data Tools) and Report Builder, Mobile Dashboard Designer, the new Report Portal Interface, HTML-5 Rendering, Power BI ...
THR2171 - Deploying a highly available SQL Server solution
SDAC, a high-performance and feature-rich SQL Server connectivity solution, is a complete replacement for standard SQL Server connectivity solutions and presents an efficient native alternative to the...
《概率统计》第四版是由Carnegie Mellon大学的Morris H. DeGroot和Mark Schervish所著,此书的解决方案手册是专为教师而设计的在线资源。该教材全面覆盖了概率与统计的基础理论,并以大量实例和习题帮助学生理解...
Cryptography and Network Security Principles and Practice 5th manual solution 密码编码学第五版英文答案
<Field and Wave Electromagnetics>(2ed.) Solution Manual电磁场与波第二版的答案 pdf文件共136页,34M.
5. **输入/输出系统**:讲解设备接口、中断处理和DMA(直接内存访问)在系统中的作用,以及如何实现高效的I/O操作。 6. **并行计算**:RISC-V支持向量扩展,因此解读书会讨论多核和多线程编程,以及向量处理单元...
Solution Manual Linear Systems And Signals B P Lathi
Microelectronics: Circuit Analysis and Design, 4th edition SOLUTION By D. A. Neamen
XML and JSON Recipes for SQL Server A Problem-Solution Approach 英文epub 本资源转载自网络,如有侵权,请联系上传者或csdn删除 查看此书详细信息请在美国亚马逊官网搜索此书