- Add to build.gradle in app level
implementation 'com.github.tntkhang:gmail-sender-library:1.3.0'
- How to use it
GMailSender.withAccount("your-email@gmail.com", "email-password")
.withTitle(title)
.withBody(body)
.withSender(getString(R.string.app_name))
.toEmailAddress(emailAddress) // one or multiple addresses separated by a comma
.withListenner(new GmailListener() {
@Override
public void sendSuccess() {
Toast.makeText(MainActivity.this, "Success", Toast.LENGTH_SHORT).show();
}
@Override
public void sendFail(String err) {
Toast.makeText(MainActivity.this, "Fail: " + err, Toast.LENGTH_SHORT).show();
}
})
.send();
- IMPORTANT ! Enable less secure for the email using to sent email: https://support.google.com/accounts/answer/6010255?hl=en
- Add those line into pro-guard
# Required for GmailSender
-dontwarn java.awt.**
-dontwarn java.beans.Beans
-dontwarn javax.security.**
-keep class javamail.** {*;}
-keep class javax.mail.** {*;}
-keep class javax.activation.** {*;}
-keep class com.sun.mail.dsn.** {*;}
-keep class com.sun.mail.handlers.** {*;}
-keep class com.sun.mail.smtp.** {*;}
-keep class com.sun.mail.util.** {*;}
-keep class mailcap.** {*;}
-keep class mimetypes.** {*;}
-keep class myjava.awt.datatransfer.** {*;}
-keep class org.apache.harmony.awt.** {*;}
-keep class org.apache.harmony.misc.** {*;}
- Enjoy