Android Library to send eMails.
-
Add it in your root build.gradle at the end of repositories:
allprojects { repositories { ... maven { url 'https://jitpack.io' } } }
-
Add the dependency:
dependencies { implementation 'com.github.cyberman-io:eMailer:1.0.0' }
-
create a new SmtpSession:
SmtpSession session = new SmtpSession(smtp_host_address);
or:
SmtpSession session = new SmtpSession(smtp_host_address,smtp_host_prot);
ex:
SmtpSession session = new SmtpSession("smtp.yandex.com",465);
-
enable encryption protocol:
session.enableStartTLS();
or:
session.enableSSL();
-
set authentication mechanisme and authentication info:
session.useAuthentication(new LoginAuthentication(user_name,user_password));
or:
session.useAuthentication(new PlainAuthentication(user_name,user_password));
-
create a new Message Object:
PlainTextMessage message = new PlainTextMessage(sender_email,recipient_email);
or if you want to add an attachments (files):
Attachment attachment = new Attachment(file_path); AttachmentMessage message = new AttachmentMessage(sender_email,recipient_email,attachment);
set message data:
message.setSubject(subject); message.setText(messageText); message.setSenderName(optional_name);
-
set message to session:
session.setMessage(message);
-
set OnCompleteListener:
session.setOnCompleteListener(new SmtpSession.OnCompleteListener() { @Override public void onSendSuccess() { //your code. } @Override public void onServerError(int responseCode, String responseMessage) { //your code. } @Override public void onError(Exception e) { //your code. } });
-
send message:
session.send();