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










share|improve this question























  • Have you followed the initial step (creating a forwarding email address)?
    – Mr.Rebot
    yesterday














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










share|improve this question























  • Have you followed the initial step (creating a forwarding email address)?
    – Mr.Rebot
    yesterday












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










share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 10 at 10:44









lgwilliams

129211




129211










asked Nov 10 at 10:34









user10538706

62




62











  • Have you followed the initial step (creating a forwarding email address)?
    – Mr.Rebot
    yesterday
















  • Have you followed the initial step (creating a forwarding email address)?
    – Mr.Rebot
    yesterday















Have you followed the initial step (creating a forwarding email address)?
– Mr.Rebot
yesterday




Have you followed the initial step (creating a forwarding email address)?
– Mr.Rebot
yesterday

















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
);



);













 

draft saved


draft discarded


















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



































active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes















 

draft saved


draft discarded















































 


draft saved


draft discarded














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














































































Popular posts from this blog

27

Top Tejano songwriter Luis Silva dead of heart attack at 64

Category:Rhetoric