1

I've implemented a class that can send a mail. However, you can only write a topic and the message and when you click on "Send" you've to choose which app (Outlook or Gmail) you want to send the mail with and then write your e-mail. However, I want to make it possible for the user to send a mail directly from the my app instead of using another app. So I want to make it possible for the user to write his/her e-mail/gmail and message and then send the message to my e-mail. So in other words in the fragment I want an EditText where the user writes his/her e-mail/gmail, another EditText where the user writes the message and a button to send. How can this be implemented?

This is what I have done in my app to send a mail:

   private void sendemail(String message) {
        String [] reciever = new String[]{"myemail@hotmail.com"};
        String subject = ("Feedback/Question");
        Intent mailIntent = new Intent(Intent.ACTION_SEND);
        mailIntent.putExtra(Intent.EXTRA_EMAIL, reciever);
        mailIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
        mailIntent.putExtra(Intent.EXTRA_TEXT, message);
        mailIntent.setType("message/rfc822");
        startActivity(Intent.createChooser(mailIntent, "Choose an application to send your mail with"));
    }
Gal Dak
  • 15
  • 1
  • 6

3 Answers3

2

Use this library -> Send email in background. It will send an email from your app without users interaction.

Cheers!

O_o
  • 1,103
  • 11
  • 36
  • It seems to me that the user needs to sign in with a Gmail account and then send the mail? What about hotmail? Isn't possible to make it send without signing in? – Gal Dak Oct 04 '16 at 12:43
0

using java mailApi,you must have to authenticate gmail app using credential. please check this link:

Email via Java MailAPI

other link to provide custom class to send mail programatically.

https://stackoverflow.com/a/4345084/1223291

I hope its useful to you.

Community
  • 1
  • 1
dipali
  • 10,966
  • 5
  • 25
  • 51
  • As I understand, the user needs to write his/her password in order to send a mail. Does this also support hotmail/live ? – Gal Dak Oct 04 '16 at 12:35
  • may be.i have not implemented it.so not clearly .but may be its work.othewise 2nd option is best. – dipali Oct 04 '16 at 12:37
0

Use this method....

public void sendEmail()
{

Intent intent = new Intent(Intent.ACTION_SEND);

intent.setType("message/rfc822");

 intent.putExtra(Intent.EXTRA_EMAIL, new String[]{"care@xyz.com"});

intent.putExtra(Intent.EXTRA_SUBJECT, "care Feedback");

intent.putExtra(Intent.EXTRA_TEXT, "");

startActivity(Intent.createChooser(intent, "Send Email"));

}