I'm using the following code to send an email in my app.
public void sendEmail() {
emailSent = 1;
String to = toEmail.getText().toString();
String subject = getUser() + " - User Feedback";
String message = bodyTxt;
Intent email = new Intent(Intent.ACTION_SEND);
email.putExtra(Intent.EXTRA_EMAIL, new String[] { to });
email.putExtra(Intent.EXTRA_SUBJECT, subject);
email.putExtra(Intent.EXTRA_TEXT, message);
email.setType("message/rfc822");
try {
startActivity(Intent.createChooser(email, "Send Email..."));
} catch (android.content.ActivityNotFoundException ex) {
String msg = ex.getMessage().toString();
emailSent = 2;
Toast.makeText(this, "There was a problem sending this email, please try again.", Toast.LENGTH_SHORT).show();
}
}
The email.setType() presents a screen offering options for which method to send the message including email. This works fine if the user selects email as a copy of the email comes up and the user can then send it. However, if the user doesn't do anything and simply uses the back space it returns to the app and assumes the email has been sent. How can I test for the user not sending the email?
You could startActivityForResult() and listen for a RESULT_OK in onActivityResults. But there is no framework requirement that forces the email app to setResult appropriately. So your mileage may vary based on the email client app.
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 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!
I want send the data to the email address, when I fill the form and that data should be forward to the mail so no need to add any message in email, on click on submit button it should be send to the reciever,
here is my code,
btnfeedbacksubmit.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
/*
Validation class will check the error and display the error on respective fields
but it won't resist the form submission, so we need to check again before submit
*/
if ( checkValidation () )
submitForm();
else
Toast.makeText(Feedback.this, "Form contains error", Toast.LENGTH_LONG).show();
Intent Email = new Intent(Intent.ACTION_SEND);
Email.setType("text/email");
Email.putExtra(Intent.EXTRA_EMAIL, new String[] { "abc#def.com" });
Email.putExtra(Intent.EXTRA_SUBJECT, "Feedback");
Email.putExtra(Intent.EXTRA_TEXT, "");
startActivity(Intent.createChooser(Email, "Sending Feedback:"));
}
});
}
this my form image
I want to send this detail via mail.
please help me in this problem,
thank you.
Add your form as a attachment. you can use below code to add attachment.
String message = etfeedbackname.getText().toString().trim() + etfeedbackno.getText().toString().trim() + etfeedbackemail.getText().toString().trim() +etfeedbackmessage.getText().toString().trim();
Intent Email = new Intent(Intent.ACTION_SEND);
Email.setType("text/email");
Email.putExtra(Intent.EXTRA_EMAIL, new String[] { "abc#def.com" });
Email.putExtra(Intent.EXTRA_SUBJECT, "Feedback");
Email.putExtra(android.content.Intent.EXTRA_TEXT, message);
startActivity(Intent.createChooser(Email, "Sending Feedback:"));
You can specify your form path and send it as a attachment.
I am trying to use the android share intent from my application.
I have listed all the contacts from my contacts content provider in my application.
Now i want to send message to all the contacts i have selected(in my app) using any of the message app
installed in user phone.
I do not want to user smsmaanger , simply want to user any sms sending application in user mobile if
available.
I tried to do with email works great but not with sms .
I tried with email as works great
public static void send(Context ctx, String[] addy, String subject,
String body,File attachment) {
try {
Intent sendIntent = new Intent(Intent.ACTION_SEND_MULTIPLE);
sendIntent.setType("message/rfc822");
sendIntent.putExtra(android.content.Intent.EXTRA_EMAIL,
addy);
sendIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
sendIntent.putExtra(android.content.Intent.EXTRA_TEXT, body);
//sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(attachment));
ctx.startActivity(Intent.createChooser(sendIntent,
"Send via which Application?"));
} catch (Exception e) {
Toast.makeText(ctx, "No activity was found to handle this action",
Toast.LENGTH_SHORT).show();
}
}
For sms i am using like this .
public static void send(Context ctx, String addy, String subject,
String body,File attachment) {
try {
Intent sendIntent = new Intent(Intent.ACTION_VIEW);
sendIntent.setType("vnd.android-dir/mms-sms");
sendIntent.putExtra(android.content.Intent.EXTRA_PHONE_NUMBER,
addy);
sendIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
sendIntent.putExtra(android.content.Intent.EXTRA_TEXT, body);
//sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(attachment));
ctx.startActivity(Intent.createChooser(sendIntent,
"Send via which Application?"));
} catch (Exception e) {
Toast.makeText(ctx, "No activity was found to handle this action",
Toast.LENGTH_SHORT).show();
}
}
I just simply want to add my all contacts to users message app for sending message, with a message
possible
To send SMS to multiple numbers you need to separate the numbers with ;
Sample here:
String toNumbers = "";
ArrayList<String> numbersArrayList;// your phone numbers here
for ( String number : numbersArrayList)
{
toNumbers = toNumbers + number + ";"//separating numbers with semicolon
}
toNumbers = toNumbers.subString(0, toNumbers.length - 1);// remove the last semicolon
...
sendIntent.putExtra(android.content.Intent.EXTRA_PHONE_NUMBER, toNumbers);
Hi I am using in built email sending functionality.But when I tried the code.
void sendEmailMessage(String emailId)
{
Log.i(TAG, "emailId = "+emailId);
Intent intentEmail = new Intent(Intent.ACTION_SEND);
intentEmail.setType("text/plain");
String[] recipients = new String[]{emailId};
intentEmail.putExtra(Intent.EXTRA_EMAIL,recipients);
intentEmail.putExtra(Intent.EXTRA_SUBJECT, "subject of email");
intentEmail.putExtra(Intent.EXTRA_TEXT, "body of email");
try
{
startActivity(Intent.createChooser(intentEmail, "Send mail..."));
} catch (android.content.ActivityNotFoundException ex)
{
Toast.makeText(this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
ex.printStackTrace();
}
}
I don't see recipient email address in recipient EditText on Email screen.I am not getting what I am doing wrong please help.
I think in your void sendEmailMessage(String emailId) method's emailId argument didn't have the value. Just check where you've been called from. And, make sure you are passing email id or not? For example. In your class's somewhere just call that method like below with value.
sendEmailMessage("mail#mail.com");