File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -37,10 +37,15 @@ public class EnableForwarding {
3737 * @throws IOException if service account credentials file not found.
3838 */
3939 public static AutoForwarding enableAutoForwarding (String forwardingEmail ) throws IOException {
40- // Load pre-authorized user credentials from the environment.
41- // TODO(developer) - See https://developers.google.com/identity for
42- // guides on implementing OAuth2 for your application.
43- GoogleCredentials credentials = GoogleCredentials .getApplicationDefault ().createScoped (Collections .singletonList (GmailScopes .GMAIL_SETTINGS_SHARING ));
40+ // TODO(developer) - Replace with your email address.
41+ String USER_EMAIL_ADDRESS = "gduser1@workspacesamples.dev" ;
42+
43+ /* Load pre-authorized user credentials from the environment.
44+ TODO(developer) - See https://developers.google.com/identity for
45+ guides on implementing OAuth2 for your application. */
46+ GoogleCredentials credentials = GoogleCredentials .getApplicationDefault ()
47+ .createScoped (Collections .singletonList (GmailScopes .GMAIL_SETTINGS_SHARING ))
48+ .createDelegated (USER_EMAIL_ADDRESS );
4449 HttpRequestInitializer requestInitializer = new HttpCredentialsAdapter (
4550 credentials );
4651
@@ -74,4 +79,4 @@ public static AutoForwarding enableAutoForwarding(String forwardingEmail) throws
7479 return null ;
7580 }
7681}
77- // [END gmail_enable_forwarding]
82+ // [END gmail_enable_forwarding]
Original file line number Diff line number Diff line change 1+ // Copyright 2022 Google LLC
2+ //
3+ // Licensed under the Apache License, Version 2.0 (the "License");
4+ // you may not use this file except in compliance with the License.
5+ // You may obtain a copy of the License at
6+ //
7+ // https://www.apache.org/licenses/LICENSE-2.0
8+ //
9+ // Unless required by applicable law or agreed to in writing, software
10+ // distributed under the License is distributed on an "AS IS" BASIS,
11+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+ // See the License for the specific language governing permissions and
13+ // limitations under the License.
14+
15+
16+ import com .google .api .services .gmail .model .AutoForwarding ;
17+ import org .junit .Test ;
18+ import java .io .IOException ;
19+ import static org .junit .Assert .assertNotNull ;
20+
21+ public class TestEnableForwarding extends BaseTest {
22+
23+ @ Test
24+ public void TestEnableAutoForwarding () throws IOException {
25+ AutoForwarding forwarding = EnableForwarding .enableAutoForwarding (FORWARDING_ADDRESS );
26+ assertNotNull (forwarding );
27+ forwarding = new AutoForwarding ().setEnabled (false );
28+ this .service .users ().settings ().updateAutoForwarding ("me" , forwarding ).execute ();
29+ this .service .users ().settings ().forwardingAddresses ().delete ("me" , FORWARDING_ADDRESS ).execute ();
30+ }
31+ }
You can’t perform that action at this time.
0 commit comments