private void nova_senha(HttpServletRequest request, HttpServletResponse response) throws XolerDAOException, IOException { String email = request.getParameter("email"); SendGrid sendgrid = new SendGrid("*****@*****.**", "3teptep3!"); SendGrid.Email sendgrid_email = new Email(); sendgrid_email.addTo(email); sendgrid_email.setFrom("*****@*****.**"); sendgrid_email.setSubject("Nova Senha"); DAOUsuario user = new DAOUsuario(true); int hash = email.hashCode(); String novasenha = Integer.toString(Math.abs(hash)); System.out.println("novasenha"); System.out.println(novasenha); user.nova_senha(email, novasenha); sendgrid_email.setText("Sua nova senha no Drogaria.me é: " + novasenha); try { SendGrid.Response response_sendgrid = sendgrid.send(sendgrid_email); System.out.println(response_sendgrid.getMessage()); } catch (SendGridException e) { System.err.println(e); } response.sendRedirect("index.jsp"); }
@Override protected Void doInBackground(Void... params) { try { // SendGrid sendgrid = new SendGrid(SENDGRID_USERNAME, SENDGRID_PASSWORD); SendGrid sendgrid = new SendGrid(SENDGRID_APIKEY); SendGrid.Email email = new SendGrid.Email(); // Get values from edit text to compose email // TODO: Validate edit texts email.addTo(toEditText.getText().toString()); email.setFrom(fromEditText.getText().toString()); email.setSubject(subjectEditText.getText().toString()); email.setText(msgEditText.getText().toString()); // Attach image if (selectedAudioURI != null) { email.addAttachment( attachmentName, getContentResolver().openInputStream(selectedAudioURI)); } // Send email, execute http request SendGrid.Response response = sendgrid.send(email); msgResponse = response.getMessage(); Log.d("SendAppExample", msgResponse); } catch (SendGridException e) { Log.e("SendAppExample", e.toString()); } catch (JSONException e) { Log.e("SendAppExample", e.toString()); } catch (IOException e) { Log.e("SendAppExample", e.toString()); } return null; }