- 浏览: 2551097 次
- 性别:
- 来自: 成都
文章分类
最新评论
-
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(6)Email Scan and Auth on Client
1. Does Gmail API Support Forwarding, NO
We can set up customer filter manually
https://support.google.com/mail/answer/6579?hl=en
We can use the admin SDK to set up filter for enterprise domain account with the administrator user.
https://developers.google.com/admin-sdk/email-settings/
Or we need to download the email content and send a new email ourselves.
2. Scan the Email and Download the Attachment from Client
I plan to use JavaScript. Here is the list
https://developers.google.com/api-client-library/
Here is the API for javascript.
https://developers.google.com/api-client-library/javascript/
https://developers.google.com/api-client-library/javascript/samples/samples
Gmail API JavaScript Client
https://developers.google.com/gmail/api/quickstart/js
3. Set up Env
Check the python version. Life is short, let’s use python. haha.
> python -V
Python 2.7.6
Create a very simple html file index.html
> cat index.html
Hello, Sillycat.
This will start the web server
> python -m SimpleHTTPServer 8000
We can visit the page for testing
http://localhost:8000/index.html
4. Gmail JavaScript API Implementation
<html>
<head>
<script type="text/javascript">
// Your Client ID can be retrieved from your project in the Google
// Developer Console, https://console.developers.google.com
var CLIENT_ID = ‘xxxxx';
var SCOPES = ['https://www.googleapis.com/auth/gmail.readonly'];
/**
* Check if current user has authorized this application.
*/
function checkAuth() {
gapi.auth.authorize(
{
'client_id': CLIENT_ID,
'scope': SCOPES,
'immediate': true
}, handleAuthResult);
}
/**
* Handle response from authorization server.
*
* @param {Object} authResult Authorization result.
*/
function handleAuthResult(authResult) {
var authorizeDiv = document.getElementById('authorize-div');
if (authResult && !authResult.error) {
// Hide auth UI, then load client library.
authorizeDiv.style.display = 'none';
loadGmailApi();
} else {
// Show auth UI, allowing the user to initiate authorization by
// clicking authorize button.
authorizeDiv.style.display = 'inline';
}
}
/**
* Initiate auth flow in response to user clicking authorize button.
*
* @param {Event} event Button click event.
*/
function handleAuthClick(event) {
gapi.auth.authorize(
{client_id: CLIENT_ID, scope: SCOPES, immediate: false},
handleAuthResult);
return false;
}
/**
* Load Gmail API client library. List labels once client library
* is loaded.
*/
function loadGmailApi() {
gapi.client.load('gmail', 'v1', listLabels);
gapi.client.load('gmail', 'v1', function(){
listMessages("me", "craigslist.org has:attachment larger:50K", messageQueryCallback);
});
}
function messageQueryCallback(res){
//console.log("message query response:" + JSON.stringify(res, null, 4));
gapi.client.load('gmail', 'v1', function(){
getMessage("me", “xxxxxx", getMessageCallback);
});
}
function getMessageCallback(res){
//console.log("message get response:" + JSON.stringify(res.payload.parts, null, 4));
var parts = res.payload.parts;
for(var i = 0; i < parts.length; i++){
//console.log("message get response:" + JSON.stringify(parts[i].mimeType));
var type = parts[i].mimeType;
if( type === 'application/pdf' || type === 'application/doc'){
//console.log("message get response:" + JSON.stringify(parts[i].body.attachmentId));
var attachmentId = JSON.stringify(parts[i].body.attachmentId);
console.log("attachment get response:" + attachmentId);
var attachmentId = “xxxxxxx";
gapi.client.load('gmail', 'v1', function(){
getAttachments("me", attachmentId, “xxxxxx", getAttachmentCallback);
});
}
}
}
function getAttachmentCallback(res){
//console.log("attachment get response:" + JSON.stringify(res.data, null, 4));
}
function getAttachments(userId, attachmentId, messageId, callback) {
var request = gapi.client.gmail.users.messages.attachments.get({
'id': attachmentId,
'messageId': messageId,
'userId': userId
});
request.execute(function(attachment) {
callback(attachment);
});
}
/**
* Get Message with given ID.
*
* @param {String} userId User's email address. The special value 'me'
* can be used to indicate the authenticated user.
* @param {String} messageId ID of Message to get.
* @param {Function} callback Function to call when the request is complete.
*/
function getMessage(userId, messageId, callback) {
var request = gapi.client.gmail.users.messages.get({
'userId': userId,
'id': messageId
});
request.execute(callback);
}
/**
* Retrieve Messages in user's mailbox matching query.
*
* @param {String} userId User's email address. The special value 'me'
* can be used to indicate the authenticated user.
* @param {String} query String used to filter the Messages listed.
* @param {Function} callback Function to call when the request is complete.
*/
function listMessages(userId, query, callback) {
var getPageOfMessages = function(request, result) {
request.execute(function(resp) {
result = result.concat(resp.messages);
var nextPageToken = resp.nextPageToken;
if (nextPageToken) {
request = gapi.client.gmail.users.messages.list({
'userId': userId,
'pageToken': nextPageToken,
'q': query
});
getPageOfMessages(request, result);
} else {
callback(result);
}
});
};
var initialRequest = gapi.client.gmail.users.messages.list({
'userId': userId,
'q': query
});
getPageOfMessages(initialRequest, []);
}
/**
* Print all Labels in the authorized user's inbox. If no labels
* are found an appropriate message is printed.
*/
function listLabels() {
var request = gapi.client.gmail.users.labels.list({
'userId': 'me'
});
request.execute(function(resp) {
var labels = resp.labels;
appendPre('Labels:');
if (labels && labels.length > 0) {
for (i = 0; i < labels.length; i++) {
var label = labels[i];
appendPre(label.name)
}
} else {
appendPre('No Labels found.');
}
});
}
/**
* Append a pre element to the body containing the given message
* as its text node.
*
* @param {string} message Text to be placed in pre element.
*/
function appendPre(message) {
var pre = document.getElementById('output');
var textContent = document.createTextNode(message + '\n');
pre.appendChild(textContent);
}
</script>
<script src="https://apis.google.com/js/client.js?onload=checkAuth">
</script>
</head>
<body>
<div id="authorize-div" style="display: none">
<span>Authorize access to Gmail API</span>
<!--Button for the user to click to initiate auth sequence -->
<button id="authorize-button" onclick="handleAuthClick(event)">
Authorize
</button>
</div>
<pre id="output"></pre>
</body>
</html>
References:
Mail Server Solution 1 ~ 5
http://sillycat.iteye.com/blog/2228923
http://sillycat.iteye.com/blog/2229222
http://sillycat.iteye.com/blog/2230801
http://sillycat.iteye.com/blog/2232877
http://sillycat.iteye.com/blog/2232889
http://stackoverflow.com/questions/24908700/mail-attachment-wrong-media-type-gmail-api
https://developers.google.com/gmail/api/guides/sending
https://developers.google.com/admin-sdk/email-settings/#manage_filters
https://developers.google.com/admin-sdk/email-settings/
https://developers.google.com/identity/sign-in/web/
meteor library load
http://stackoverflow.com/questions/22723300/how-do-you-include-3rd-party-javascript-libraries-in-meteor-js
https://atmospherejs.com/slava/gmail
package meteor library myself
http://www.meteorpedia.com/read/Packaging_existing_Libraries
https://github.com/MeteorCommunity/discussions/issues/14
1. Does Gmail API Support Forwarding, NO
We can set up customer filter manually
https://support.google.com/mail/answer/6579?hl=en
We can use the admin SDK to set up filter for enterprise domain account with the administrator user.
https://developers.google.com/admin-sdk/email-settings/
Or we need to download the email content and send a new email ourselves.
2. Scan the Email and Download the Attachment from Client
I plan to use JavaScript. Here is the list
https://developers.google.com/api-client-library/
Here is the API for javascript.
https://developers.google.com/api-client-library/javascript/
https://developers.google.com/api-client-library/javascript/samples/samples
Gmail API JavaScript Client
https://developers.google.com/gmail/api/quickstart/js
3. Set up Env
Check the python version. Life is short, let’s use python. haha.
> python -V
Python 2.7.6
Create a very simple html file index.html
> cat index.html
Hello, Sillycat.
This will start the web server
> python -m SimpleHTTPServer 8000
We can visit the page for testing
http://localhost:8000/index.html
4. Gmail JavaScript API Implementation
<html>
<head>
<script type="text/javascript">
// Your Client ID can be retrieved from your project in the Google
// Developer Console, https://console.developers.google.com
var CLIENT_ID = ‘xxxxx';
var SCOPES = ['https://www.googleapis.com/auth/gmail.readonly'];
/**
* Check if current user has authorized this application.
*/
function checkAuth() {
gapi.auth.authorize(
{
'client_id': CLIENT_ID,
'scope': SCOPES,
'immediate': true
}, handleAuthResult);
}
/**
* Handle response from authorization server.
*
* @param {Object} authResult Authorization result.
*/
function handleAuthResult(authResult) {
var authorizeDiv = document.getElementById('authorize-div');
if (authResult && !authResult.error) {
// Hide auth UI, then load client library.
authorizeDiv.style.display = 'none';
loadGmailApi();
} else {
// Show auth UI, allowing the user to initiate authorization by
// clicking authorize button.
authorizeDiv.style.display = 'inline';
}
}
/**
* Initiate auth flow in response to user clicking authorize button.
*
* @param {Event} event Button click event.
*/
function handleAuthClick(event) {
gapi.auth.authorize(
{client_id: CLIENT_ID, scope: SCOPES, immediate: false},
handleAuthResult);
return false;
}
/**
* Load Gmail API client library. List labels once client library
* is loaded.
*/
function loadGmailApi() {
gapi.client.load('gmail', 'v1', listLabels);
gapi.client.load('gmail', 'v1', function(){
listMessages("me", "craigslist.org has:attachment larger:50K", messageQueryCallback);
});
}
function messageQueryCallback(res){
//console.log("message query response:" + JSON.stringify(res, null, 4));
gapi.client.load('gmail', 'v1', function(){
getMessage("me", “xxxxxx", getMessageCallback);
});
}
function getMessageCallback(res){
//console.log("message get response:" + JSON.stringify(res.payload.parts, null, 4));
var parts = res.payload.parts;
for(var i = 0; i < parts.length; i++){
//console.log("message get response:" + JSON.stringify(parts[i].mimeType));
var type = parts[i].mimeType;
if( type === 'application/pdf' || type === 'application/doc'){
//console.log("message get response:" + JSON.stringify(parts[i].body.attachmentId));
var attachmentId = JSON.stringify(parts[i].body.attachmentId);
console.log("attachment get response:" + attachmentId);
var attachmentId = “xxxxxxx";
gapi.client.load('gmail', 'v1', function(){
getAttachments("me", attachmentId, “xxxxxx", getAttachmentCallback);
});
}
}
}
function getAttachmentCallback(res){
//console.log("attachment get response:" + JSON.stringify(res.data, null, 4));
}
function getAttachments(userId, attachmentId, messageId, callback) {
var request = gapi.client.gmail.users.messages.attachments.get({
'id': attachmentId,
'messageId': messageId,
'userId': userId
});
request.execute(function(attachment) {
callback(attachment);
});
}
/**
* Get Message with given ID.
*
* @param {String} userId User's email address. The special value 'me'
* can be used to indicate the authenticated user.
* @param {String} messageId ID of Message to get.
* @param {Function} callback Function to call when the request is complete.
*/
function getMessage(userId, messageId, callback) {
var request = gapi.client.gmail.users.messages.get({
'userId': userId,
'id': messageId
});
request.execute(callback);
}
/**
* Retrieve Messages in user's mailbox matching query.
*
* @param {String} userId User's email address. The special value 'me'
* can be used to indicate the authenticated user.
* @param {String} query String used to filter the Messages listed.
* @param {Function} callback Function to call when the request is complete.
*/
function listMessages(userId, query, callback) {
var getPageOfMessages = function(request, result) {
request.execute(function(resp) {
result = result.concat(resp.messages);
var nextPageToken = resp.nextPageToken;
if (nextPageToken) {
request = gapi.client.gmail.users.messages.list({
'userId': userId,
'pageToken': nextPageToken,
'q': query
});
getPageOfMessages(request, result);
} else {
callback(result);
}
});
};
var initialRequest = gapi.client.gmail.users.messages.list({
'userId': userId,
'q': query
});
getPageOfMessages(initialRequest, []);
}
/**
* Print all Labels in the authorized user's inbox. If no labels
* are found an appropriate message is printed.
*/
function listLabels() {
var request = gapi.client.gmail.users.labels.list({
'userId': 'me'
});
request.execute(function(resp) {
var labels = resp.labels;
appendPre('Labels:');
if (labels && labels.length > 0) {
for (i = 0; i < labels.length; i++) {
var label = labels[i];
appendPre(label.name)
}
} else {
appendPre('No Labels found.');
}
});
}
/**
* Append a pre element to the body containing the given message
* as its text node.
*
* @param {string} message Text to be placed in pre element.
*/
function appendPre(message) {
var pre = document.getElementById('output');
var textContent = document.createTextNode(message + '\n');
pre.appendChild(textContent);
}
</script>
<script src="https://apis.google.com/js/client.js?onload=checkAuth">
</script>
</head>
<body>
<div id="authorize-div" style="display: none">
<span>Authorize access to Gmail API</span>
<!--Button for the user to click to initiate auth sequence -->
<button id="authorize-button" onclick="handleAuthClick(event)">
Authorize
</button>
</div>
<pre id="output"></pre>
</body>
</html>
References:
Mail Server Solution 1 ~ 5
http://sillycat.iteye.com/blog/2228923
http://sillycat.iteye.com/blog/2229222
http://sillycat.iteye.com/blog/2230801
http://sillycat.iteye.com/blog/2232877
http://sillycat.iteye.com/blog/2232889
http://stackoverflow.com/questions/24908700/mail-attachment-wrong-media-type-gmail-api
https://developers.google.com/gmail/api/guides/sending
https://developers.google.com/admin-sdk/email-settings/#manage_filters
https://developers.google.com/admin-sdk/email-settings/
https://developers.google.com/identity/sign-in/web/
meteor library load
http://stackoverflow.com/questions/22723300/how-do-you-include-3rd-party-javascript-libraries-in-meteor-js
https://atmospherejs.com/slava/gmail
package meteor library myself
http://www.meteorpedia.com/read/Packaging_existing_Libraries
https://github.com/MeteorCommunity/discussions/issues/14
发表评论
-
Stop Update Here
2020-04-28 09:00 315I will stop update here, and mo ... -
NodeJS12 and Zlib
2020-04-01 07:44 475NodeJS12 and Zlib It works as ... -
Docker Swarm 2020(2)Docker Swarm and Portainer
2020-03-31 23:18 367Docker Swarm 2020(2)Docker Swar ... -
Docker Swarm 2020(1)Simply Install and Use Swarm
2020-03-31 07:58 368Docker Swarm 2020(1)Simply Inst ... -
Traefik 2020(1)Introduction and Installation
2020-03-29 13:52 335Traefik 2020(1)Introduction and ... -
Portainer 2020(4)Deploy Nginx and Others
2020-03-20 12:06 429Portainer 2020(4)Deploy Nginx a ... -
Private Registry 2020(1)No auth in registry Nginx AUTH for UI
2020-03-18 00:56 435Private Registry 2020(1)No auth ... -
Docker Compose 2020(1)Installation and Basic
2020-03-15 08:10 373Docker Compose 2020(1)Installat ... -
VPN Server 2020(2)Docker on CentOS in Ubuntu
2020-03-02 08:04 454VPN Server 2020(2)Docker on Cen ... -
Buffer in NodeJS 12 and NodeJS 8
2020-02-25 06:43 384Buffer in NodeJS 12 and NodeJS ... -
NodeJS ENV Similar to JENV and PyENV
2020-02-25 05:14 475NodeJS ENV Similar to JENV and ... -
Prometheus HA 2020(3)AlertManager Cluster
2020-02-24 01:47 421Prometheus HA 2020(3)AlertManag ... -
Serverless with NodeJS and TencentCloud 2020(5)CRON and Settings
2020-02-24 01:46 336Serverless with NodeJS and Tenc ... -
GraphQL 2019(3)Connect to MySQL
2020-02-24 01:48 246GraphQL 2019(3)Connect to MySQL ... -
GraphQL 2019(2)GraphQL and Deploy to Tencent Cloud
2020-02-24 01:48 450GraphQL 2019(2)GraphQL and Depl ... -
GraphQL 2019(1)Apollo Basic
2020-02-19 01:36 326GraphQL 2019(1)Apollo Basic Cl ... -
Serverless with NodeJS and TencentCloud 2020(4)Multiple Handlers and Running wit
2020-02-19 01:19 312Serverless with NodeJS and Tenc ... -
Serverless with NodeJS and TencentCloud 2020(3)Build Tree and Traverse Tree
2020-02-19 01:19 317Serverless with NodeJS and Tenc ... -
Serverless with NodeJS and TencentCloud 2020(2)Trigger SCF in SCF
2020-02-19 01:18 292Serverless with NodeJS and Tenc ... -
Serverless with NodeJS and TencentCloud 2020(1)Running with Component
2020-02-19 01:17 311Serverless with NodeJS and Tenc ...
相关推荐
在本文中,我们将深入探讨Laravel开发中的"laravel-auth-client",这是一个专门设计用于集成Jincor Auth服务的Artisan命令。Laravel是PHP框架中的一个流行选择,以其优雅的语法和强大的功能而受到开发者喜爱。Jincor...
【auth-client:认证客户端库】 `auth-client` 是一个专门设计用于处理认证流程的客户端库,它主要关注用户身份验证和授权的过程。这个库适用于Java开发者,尤其对那些需要在应用中集成安全认证机制的项目非常有用。...
6. **跨域兼容**:考虑到Web应用的特性,Solid Auth Client处理了跨域认证的问题,确保在不同域名下的应用间数据的无缝共享。 在使用Solid Auth Client时,开发者通常会遇到以下关键概念: - **WebID**:WebID是一...
《PyPI官网下载:middle_auth_client-3.7.0-py3-none-any.whl——深入解析Python库的安装与使用》 在Python的世界里,PyPI(Python Package Index)是全球最大的Python软件仓库,提供了丰富的第三方库资源,极大地...
标题提到的"PyPI官网下载 | middle_auth_client-1.3.0-py3-none-any.whl"意味着我们正在讨论一个可以从PyPI获取的Python库,名为`middle_auth_client`,版本号为1.3.0,它以.whl格式提供。 `.whl`文件是Python的二...
一款超强的网络监控软件,有了认证权限才能连接到网络!
自己部署使用部署示例:如何使用使用或执行以引导示例: npx create-next-app --example api-routes-apollo-server-and-client-auth api-routes-apollo-server-and-client-auth-app# oryarn create next-app --...
-u 指定单个url -l 指定url文件 先用fofa脚本爬取所有Huawei Auth-Http相关资产(fofa脚本下载地址:) python3 fofa-cwillchris.py -k body="umweb/u20.png" 然后用此脚本 ./poc.bin -l url.txt
在IT领域,邮件服务器是企业通信的...阅读`suse mailserver.docx`和`email3_manual.pdf`中的详细信息,将为您提供更深入的指导和最佳实践。在实践中不断学习和优化,您的邮件服务器将能够为企业提供可靠的邮件服务。
-- These servernames are used for both matcher/mailet processing and SMTP auth --> <!-- to determine when a mail is intended for local delivery. --> ``` #### 四、客户端配置 客户端配置主要包括设置...
**邮件服务器Courier Mail Server配置详解** Courier Mail Server是一款开源、免费的邮件服务器软件,它集成了IMAP、POP3和SMTP服务,适用于个人和小型企业使用。本篇将详细介绍如何配置Courier Mail Server,以...
6. `src`或`django_rest_email_auth`目录:包含实际的源代码,可能有`models.py`(数据模型)、`views.py`(视图函数)、`serializers.py`(序列化器)、`permissions.py`(权限控制)等文件,实现了RESTful API与...
rsync error: error starting client-server protocol (code 5) at main.c(1516) [Receiver=3.0.9] rsync服务器配置如下 [root@localhost ~]# cat /etc/rsyncd.conf # /etc/rsyncd: configuration
二、@ERROR: auth failed on module(rsync error: error starting client-server protocol (code 5)) 这种错误的原因是服务器端的模块需要验证用户名密码,但是客户端没有提供正确的用户名密码,认证失败。解决方法...
Office Online Server 2016 中文版详细安装步骤 Office Online Server 2016 中文版是 Microsoft 公司推出的在线办公服务器解决方案,旨在提供一站式的办公体验。以下是 Office Online Server 2016 中文版的详细安装...
3A客户端, Auth Client 2.0.5 用于校园网络登录,
远程控制编码技术是一种在计算机网络中实现一台设备(通常称为客户端或client)对另一台设备(服务器或server)进行操作的技术。这种技术广泛应用于系统管理、技术支持、远程协作以及自动化任务执行等领域。在这个...