Can Send only email with random characters from Android phone using Gmail - android

Intent i = new Intent(Intent.ACTION_SEND);
i.setType("message/rfc822");
i.putExtra(Intent.EXTRA_EMAIL , new String[]{"recipient#example.com"});
i.putExtra(Intent.EXTRA_SUBJECT, "subject of email");
i.putExtra(Intent.EXTRA_TEXT , sb.toString());
try {
startActivity(Intent.createChooser(i, "Send mail..."));
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(MyActivity.this, "There are no email clients installed.",
Toast.LENGTH_SHORT).show();
}
The sb.toString() is a stringbuilder that holds the appropriate data.
At first, I thought everything working fine because I could open the email app and the appropriate text was displayed. However, after pressing send I found that when I looked at the mail in my gmail client (on phone and on computer) it was gibberish. What is causing this and how do I fix it?
I am using gmail mail client.
Here is what I see in the email after I send it to myself:
&#0 407,497,552
repeated many, many times.
Before I press send, I see: integer, integer, integer
on each line for a 50-75 lines.

Related

How to send an email in Android without action to UI?

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

How to Make a Button Submit Multiple Textviews to my Email?

I looked it up, and this is the most common way to send an email...
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("message/rfc822");
i.putExtra(Intent.EXTRA_EMAIL , new String[]{"recipient#example.com"});
i.putExtra(Intent.EXTRA_SUBJECT, "subject of email");
i.putExtra(Intent.EXTRA_TEXT , "body of email");
try {
startActivity(Intent.createChooser(i, "Send mail..."));
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(MyActivity.this, "There are no email clients
installed.",
Toast.LENGTH_SHORT).show();
}
I am confused as to what this is actually sending, and how to make this happen when the user clicks a button. Do I put the recipient email (me) like this?
i.putExtra(Intent.EXTRA_EMAIL , "myemail#gmail.com");
Then the same format for subject and message/body of the email?
Is this how I would put the user's input into the body of the email? (The user inputs multiple editText boxes)
editText userTitle = (editText)findViewById(R.id.idOfTheEditTextBox);
editText userDescription = (editText)findViewById(R.id.idOfTheEditTextBox);
Then input it like this?
i.putExtra(Intent.EXTRA_TEXT , "userTitle", "userDescription");
Finally, what does all that toast and no email clients installed mean? I am new to android app development, and am making an app on Android Studio! All help is very much appreciated!! Thanks!
Firstly "Toast"
Toast code is written to give alert to user, notifying that no email
client is available in users phone (ex. gmail, etc)
Now the main portion,
i.putExtra(Intent.EXTRA_EMAIL , new String[]{"recipient#example.com"});
Yes this above line add the recipents email address.
So to achive this kind of thing, you need to do following things,
Create layout with one Edittext (where user can put recepeints email address which you can pass to Intent). And one button on click of which you will launch Intent.
Now then the button is clicked write this code:-
public class MainActivity extends AppCompatActivity {
EditText etRecipentId, etSubject, etBody;
Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
etRecipentId = (EditText) findViewById(R.id.email_id);
etSubject = (EditText) findViewById(R.id.et_subject);
etBody = (EditText) findViewById(R.id.et_body);
}
b1.setOnClickListener(new OnClickListener() {
public void onClick() {
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("message/rfc822");
i.putExtra(Intent.EXTRA_EMAIL, new String[] {
etRecipentId.getText().toString();
});
i.putExtra(Intent.EXTRA_SUBJECT, etSubject.getText().toString(););
i.putExtra(Intent.EXTRA_TEXT, etBody.getText().toString(););
try {
startActivity(Intent.createChooser(i, "Send mail..."));
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(MyActivity.this, "There are no email clients
installed.",
Toast.LENGTH_SHORT).show();
}
}
});
instead of i.putExtra(Intent.EXTRA_TEXT , "userTitle", "userDescription"); use i.putExtra(Intent.EXTRA_TEXT , userTitle+" "+userDescription);
And as you are getting exception ,check that is there any email client like gmail,etc is installed in your phone or not.

How can I implement italic HTML format of text in Android in Yahoo email client, or native mail client

I have to implement a text in italic, so I have used HTML formatting.
In gmail app it works fine but in native mail client, yahoo mail app, or outlook, I cant see italicised text.
below is the sample code:
Html html = null;
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(Intent.EXTRA_EMAIL , new String[]{"konypsteam#gmail.com"});
i.putExtra(Intent.EXTRA_SUBJECT, "testMail");
//i.putExtra(Intent.EXTRA_TEXT , html.fromHtml(body));
i.putExtra(android.content.Intent.EXTRA_TEXT, html.fromHtml(body));
try {
startActivity(Intent.createChooser(i, "Send mail..."));
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(MainActivity.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
}
Any help?

Sending email programatically using the DEFAULT app

I am developing an app that send programatically an email, Im using stoxk LG mail
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("message/rfc822");
i.putExtra(Intent.EXTRA_EMAIL , new String[]{XXXXXXX});
i.putExtra(Intent.EXTRA_SUBJECT, "XXXXXXXXXX");
i.putExtra(Intent.EXTRA_TEXT , (" XXXXXXXX"));
try {
startActivity(Intent.createChooser(i, "Sending mail..."));
} catch (android.content.ActivityNotFoundException ex) {
Toast toast = Toast.makeText(getApplicationContext(), "Not found ", Toast.LENGTH_LONG);
toast.show();
finish();
}
It opens the LG mail and pastes the SUBJECT, the TEXT and the MAIL BUT it doesn't send it , how can I achieve it?
Anny suggestion will be apreciated!
With intent you can't do this.
But look at the link, there is an answer for your question.
Sending Email in Android using JavaMail API without using the default android app(Builtin Email application)

Android: Separate intents for email & SMS

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");

Categories

Resources