0

i am currently on my app trying to invite people to join as a guest to test the app out. The user will input the email address of the guest and they should receive an email to join as a guest. For some reason, the user doesn't receive an email.

Very new to programming and android studio, so can someone please help me. I have put an image of the xml to show you how it looks.

enter image description here

public class ClientInfo extends AsyncTask<Void, Void, Void> {
    private static final String TAG = "ClientInfo";
    private static final String url = "https://"+ BuildConfig.PORTAL_HOSTNAME+"/api3/im/%s/invite";

    private final String emailaddress;
    private final Context context;
    private final String deviceId;

    public ClientInfo(Context context, String emailaddress) {
        this.deviceId = SaltIMApplication.getDeviceId(context);
        this.emailaddress = emailaddress;
        this.context = context;
    }

    protected String readResponse(HttpPost post) throws Exception {
        return Utils.readResponse(Utils.getHttpClient().execute(post));
    }

    protected Void doInBackground(Void... voids) {
        Log.i(TAG, "Invite ---- Send invite");
        String path = String.format(url, this.deviceId);
        String response = "";
        Log.i(TAG, "Invite ---- Path is:" + path);

        try {
            Log.i(TAG, "Invite ---- Post is: " + (Utils.createJsonPost(path, createBody())).toString());
            response = readResponse(Utils.createJsonPost(path, createBody()));
        } catch (Exception e) {
            Log.i(TAG, "Invite ---- Response from the invite - " + e.getMessage());
        }
        if (!response.equals("")) {
            try {
                JSONObject jsonObject = new JSONObject(response);
                String s = jsonObject.toString();
                Log.i(TAG, "Invite ---- Response: " + s);
            } catch (JSONException e) {
                Log.i(TAG, "Invite ---- Response: JSONException");
                e.printStackTrace();
            }
        }
        return null;
    }

    private StringEntity createBody() throws JSONException, UnsupportedEncodingException {


        JSONObject jsonRequest = new JSONObject();
        jsonRequest.put("email", emailaddress);
        jsonRequest.put("secret", BuildConfig.SHARED_SECRET);

        Log.i(TAG, "Invite ---- JsonObject is: " +jsonRequest);
        Log.i(TAG, "Invite ---- Sending invite");
        return new StringEntity(jsonRequest.toString());
    }
}

Here is my activity

public class ClientInviteActivity extends AppCompatActivity {
    private static final String TAG = "ClientInviteActivity";

    @InjectView(R.id.enterEmail)
    EditText emailEntry;
    @InjectView(R.id.inviteButton)
    ImageButton inviteButton;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.client_invite);
        ButterKnife.inject(this);
        getSupportActionBar().setHomeButtonEnabled(true);
        getSupportActionBar().setTitle("Guest Invite");
    }

    @OnClick(R.id.inviteButton)

    public void onClick(){
        Log.i(TAG, "Invite - we are going to send an invite to " + emailEntry.getText().toString());
        String email = emailEntry.getText().toString();
        ClientInfo clientInfo = new ClientInfo(this, email);
        clientInfo.execute();

    }
}
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
A.Samad
  • 13
  • 6
  • Nowhere in the code in the question does an email get sent. Please edit your question to include more code – OneCricketeer Mar 18 '16 at 11:39
  • Still missing some code.... As far as I can tell, you are sending POST requests. That is completely different than sending email. You need a POP3 or IMAP server to do that – OneCricketeer Mar 18 '16 at 12:56
  • okay thank you! it seems to be going through okay ,as the invite was successful but the guest doesn't seem to receive an email – A.Samad Mar 18 '16 at 13:13
  • Sure, your Android code could work just fine. The problem is your API may not actually be sending an when it gera a request. As I said,that's the code you are missing in this question. What is `https://"+ BuildConfig.PORTAL_HOSTNAME+"/api3/im/%s/invite`? Is it your server, or some third party API? – OneCricketeer Mar 18 '16 at 13:19
  • that is the url page to where the guest can use the vertification code to invite themselves as a guest – A.Samad Mar 18 '16 at 13:23
  • Okay, sure. But where do you actually **send** an invitation email? – OneCricketeer Mar 18 '16 at 13:25
  • hm okay, i see where your coming from now. Just very new to programming, still learning – A.Samad Mar 18 '16 at 14:47
  • Maybe you should see how to [send an email in Java](http://stackoverflow.com/questions/3649014/send-email-using-java) or do the same in your web server code. – OneCricketeer Mar 18 '16 at 15:15
  • Okay, thank you very much for your help – A.Samad Mar 18 '16 at 15:23

0 Answers0