Good evening everyone! I am writing this code to send e-mail and SMS from my application, the SMS is sent, but the e-mail is not. `

public void onClick(View v) { switch (v.getId()) { case R.id.btnSms: // TODO Call second activity Intent sendIntent = new Intent(Intent.ACTION_VIEW); sendIntent .putExtra( "sms_body", "Здесь текст и смс прекрасно отправляется!!"); sendIntent.setType("vnd.android-dir/mms-sms"); startActivity(sendIntent); break; 

case R.id.btnEmail:

  /* Создаем интент с экшеном на отправку */ Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); /* Заполняем данными: тип текста, адрес, сабж и собственно текст письма */ emailIntent.setType("text"); emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{""}); emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Здесь заголовок"); emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "здесь тоже текст. Но почему-то письмо никак не хочет отправляться???"); /* Отправляем на выбор!*/ context.startActivity(Intent.createChooser(emailIntent, "Send mail...")); break; default: break;` 

Where was the mistake? In the manifest, like all the permissions are prescribed. Maybe for e-mail some separate permission is needed?

  • habrahabr.ru/post/112450 :> Minuses: The user must have a configured program for receiving and transmitting mail messages, without it there will be no one to handle this Intent. - KaZaca
  • KaZats, is not very clear about the program, should it be something like gmail on the phone or did you mean something different? - s01nyshko
  • Yes, it implies that there should be any email client on the phone, which is almost always true (not counting the samopal) for sending emails using Intents. - DroidAlex

1 answer 1

How to send email from my Android application .

I think an error in the line:

 setType("text"); 

Well, sending soap without using Intent and a third-party client: Sending Email in Android using JavaMail API without using the default / built-in app .

  • DroidAlex, i.e. here should be setType ("text / plain") or setType ("message / rfc822") ;? - s01nyshko
  • And what is the fundamental difference between Intent intent = new Intent (Intent.ACTION_SENDTO); and Intent emailIntent = new Intent (android.content.Intent.ACTION_SEND) ;? - s01nyshko
  • one
    According to the idea text / plain should suffice. But if the error is - try the second. I will not answer the second question this way, I know that ACTION_SEND is usually used to send letters. And for the future: the errors that the environment displays to you, also write to the question. So it will be easier to understand what your problem is. - DroidAlex
  • Thanks for the help! Now everything works - (android.content.Intent.ACTION_SEND), and in setType after all ("text / plain") ;. - s01nyshko
  • Please :) - DroidAlex