Skip to content

Instantly share code, notes, and snippets.

@KryptKode
Created May 29, 2020 06:46
Show Gist options
  • Save KryptKode/ed47d3eaeb40e2a86d286c1040a19458 to your computer and use it in GitHub Desktop.
Save KryptKode/ed47d3eaeb40e2a86d286c1040a19458 to your computer and use it in GitHub Desktop.
Helper for sending email android
import android.app.Activity
import android.content.Intent
import android.net.Uri
import androidx.appcompat.app.AppCompatActivity
import com.kryptkode.flashalerts.R
import javax.inject.Inject
/**
* Created by kryptkode on 2/26/2020.
*/
class SendEmailUtil @Inject constructor(private val activity: AppCompatActivity) {
fun sendEmail(recipientEmail: String, subject: String, body: String) {
val intent = Intent(
Intent.ACTION_SENDTO, Uri.fromParts(
"mailto", recipientEmail, null
)
)
intent.putExtra(Intent.EXTRA_EMAIL, arrayOf(recipientEmail))
intent.putExtra(Intent.EXTRA_SUBJECT, subject)
intent.putExtra(Intent.EXTRA_TEXT, body)
activity.startActivity(
Intent.createChooser(
intent,
activity.getString(R.string.send_email_hint)
)
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment