move all messages from inbox to new label in gmail using gam

548 views
Skip to first unread message

Rajagopal Suresh

unread,
Jul 16, 2021, 9:54:05 AM7/16/21
to GAM for Google Workspace
Hi, 

I am looking gam commands to move emails from Inbox to particular lable then arhive from the inbox.


Tried with the below commands but getting below error as "ERROR: 400: Invalid label name - invalidArgument"

Syntax:-

gam user x...@email.com modify messages query to:sx...@email.com in:inbox " addlabel "ToMe" removelabel "Inbox" maxtomodify 1000000 doit

Please help me to get the correct syntax to solve my issue.

Ross Scroggs

unread,
Jul 17, 2021, 9:21:47 AM7/17/21
to google-ap...@googlegroups.com
What is your Gam version?

You must create the ToMe label before running the command.

Ross
On Jul 16, 2021, at 6:54 AM, Rajagopal Suresh <sures...@gmail.com> wrote:

Hi, 

I am looking gam commands to move emails from Inbox to particular lable then arhive from the inbox.


Tried with the below commands but getting below error as "ERROR: 400: Invalid label name - invalidArgument"

Syntax:-

gam user x...@email.com modify messages query to:sxxx@email.com in:inbox " addlabel "ToMe" removelabel "Inbox" maxtomodify 1000000 doit

Please help me to get the correct syntax to solve my issue.

--
You received this message because you are subscribed to the Google Groups "GAM for Google Workspace" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-man...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-manager/d370297b-1031-4189-b156-01292bb43573n%40googlegroups.com.

Rajagopal Suresh

unread,
Jul 18, 2021, 7:20:47 AM7/18/21
to GAM for Google Workspace
Hi,

Thanks for your response.

GAM version is 6.06.

I have created the label before executed this command but still getting the same error.

Ross Scroggs

unread,
Jul 18, 2021, 9:10:57 AM7/18/21
to google-ap...@googlegroups.com
It's a coding issue, change your command slightly; Inbox should be INBOX in removelabel

gam user x...@email.com modify messages query "to:sxxx@email.com in:inbox" addlabel "ToMe" removelabel "INBOX" maxtomodify 1000000 doit

Rajagopal Suresh

unread,
Jul 19, 2021, 1:13:28 AM7/19/21
to GAM for Google Workspace
Hi,

Thank you so much!!!!. 
It is working now after being changed with INBOX.

Rajagopal Suresh

unread,
Jul 22, 2021, 7:44:10 AM7/22/21
to GAM for Google Workspace
Hi,

Could you please guide me on how to create a batch file to run gam commands for bulk users with below syntax.

gam user x...@email.com modify messages query to:sx...@email.com in:inbox " addlabel "ToMe" removelabel "INBOX" maxtomodify 1000000 doit


Ross Scroggs

unread,
Jul 22, 2021, 1:38:39 PM7/22/21
to google-ap...@googlegroups.com
Rajagopal,

In your example you show two slightly different email addresses; are they supposed to be the same?
gam user x...@email.com modify messages query to:sx...@email.com in:inbox " addlabel "ToMe" removelabel "INBOX" maxtomodify 1000000 doit

If not, make a two column CSV file UserTo.csv
userEmail,toEmail
...

gam csv UserTo.csv gam user "~userEmail" modify messages query "to:~~toEmail~~ in:inbox" addlabel "ToMe" removelabel "INBOX" maxtomodify 1000000 doit

If they are actually the same, make a one column CSV file User.csv
userEmail
...

gam csv User.csv gam user "~userEmail" modify messages query "to:~~userEmail~~ in:inbox" addlabel "ToMe" removelabel "INBOX" maxtomodify 1000000 doit

Ross






--

Rajagopal Suresh

unread,
Jul 25, 2021, 2:20:10 AM7/25/21
to GAM for Google Workspace
Hi Ross,

Thanks for your great help. Request you suggest for below error.

I have tried the below suggestion and getting an error as "Error: 409: Lable name exist or conflicts - aborted".

Only getting errors if I mention the label name which is already available in my email account.
The below syntax is working fine if I mention the label which does not exist already in the email account. 

Please guide me on how can i mention different label names like "userEmail", "toEmail" if i want to run gam for more users with different labels.


gam user x...@email.com modify messages query to:sx...@email.com in:inbox " addlabel "ToMe" removelabel "INBOX" maxtomodify 1000000 doit
two column CSV file UserTo.csv
userEmail,toEmail
Reply all
Reply to author
Forward
0 new messages