Advertisement
urksiful

Send Mail

Jul 25th, 2018
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.96 KB | None | 0 0
  1. package pro.izcali.apptojoc.listenersNotificationsFirebase;
  2.  
  3. import android.os.AsyncTask;
  4. import android.util.Log;
  5.  
  6. import org.json.JSONObject;
  7.  
  8. import okhttp3.MediaType;
  9. import okhttp3.OkHttpClient;
  10. import okhttp3.Request;
  11. import okhttp3.RequestBody;
  12. import okhttp3.Response;
  13.  
  14. public class SendMail {
  15.  
  16.     public static void sendMailTo(String descripcion, String tipo_usuario, String asunto, String from, String to) {
  17.      //   Log.d(TAG, "sendNotification: TOKEN "+regToken);
  18.  
  19.         final String descripcion_f = descripcion;
  20.         final String tipo_usuario_f = tipo_usuario;
  21.         final String asunto_f = asunto;
  22.         final String from_f = from;
  23.         final String to_f = to;
  24.  
  25.         final MediaType JSON
  26.                 = MediaType.parse("application/json; charset=utf-8");
  27.  
  28.         new AsyncTask<Void,Void,Void>(){
  29.             @Override
  30.             protected Void doInBackground(Void... params) {
  31.                 try {
  32.                     OkHttpClient client = new OkHttpClient();
  33.                     JSONObject json=new JSONObject();
  34.                    
  35.  
  36.                     json.put("descripcion",descripcion_f);
  37.                     json.put("usuario",tipo_usuario_f);
  38.                     json.put("asunto", asunto_f);
  39.                     json.put("from", from_f);
  40.                     json.put("to", to_f);
  41.  
  42.                     RequestBody body = RequestBody.create(JSON, json.toString());
  43.                     Request request = new Request.Builder()
  44.                             .url("https://apptojo.izcali.pro/api/v1/mail/send_mail.php?")
  45.                             .post(body)
  46.                             .build();
  47.                     Response response = client.newCall(request).execute();
  48.                     String finalResponse = response.body().string();
  49.                 }catch (Exception e){
  50.                     //Log.d(TAG,e+"");
  51.                 }
  52.                 return null;
  53.             }
  54.         }.execute();
  55.  
  56.  
  57.  
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement