I would like to send an email to given email address with some default instructions. I know that I can achieve it for sms by using twilio but don't know how to do this via mail..
You can directly use following to send mail with body:
final Intent intent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("text/plain");
intent.putExtra(android.content.Intent.EXTRA_EMAIL, new String\[\]{ "serveroverloadofficial#gmail.com"});
intent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Hello There");
intent.putExtra(android.content.Intent.EXTRA_TEXT, "Add Message here");
intent.setType("message/rfc822");
try {
startActivity(Intent.createChooser(intent,
"Send email using..."));
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(getActivity(),
"No email clients installed.",
Toast.LENGTH_SHORT).show();
}
}
});
Use Mailgun.com to send email by Using their API.
Related
I have an POS app and I want to send my e-receipt to customers via email.
I have checked some resources and what I have found is how to send emails with text messages.
How can I make my email to look something like this?
You can pass Spanned text in your extra
final Intent shareIntent = new Intent(Intent.ACTION_SENDTO, Uri.parse("mailto:"));
shareIntent.putExtra(Intent.EXTRA_SUBJECT, "The Subject");
shareIntent.putExtra(
Intent.EXTRA_TEXT,
Html.fromHtml(new StringBuilder()
.append("<p><b>Some Content</b></p>")
.append("<small><p>More content</p></small>")
.toString())
);
I think you can send email via Intent action
Intent it = new Intent(Intent.ACTION_SEND);
it.putExtra(Intent.EXTRA_EMAIL, new String[]{"support#tutlane.com"});
it.putExtra(Intent.EXTRA_SUBJECT, "Welcome to Tutlane");
it.putExtra(Intent.EXTRA_TEXT, "Hi Guest, Welcome to Tutlane Tutorial Site");
it.setType("message/rfc822");
https://www.tutlane.com/tutorial/android/android-send-email-with-examples
You can try the following way.
String[] recipients = {"abc#gmail.com"};
Intent email = new Intent(Intent.ACTION_SEND, Uri.parse("mailto:"));
// prompts email clients only
email.setType("message/rfc822");
email.putExtra(Intent.EXTRA_EMAIL, recipients);
email.putExtra(Intent.EXTRA_SUBJECT, "email subject");
email.putExtra(Intent.EXTRA_TEXT, "Hello, This is a test message");
try {
// the user can choose the email client
startActivity(Intent.createChooser(email, "Choose an email client from..."));
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(MainActivity.this, "No email client installed.",
Toast.LENGTH_LONG).show();
}
}
Android provides some further fields, these fields have to be attached to the Intent as extra data:
EXTRA_BCC: email addresses for blind carbon copy
EXTRA_CC: email addresses for carbon copy
EXTRA_HTML_TEXT: supply an alternative to EXTRA_TEXT as HTML formatted text
EXTRA_STREAM: URI holding a stream of data supplying the data that
are sent
EXTRA_TITLE: the title that is shown when the user has to choose an
email client
For a complete example, see this tutorial.
I want to use Intent to send an email without any touching in the screen. I tried the bellow code but it requires to choose many steps: such as email client, send button...I do not want to perform these steps. Just auto send without any touching in the screen. Is it possible in Android M? Thanks
//Email
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("message/rfc822");
i.putExtra(Intent.EXTRA_EMAIL , new String[]{"abc#gmail.com"});
i.putExtra(Intent.EXTRA_SUBJECT, "Title");
i.putExtra(Intent.EXTRA_TEXT , "Body");
try {
startActivity(Intent.createChooser(i, "Send mail..."));
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
}
using Intent with ACTION_SEND should open all Apps that can handle sending emails and user will have to select one of them to proceed with sending.
Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.setData(Uri.parse("mailto:user_name#provider"));
intent.putExtra(Intent.EXTRA_SUBJECT, "Subject");
intent.putExtra(Intent.EXTRA_TEXT,"Body");
try {
startActivity(Intent.createChooser(intent, "Send Email"));
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
}
but if want to send email without using other apps (email clients), you should search for how to send emails directly or check this
I am developing an application for a hotel, where in, on booking a room, the app sends an email to the email-id given by the user. Now, i know it will use one of my default email clients, which is the gmail. The problem is, it is showing up with gmail's compose message window, with my message in the message body,but the 'to'field is empty. Any help?
here is the code:
public void sendmail(View vw)
{
name=et1.getText().toString();
to=et2.getText().toString();
phone=et3.getText().toString();
addr=et4.getText().toString();
Log.i("Send email", "");
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.setData(Uri.parse("mailto:"));
emailIntent.setType("text/plain");
emailIntent.putExtra(Intent.EXTRA_EMAIL, to);
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Thanks for using our app");
emailIntent.putExtra(Intent.EXTRA_TEXT, "Hello mr"+name+"We just received an email with your details asking for a reservation:"+phone+" "+addr+"for room number"+x+"");
try {
startActivity(Intent.createChooser(emailIntent, "Send mail..."));
finish();
Log.i("Finished sending email...", "");
}
catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(getBaseContext(), "There is no email client installed.", Toast.LENGTH_SHORT).show();
}
}
}
From the documentation of EXTRA_EMAIL:
A String[] holding e-mail addresses that should be delivered to.
Something like this should work:
Intent mailIntent = new Intent(Intent.ACTION_SENDTO);
mailIntent.setData(Uri.parse("mailto:"));
mailIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{to});
mailIntent.putExtra(Intent.EXTRA_SUBJECT, "Thanks for using our app");
mailIntent.putExtra(Intent.EXTRA_TEXT, "Hello mr"+name+"We just received an email with your details asking for a reservation:"+phone+" "+addr+"for room number"+x+"");
if (mailIntent.resolveActivity(getPackageManager()) != null) {
startActivity(mailIntent);
} else {
// no e-mail app installed
}
Try this :
emailIntent.putExtra(Intent.EXTRA_EMAIL , new String[]{"recipient#to.com"});
email intent expects an String array but you're providing a string.So, it's not working in your case!
IO want to send email in html format in android. I am able to send mail via gmail client but I am not able to get the styles of html of when I use any other client. I have used below code
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/html");
i.putExtra(Intent.EXTRA_SUBJECT, "TestMail");
i.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml("<p><b>Some Content</b></p>"));
try {
startActivity(Intent.createChooser(i, "Send mail..."));
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(EmailHtmlActivity.this, "There are no email clients installed.",Toast.LENGTH_SHORT).show();
}
try this I am not sure but it may be help you..
startActivity(Intent.createChooser(new Intent(Intent.ACTION_SEND).setType("message/rfc822")
.putExtra(Intent.EXTRA_SUBJECT, subject)
.putExtra(Intent.EXTRA_TEXT,Html.fromHtml(new String().concat("YOUR MESSAGE")),
"Send your email in:"));
Thanks.
I have an app that has two buttons – one for email & one for SMS. Depending on the button pressed I want to email or else SMS a certain text. I have coded the email button and it is working fine. The problem is that the dialog box that pops-up gives an option of e-mail or Messaging the text. I want to separate out the two, so that when the user presses email, only the options of email is there, and when the user presses SMS, only the option of Messaging is there.
Here is the code that I have tried.
private void sendEmail(){
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(Intent.EXTRA_EMAIL , new String[]{"recipient#example.com"});
i.putExtra(Intent.EXTRA_SUBJECT, "Subject of the message");
i.putExtra(Intent.EXTRA_TEXT , "Body of the message");
try {
startActivity(Intent.createChooser(i, "Send mail..."));
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
}
}
Basically there seems to be a single intent Intent.ACTION_SEND for both emails & Messaging.
Any way to separate them out?
You can launch the Messaging application with a prepopulated message like this:
Intent sendIntent = new Intent(Intent.ACTION_VIEW);
sendIntent.putExtra("sms_body", "The SMS text");
sendIntent.setType("vnd.android-dir/mms-sms");
startActivity(sendIntent);
or do something like this to just send it straightaway, without presenting the Messaging app:
Uri uri = Uri.parse("smsto:0800000123");
Intent it = new Intent(Intent.ACTION_SENDTO, uri);
it.putExtra("sms_body", "The SMS text");
startActivity(it);
String to use for sending email only is:
email.setType("message/rfc822");