Reputation: 1122
I am creating an android application.in which it has a feedback form. Now, as the user clicks on "Submit Comments" button, this should send all the details to my email address, all the details that user entered in the form. I've seen so many examples and questions here, but didn't get proper answer. I don't know how to do it. I am new in android. Please help me.
Upvotes: 1
Views: 3085
Reputation: 371
For sending email, you will have to use the inbuilt/installed email clients/apps which have been configured with a correct email account. There is no API in android for sending mail. Sending receiving emails uses protocols which has been implemented by the email apps. Implementing that in your app would make it very complex.
Better option for you would be call a web service and pass the data to the server and store it in DB. If you really want to send email, then send the received data at the server as email. Depending on the server you are using, you will be able to find connectors for emails.
Upvotes: 0
Reputation: 3110
Intent email = new Intent(Intent.ACTION_SEND);
email.putExtra(Intent.EXTRA_EMAIL, new String[]{ to});
//email.putExtra(Intent.EXTRA_CC, new String[]{ to});
//email.putExtra(Intent.EXTRA_BCC, new String[]{to});
email.putExtra(Intent.EXTRA_SUBJECT, "subject");
email.putExtra(Intent.EXTRA_TEXT, "message");
//need this to prompts email client only
email.setType("message/rfc822");
startActivity(Intent.createChooser(email, "Choose an Email client :"));
}
Upvotes: 0
Reputation: 7376
You can try this on your send button click event:
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("message/rfc822");
i.putExtra(Intent.EXTRA_EMAIL , new String[]{"[email protected]"});
i.putExtra(Intent.EXTRA_SUBJECT, "title");
i.putExtra(Intent.EXTRA_TEXT, message);//message is your details
try {
startActivity(Intent.createChooser(i, "Send mail..."));
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(about.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
}
Upvotes: 2
Reputation: 1556
Try this on Submit Button:
Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(
"mailto","[email protected]", null));
intent.putExtra(Intent.EXTRA_SUBJECT, subject);
intent.putExtra(Intent.EXTRA_TEXT, message);
startActivity(Intent.createChooser(intent, "Choose an Email client :"));
If you don't have a specific recipient - go like this:
Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(
"mailto",null, null));
Upvotes: 0