Gal Dak
Gal Dak

Reputation: 25

Send a mail through an android app

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[]{"[email protected]"};
        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"));
    }

Upvotes: 1

Views: 4577

Answers (3)

Vaibhav Purohit
Vaibhav Purohit

Reputation: 13

Use this method....

public void sendEmail()
{

Intent intent = new Intent(Intent.ACTION_SEND);

intent.setType("message/rfc822");

 intent.putExtra(Intent.EXTRA_EMAIL, new String[]{"[email protected]"});

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

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

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

}

Upvotes: 0

O_o
O_o

Reputation: 1103

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

Cheers!

Upvotes: 2

dipali
dipali

Reputation: 11188

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.

Upvotes: 0

Related Questions