I am building an android application where an user is required to lo-gin using g+ to enter in the app. After lo-gin there is 3 EditTextView where user enter required data respect to their field to send mail. the field like - recipient mail Id, subject, and body.
Now the problem is How to send the mail to that recipient ID. using my app.
Here you go:
https://stackoverflow.com/a/2197841/3498044
https://stackoverflow.com/a/6264746/3498044
Next time search before you ask
Try with Following
private String[] recipients = {"abc#gmail.com"};
private String type = "text/html";
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_EMAIL, recipients);
intent.putExtra(Intent.EXTRA_SUBJECT, "Subject");
intent.putExtra(Intent.EXTRA_TEXT, "text");
intent.setType(type);
startActivity(Intent.createChooser(intent, "Send mail"));
Related
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"));
}
Use this library -> Send email in background. It will send an email from your app without users interaction.
Cheers!
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.
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"));
}
How can I create a simple program that it can send a text to a gmail address?
I want to create a simple program that it have a EditText and when I write some text in the EditText and I click on the Button, as the result the text be sent to a gmail address, for example to the example#gmail.com. I know how to create a EditText class but I do not know the operation post to the gmail. Thank you.
In Android, you can use Intent.ACTION_SEND to call an existing email client to send an Email.
Intent email = new Intent(Intent.ACTION_SEND);
email.putExtra(Intent.EXTRA_EMAIL, new String[]{"put_your_mail#gmail.com"});
email.putExtra(Intent.EXTRA_SUBJECT, "subject");
email.putExtra(Intent.EXTRA_TEXT, "message");
email.setType("message/rfc822");
startActivity(Intent.createChooser(email, "Choose an Email client :"));
For more details you visit How to send Email in Android and
http://code.tutsplus.com/tutorials/quick-tip-enabling-users-to-send-email-from-your-android-applications-the-easy-way--mobile-1686
Standard way to do this is using the ACTION_SEND intent
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_EMAIL, "emailaddress#emailaddress.com");
intent.putExtra(Intent.EXTRA_SUBJECT, "Subject");
intent.putExtra(Intent.EXTRA_TEXT, "I'm email body.");
startActivity(Intent.createChooser(intent, "Send Email"));
If you want to send the mail in background without opening another app check this answer https://stackoverflow.com/a/2033124/2761055
Here, you have information how to do that in background with PHP file on your server.
But in my opinion, this method is deprecated.
Look also here. This code will start new intent with email.
String body="message";
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Check out this book I am reading");
emailIntent.setType("plain/text");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, body);
startActivity(Intent.createChooser(emailIntent, "Send email..."));
No matter what I do (removing all gmail accounts and signin a hotmail account with mail app), this code launches Gmail by default and do not show or let me choose my universal mail app.
Consequently, there is no way to let user send email via hotmail or other mail provider.
update:
Actually this is the best piece of code I ever come across, it presents you directly with an app chooser where only mail client are present. The answer below will give you a huge list of apps to choose from that are irrelevant.
String mailTo="";
Intent email_intent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto",mailTo, null));
email_intent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Subject text here");
email_intent.putExtra(android.content.Intent.EXTRA_TEXT,"Body text here");
startActivity(Intent.createChooser(email_intent, "Send email..."));
Try using the correct MIME type (text/plain) instead of an invalid MIME type (plain/text).
Hello I am just curious about.
From Message Inbox/Outbox. we can retrieve :phone number,message body,date,locked status,StatusOnSim etc.
So Can we retrieve from email (sent+inbox):Email_id,Subject,Body,CC,BCC etc.
I want to retrive all this thing from my email like Email_id,Subject,Body,CC,BCC etc
if any one have idea regarding this than please help me on it.
Code to send email information:
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_EMAIL, new String[] {
"ur mail id" });
intent.putExtra(Intent.EXTRA_SUBJECT, "ur subject");
intent.putExtra(Intent.EXTRA_TEXT, "ur text");
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(FileName));
startActivity(Intent.createChooser(intent, "Choose"));
it cant retrieve data like Email_id,Subject,Body,CC,BCC etc from ur mail box. But it possible in Message inbox.
This question already has answers here:
Send HTML mail using Android intent
(5 answers)
Closed 3 months ago.
I want to send email through my application. I need to send HTML based email just through G-Mail. I found following solutions that each of them has pros and cons.
1) Using Intent (Intent.ACTION_SEND). This is very simple way and I can see my body in HTML format but the problem is when I click on "Send email" button, so many applications like Facebook and Google+ pop up which are useless and I shouldn't show it in that list. This is its code:
String html = "<!DOCTYPE html><html><body>Visit W3Schools.com!" + "<p>If you set the target attribute to \"_blank\", the link will open in a new browser window/tab.</p></body></html>";
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_EMAIL, new String[] {"MY EMAIL ADDRESS"});
intent.putExtra(Intent.EXTRA_SUBJECT, "subject here");
intent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(html));
startActivity(Intent.createChooser(intent, "Send email..."));
2) Using Intent (Intent.ACTION_SENDTO). This way Filters useless applications and shows me just mail clients. But it doesn't display my email in HTML format in gmail client. When i send the email some clients show the body in HTML format while others doesn't identify HTML and my link behaves like plain text. This code is like:
String html = "<!DOCTYPE html><html><body>Visit W3Schools.com!" + "<p>If you set the target attribute to \"_blank\", the link will open in a new browser window/tab.</p></body></html>";
Intent send = new Intent(Intent.ACTION_SENDTO);
String uriText = "mailto:MY EMAIL ADDRESS" + "?subject=subject here" + "&body=" + html;
uriText = uriText.replace(" ", "%20");
Uri uri = Uri.parse(uriText);
send.setData(uri);
startActivity(Intent.createChooser(send, "Send mail..."));
3) Sending mail using JavaMail API which adds so much complexity to application and I didn't test it so far.
What is your suggestion? I need a way to have advantages of first and second ways. I need when user click on button it shows Gmail client and I can show him/her html content in body part of client.
any suggestion would be appreciated. Thanks
======================
Update
Something about code 2 is wrong. The code is like this:
String html = "<!DOCTYPE html><html><body>Visit W3Schools.com!" + "<p>If you set the target attribute to \"_blank\", the link will open in a new browser window/tab.</p></body></html>";
Intent send = new Intent(Intent.ACTION_SENDTO);
String uriText = "mailto:MY EMAIL ADDRESS" + "?subject=subject here" + "&body=" + Html.fromHtml(html);
uriText = uriText.replace(" ", "%20");
Uri uri = Uri.parse(uriText);
send.setData(uri);
startActivity(Intent.createChooser(send, "Send mail..."));
Try the following -
Intent shareIntent = new Intent(Intent.ACTION_SENDTO,Uri.parse("mailto:"));
shareIntent.putExtra(Intent.EXTRA_TEXT,Html.fromHtml(body));
shareIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
startActivity(shareIntent);
This will only present email applications.
If you want only one application to handle your intent then you need to remove Intent.createChooser(), rather jst use startActivity()---> it send the mail using default email client, if not set then will ask to do so... tat can be changed anytime
To get only email applications, use
Intent.setType("message/rfc822")