Android wrapper for JavaMail to easily send email without intents.
The library is still in development but you can get the SNAPSHOT with Gradle:
compile 'it.enricocandino:androidmail:1.0.0-SNAPSHOT'or Maven:
<dependency>
<groupId>it.enricocandino</groupId>
<artifactId>androidmail</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>Create a MailSender with your email and password, build a Mail and send it. The mail will be sent in background with an AsyncTask.
In the simplest way:
MailSender mailSender = new MailSender(email, password);
Mail.MailBuilder builder = new Mail.MailBuilder();
Mail mail = builder
.setSender(senderMail)
.addRecipient(new Recipient(recipient))
.setText("Hello")
.build();
mailSender.sendMail(mail);
You can be notified through a listener, or add more recipients, html and attachments!
MailSender mailSender = new MailSender(email, password);
Mail.MailBuilder builder = new Mail.MailBuilder();
Mail mail = builder
.setSender(senderMail)
.addRecipient(new Recipient(recipient))
.addRecipient(new Recipient(Recipient.TYPE.CC, recipientCC))
.setText("Hello")
.setHtml("<h1 style=\"color:red;\">Hello</h1>")
.addAttachment(new Attachment(filePath, fileName))
.build();
MailSender.OnMailSentListener onMailSentListener = new MailSender.OnMailSentListener() {
@Override
public void onSuccess() {
// mail sent!
}
@Override
public void onError(Exception error) {
// something bad happened :(
}
});
mailSender.sendMail(mail, onMailSentListener);
Remember to add the INTERNET permissions and (for the attachments) the READ_EXTERNAL_STORAGE/WRITE_EXTERNAL_STORAGE:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Note: since API 23+ you have to check again in the app if the user granted the storage permissions.
The only provider supported (at the moment) is Gmail.
Check the sample for a working app!
Let me know if you used the library in your project. I will be happy to list it here!
Enrico Candino - www.enricocandino.it
-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.** {*;}
The MIT License (MIT)
Copyright (c) 2015 Enrico Candino
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.