I just wanted to open the Gmail app through my app and wanted to set email, subject and message from my application.
I have tried GmailService but it is not supporting bcc or cc emails. Link: https://github.com/yesidlazaro/GmailBackground
BackgroundMail.newBuilder(this)
.withUsername("[email protected]")
.withPassword("password12345")
.withMailto("[email protected]")
.withType(BackgroundMail.TYPE_PLAIN)
.withSubject("this is the subject")
.withBody("this is the body")
.withOnSuccessCallback(new BackgroundMail.OnSuccessCallback() {
@Override
public void onSuccess() {
//do some magic
}
}).withOnFailCallback(new BackgroundMail.OnFailCallback() {
@Override
public void onFail() {
//do some magic
}
}).send();
I would like to use bcc and cc functionality along with the attachment, subject, and message.
// For Email by Any app
Intent email= new Intent(Intent.ACTION_SENDTO);
email.setData(Uri.parse("mailto:[email protected]"));
email.putExtra(Intent.EXTRA_SUBJECT, "Subject");
email.putExtra(Intent.EXTRA_TEXT, "My Email message");
startActivity(email);
open gmail via Intent
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("[email protected]"));
intent.setClassName("com.google.android.gm", "com.google.android.gm.ComposeActivityGmail");
intent.putExtra(Intent.EXTRA_CC, new String[]{"[email protected]"});
intent.putExtra(Intent.EXTRA_BCC, new String[]{"[email protected]"});
intent.putExtra(Intent.EXTRA_SUBJECT, "your subject goes here...");
intent.putExtra(Intent.EXTRA_TEXT, "Your message content goes here...");
startActivity(intent);
just pass EXTRA_CC
& EXTRA_BCC
in intent argument
Edit
Below answer will work on android 11
Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.setData(Uri.parse("mailto:"));
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{"[email protected]"});
intent.putExtra(Intent.EXTRA_SUBJECT, "Your subject here...");
intent.putExtra(Intent.EXTRA_TEXT,"Your message here...");
startActivity(intent);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With