GMAIL API:forward all the client gmail messages to a gmail address by using gmail api
up vote
1
down vote
favorite
Currently, I am writing a program to forward all the Gmail messages of users to a Gmail address
I took the help from:Link
I created all the storage, credentials file etc
but when I try to run the program it's giving an error:
Traceback (most recent call last):
File "hh.py", line 40, in <module>
thadari()
File "hh.py", line 30, in thadari
result = GMAIL.users().settings().forwardingAddresses().create(userId='me', body=address).execute()
File "/home/vishalthadari/Documents/Seperation 1/virutalenv/python 3/env/lib/python3.6/site-packages/googleapiclient/_helpers.py", line 130, in positional_wrapper
return wrapped(*args, **kwargs)
File "/home/vishalthadari/Documents/Seperation 1/virutalenv/python 3/env/lib/python3.6/site-packages/googleapiclient/http.py", line 842, in execute
raise HttpError(resp, content, uri=self.uri)
googleapiclient.errors.HttpError: <HttpError 403 when requesting https://www.googleapis.com/gmail/v1/users/me/settings/forwardingAddresses?alt=json returned "Insufficient Permission">
i already gave the sending mail permission to it but I don't know why it's giving the error.there's no scope for forward message as I read here:link
Or do I need to buy google gsuite for this? which is defined here:Link
in gmail.settings.sharing
I know that whole wall of code is not reusable but as I am new to Google API's so I think their's small minor bugs in my code:
from apiclient import discovery
from apiclient import errors
from httplib2 import Http
from oauth2client import file, client, tools
import base64
from bs4 import BeautifulSoup
import re
import time
import dateutil.parser as parser
from datetime import datetime
import datetime
import csv
def thadari():
SCOPES = 'https://www.googleapis.com/auth/gmail.send'
store = file.Storage('storage.json')
creds = store.get()
if not creds or creds.invalid:
flow = client.flow_from_clientsecrets('client_secret.json', SCOPES)
creds = tools.run_flow(flow, store)
GMAIL = discovery.build('gmail', 'v1', http=creds.authorize(Http()))
user_id = 'me'
label_id_one = 'INBOX'
address = {'forwardingEmail': 'girlsdontloveme75@gmail.com'}
result = GMAIL.users().settings().forwardingAddresses().create(userId='me', body=address).execute()
if result.get('verificationStatus') == 'accepted':
body = {
'emailAddress': result.get('forwardingEmail'),
'enabled': True,
'disposition': 'trash'
}
if __name__ == '__main__':
thadari()
Is this the right way to do it? or there's a better way to do this please help me
Thanks in advance
python oauth-2.0 google-api gmail gmail-api
add a comment |
up vote
1
down vote
favorite
Currently, I am writing a program to forward all the Gmail messages of users to a Gmail address
I took the help from:Link
I created all the storage, credentials file etc
but when I try to run the program it's giving an error:
Traceback (most recent call last):
File "hh.py", line 40, in <module>
thadari()
File "hh.py", line 30, in thadari
result = GMAIL.users().settings().forwardingAddresses().create(userId='me', body=address).execute()
File "/home/vishalthadari/Documents/Seperation 1/virutalenv/python 3/env/lib/python3.6/site-packages/googleapiclient/_helpers.py", line 130, in positional_wrapper
return wrapped(*args, **kwargs)
File "/home/vishalthadari/Documents/Seperation 1/virutalenv/python 3/env/lib/python3.6/site-packages/googleapiclient/http.py", line 842, in execute
raise HttpError(resp, content, uri=self.uri)
googleapiclient.errors.HttpError: <HttpError 403 when requesting https://www.googleapis.com/gmail/v1/users/me/settings/forwardingAddresses?alt=json returned "Insufficient Permission">
i already gave the sending mail permission to it but I don't know why it's giving the error.there's no scope for forward message as I read here:link
Or do I need to buy google gsuite for this? which is defined here:Link
in gmail.settings.sharing
I know that whole wall of code is not reusable but as I am new to Google API's so I think their's small minor bugs in my code:
from apiclient import discovery
from apiclient import errors
from httplib2 import Http
from oauth2client import file, client, tools
import base64
from bs4 import BeautifulSoup
import re
import time
import dateutil.parser as parser
from datetime import datetime
import datetime
import csv
def thadari():
SCOPES = 'https://www.googleapis.com/auth/gmail.send'
store = file.Storage('storage.json')
creds = store.get()
if not creds or creds.invalid:
flow = client.flow_from_clientsecrets('client_secret.json', SCOPES)
creds = tools.run_flow(flow, store)
GMAIL = discovery.build('gmail', 'v1', http=creds.authorize(Http()))
user_id = 'me'
label_id_one = 'INBOX'
address = {'forwardingEmail': 'girlsdontloveme75@gmail.com'}
result = GMAIL.users().settings().forwardingAddresses().create(userId='me', body=address).execute()
if result.get('verificationStatus') == 'accepted':
body = {
'emailAddress': result.get('forwardingEmail'),
'enabled': True,
'disposition': 'trash'
}
if __name__ == '__main__':
thadari()
Is this the right way to do it? or there's a better way to do this please help me
Thanks in advance
python oauth-2.0 google-api gmail gmail-api
Have you followed the initial step (creating a forwarding email address)?
– Mr.Rebot
Nov 12 at 6:35
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
Currently, I am writing a program to forward all the Gmail messages of users to a Gmail address
I took the help from:Link
I created all the storage, credentials file etc
but when I try to run the program it's giving an error:
Traceback (most recent call last):
File "hh.py", line 40, in <module>
thadari()
File "hh.py", line 30, in thadari
result = GMAIL.users().settings().forwardingAddresses().create(userId='me', body=address).execute()
File "/home/vishalthadari/Documents/Seperation 1/virutalenv/python 3/env/lib/python3.6/site-packages/googleapiclient/_helpers.py", line 130, in positional_wrapper
return wrapped(*args, **kwargs)
File "/home/vishalthadari/Documents/Seperation 1/virutalenv/python 3/env/lib/python3.6/site-packages/googleapiclient/http.py", line 842, in execute
raise HttpError(resp, content, uri=self.uri)
googleapiclient.errors.HttpError: <HttpError 403 when requesting https://www.googleapis.com/gmail/v1/users/me/settings/forwardingAddresses?alt=json returned "Insufficient Permission">
i already gave the sending mail permission to it but I don't know why it's giving the error.there's no scope for forward message as I read here:link
Or do I need to buy google gsuite for this? which is defined here:Link
in gmail.settings.sharing
I know that whole wall of code is not reusable but as I am new to Google API's so I think their's small minor bugs in my code:
from apiclient import discovery
from apiclient import errors
from httplib2 import Http
from oauth2client import file, client, tools
import base64
from bs4 import BeautifulSoup
import re
import time
import dateutil.parser as parser
from datetime import datetime
import datetime
import csv
def thadari():
SCOPES = 'https://www.googleapis.com/auth/gmail.send'
store = file.Storage('storage.json')
creds = store.get()
if not creds or creds.invalid:
flow = client.flow_from_clientsecrets('client_secret.json', SCOPES)
creds = tools.run_flow(flow, store)
GMAIL = discovery.build('gmail', 'v1', http=creds.authorize(Http()))
user_id = 'me'
label_id_one = 'INBOX'
address = {'forwardingEmail': 'girlsdontloveme75@gmail.com'}
result = GMAIL.users().settings().forwardingAddresses().create(userId='me', body=address).execute()
if result.get('verificationStatus') == 'accepted':
body = {
'emailAddress': result.get('forwardingEmail'),
'enabled': True,
'disposition': 'trash'
}
if __name__ == '__main__':
thadari()
Is this the right way to do it? or there's a better way to do this please help me
Thanks in advance
python oauth-2.0 google-api gmail gmail-api
Currently, I am writing a program to forward all the Gmail messages of users to a Gmail address
I took the help from:Link
I created all the storage, credentials file etc
but when I try to run the program it's giving an error:
Traceback (most recent call last):
File "hh.py", line 40, in <module>
thadari()
File "hh.py", line 30, in thadari
result = GMAIL.users().settings().forwardingAddresses().create(userId='me', body=address).execute()
File "/home/vishalthadari/Documents/Seperation 1/virutalenv/python 3/env/lib/python3.6/site-packages/googleapiclient/_helpers.py", line 130, in positional_wrapper
return wrapped(*args, **kwargs)
File "/home/vishalthadari/Documents/Seperation 1/virutalenv/python 3/env/lib/python3.6/site-packages/googleapiclient/http.py", line 842, in execute
raise HttpError(resp, content, uri=self.uri)
googleapiclient.errors.HttpError: <HttpError 403 when requesting https://www.googleapis.com/gmail/v1/users/me/settings/forwardingAddresses?alt=json returned "Insufficient Permission">
i already gave the sending mail permission to it but I don't know why it's giving the error.there's no scope for forward message as I read here:link
Or do I need to buy google gsuite for this? which is defined here:Link
in gmail.settings.sharing
I know that whole wall of code is not reusable but as I am new to Google API's so I think their's small minor bugs in my code:
from apiclient import discovery
from apiclient import errors
from httplib2 import Http
from oauth2client import file, client, tools
import base64
from bs4 import BeautifulSoup
import re
import time
import dateutil.parser as parser
from datetime import datetime
import datetime
import csv
def thadari():
SCOPES = 'https://www.googleapis.com/auth/gmail.send'
store = file.Storage('storage.json')
creds = store.get()
if not creds or creds.invalid:
flow = client.flow_from_clientsecrets('client_secret.json', SCOPES)
creds = tools.run_flow(flow, store)
GMAIL = discovery.build('gmail', 'v1', http=creds.authorize(Http()))
user_id = 'me'
label_id_one = 'INBOX'
address = {'forwardingEmail': 'girlsdontloveme75@gmail.com'}
result = GMAIL.users().settings().forwardingAddresses().create(userId='me', body=address).execute()
if result.get('verificationStatus') == 'accepted':
body = {
'emailAddress': result.get('forwardingEmail'),
'enabled': True,
'disposition': 'trash'
}
if __name__ == '__main__':
thadari()
Is this the right way to do it? or there's a better way to do this please help me
Thanks in advance
python oauth-2.0 google-api gmail gmail-api
python oauth-2.0 google-api gmail gmail-api
edited Nov 10 at 10:44
lgwilliams
505317
505317
asked Nov 10 at 10:34
user10538706
42
42
Have you followed the initial step (creating a forwarding email address)?
– Mr.Rebot
Nov 12 at 6:35
add a comment |
Have you followed the initial step (creating a forwarding email address)?
– Mr.Rebot
Nov 12 at 6:35
Have you followed the initial step (creating a forwarding email address)?
– Mr.Rebot
Nov 12 at 6:35
Have you followed the initial step (creating a forwarding email address)?
– Mr.Rebot
Nov 12 at 6:35
add a comment |
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53238081%2fgmail-apiforward-all-the-client-gmail-messages-to-a-gmail-address-by-using-gmai%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53238081%2fgmail-apiforward-all-the-client-gmail-messages-to-a-gmail-address-by-using-gmai%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Have you followed the initial step (creating a forwarding email address)?
– Mr.Rebot
Nov 12 at 6:35