0

so i am building an application that is supposed to send an automated email and i'm a little lost. i've been doing some research and i just don't really understand exactly what i am doing so i'm having trouble figuring out the details. on one page i found a method that seemed like it would be what i need but the example given used '*' instead of actual value for a variable called code. here is an example of the code i am writing containing the variable:

public static Gmail init() throws IOException{
    HttpTransport httpTransport = new NetHttpTransport();
    JsonFactory jsonFactory = new JacksonFactory();

    sClientSecrets = GoogleClientSecrets.load(jsonFactory, mClientSecretReader);
    Log.d(TAG, "Client Secrets: " + sClientSecrets);

    GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
            httpTransport,
            jsonFactory,
            sClientSecrets,
            Arrays.asList(mScope)
    ).setAccessType("online").setApprovalPrompt("auto").build();

    String code = "***"; // <-----how do i get code?
    GoogleTokenResponse response = flow.newTokenRequest(code)
            .setRedirectUri(GoogleOAuthConstants.OOB_REDIRECT_URI).execute();
    GoogleCredential credential = new GoogleCredential()
            .setFromTokenResponse(response);

    return new Gmail.Builder(httpTransport, jsonFactory, credential)
            .setApplicationName(APP_NAME).build();

}//end init()

i do not understand what i am supposed to use for this variable. i feel that i should know but... i don't. please point this out to me. thanks in advance.

Mox_z
  • 501
  • 7
  • 30
  • You get the code from the user, he will get it after logging in from a URL you will generate using flow.newAuthorizationUrl(). See [here](https://github.com/google/mail-importer/blob/master/src/main/java/to/lean/tools/gmail/importer/gmail/Authorizer.java) for an example. – Oleg Aug 01 '17 at 05:12
  • @Oleg perhaps I'm going down the wrong path then. All I want to do is send an email. I could even have one dedicated address account to send this email from. Could you point me in the right direction? – Mox_z Aug 01 '17 at 05:20
  • You can see several options [here](https://stackoverflow.com/questions/6264698/how-can-i-send-an-email-from-android-application-directly-without-showing-the-de) , and yes OAuth is rather complicated and if all you want is to send an email you definitely don't want to deal with it. – Oleg Aug 01 '17 at 05:40

0 Answers0