Send E-mail by pressing a button

Asked

Viewed 84 times

0

I’m making an application that consists of, by pressing a button a programmed email is sent automatically without I have to enter gmail to press "send"

Until then I built this code and it’s doing everything but send without I have to go to gmail

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    button = findViewById(R.id.button);
    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            try {
                Intent email = new Intent(Intent.ACTION_SEND);

                email.setData(Uri.parse("mailto"));
                email.setType("message/rfc822");
                email.putExtra(Intent.EXTRA_EMAIL,
                        new String[]{"[email protected]"});
                email.putExtra(Intent.EXTRA_SUBJECT,
                        "Assunto do email ");
                email.putExtra(Intent.EXTRA_TEXT, "mensagem que quero enviar ");
                //startActivity(email);
                email.putExtra(Intent.ACTION_SEND, email);
            }catch (Exception e){
                e.printStackTrace();
                Toast.makeText(MainActivity.this, e.getMessage().toString(), Toast.LENGTH_SHORT).show();
            }
        }
    });
}

what I should add for him to send without having to enter the email

  • By using Intent, you are asking the system to send email, to you send the email programmatically you can use this tutorial

  • https://www.devmedia.com.br/enviando-email-com-javamail-utilizando-gmail/18034

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.