Kotlin (Android) Send SMTP Email with Awesome MailDroid Library [NEW] – Coding Shiksha

Welcome folks I am back with another tutorial send this tutorial we will be talking about that how we can implement SMTP mail server and kotlin and to this library will be able to integrate mail facility and Android application so that library name is maildroid Mail Droid is a handy library which comes with lot of handy functions that you can use in now to implement mailing facility in your Android application so in this blog post we will be looking at those functions with life source code examples and also source code of this examples are given below just copy paste and also the demo of this application is given below so I will see the screenshot and also try to extend this application accordingly to your needs.


Demo of Application



As we can see in the demo application we are sending emails through a client called as mailtrap In this tutorial I will be using a special website which is used to send and receive emails for developers who are wanting to include some mailing functionality in their application to the web servers that service name is mailtrap so you can just go to its official website from here so just signup form in for a new account and then you can use this service for development purpose and once your application is ready you can just move on to gmail.com for other SMTP server that you are using in our application


Key Features

  • Sending emails using SMTP protocol
  • Compatible with all smtp providers
  • Sending HTML/CSS styled emails
  • Library is using Java Mail API that is well known as best library for sending emails


Include the Library


Maildroid is hosted on JitPack and it’s quite easy to integrate in to your project. Maildroid requires at least Android API level 19 Android KitKatHow you want to include this library in your project



For Gradle

For Maven


Using this Library



As you can see in the above code snippet we are using the maildroid Builder method so in this builder method you need to provide some arguments such as the from address and what is address that you are sending this mail to and if you are including any kind of attachment such as PDF file or any kind of file you need to put full path of that file and also you need to specify the message subject and there is a field called as body we need to specify the body of the email also and there are two callback functions available in this method so when the mail has been successfully sent then and on complete callback function will be fired and in that callback function you can write anything you want when you want to print out something that your mail has been sent and on the other side there is also a fail call back so when the mail is not sent successfully then you can print out something like that that the mail is not sent properly so you can handle all kind of situations in this two callback functions and lastly we can also provide some time limit and in this case we are providing 3 seconds 3 millisecond wait so this will wait 3 seconds and then it will send your mail and lastly attaching .mail() function will actually send the email to the client that is mailtrap.


Full Example Source Code


  1. Layout File:


2) Kotlin Code


Leave a Reply