JMailTM is a Lightweight Java Wrapper for https://mail.tm API (A Temp Mail Service). It has a easy to use interface and callbacks with javaDoc.
Easy to add in your projects using gradle, maven or jar
- Add it in your root build.gradle at the end of repositories:
allprojects {
repositories {
maven { url 'https://jitpack.io' }
}
}
- Add the dependency (replace version with the version on top)
dependencies {
implementation 'com.github.shivam1608:JMailTM:0.6'
}
- Add the repository in pom.xml file
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
- Add the dependency (replace version with the version on top)
<dependency>
<groupId>com.github.shivam1608</groupId>
<artifactId>JMailTM</artifactId>
<version>0.6</version>
</dependency>
Download the jar from this repo
out/artifact/JMailTM.jar or Use the Release Section
- Open a Message Listener with a new Temp EMail
import me.shivzee.JMailTM;
import me.shivzee.callbacks.EventListener;
import me.shivzee.util.JMailBuilder;
import me.shivzee.util.Message;
import javax.security.auth.login.LoginException;
public class JMailService {
public static void main(String[] args) {
try {
JMailTM mailer = JMailBuilder.createDefault("randomPassword");
mailer.init();
System.out.println("Email : " + mailer.getSelf().getEmail());
mailer.openEventListener(new EventListener() {
@Override
public void onMessageReceived(Message message) {
System.out.println("Message Has Attachments ? : " + message.hasAttachments());
System.out.println("Message Content : " + message.getContent());
System.out.println("Message RawHTML : " + message.getRawHTML());
// To Mark Message As Read
message.markAsRead(status -> {
System.out.println("Message " + message.getId() + " Marked As Read");
});
}
@Override
public void onError(String error) {
System.out.println("Some Error Occurred " + error);
}
});
} catch (LoginException exception) {
System.out.println("Exception Caught " + exception);
}
}
}
- All Overridable Methods
mailer.openEventListener(new EventListener() {
@Override
public void onReady() {}
@Override
public void onMessageReceived(Message message) {}
@Override
public void onMessageDelete(String id) {}
@Override
public void onMessageSeen(Message message) {}
@Override
public void onAccountDelete(Account account) {}
@Override
public void onError(String error) {}
});
- Get Details of Email
mailer.openEventListener(new EventListener() {
@Override
public void onMessageReceived(Message message) {
String sender = message.getSenderAddress();
String senderName = message.getSenderName();
String content = message.getContent();
String subject = message.getSubject();
String id = message.getId();
boolean b = message.hasAttachments();
}
@Override
public void onError(String error) {
System.out.println("Some Error Occurred "+error);
}
});
- Refer to Docs for all functions
message.markAsRead(status->{
if(status) System.out.println("Message Marked as Read");
});
message.asyncMarkAsRead(status->{
if(status) System.out.println("Message Marked as Read");
});
message.delete(status->{
if(status) System.out.println("Message was Deleted");
});
message.asyncDelete(status->{
if(status) System.out.println("Message was Deleted");
});
@Override
public void onMessageReceived(Message message) {
if(message.hasAttachments()){
for (Attachment attachment : message.getAttachments()){
String filename = attachment.getFilename();
String id = attachment.getId();
long size = attachment.getSize();
// Download The Attachment
attachment.save(status->{
if (status) System.out.println("File Was Downloaded");
});
}
}
}
- Fetch All Messages
try {
JMailTM mailer = JMailBuilder.createDefault("randomPassword");
mailer.init();
System.out.println("Email : "+mailer.getSelf().getEmail());
mailer.fetchMessages(new MessageFetchedCallback() {
@Override
public void onMessagesFetched(List<Message> list) {
for (Message message : list){
// All Message Functions
}
}
@Override
public void onError(Response response) {
}
});
}catch (LoginException | MessageFetchException exception){
System.out.println("Exception Caught "+exception);
}
- Fetch Limited Messages
try {
JMailTM mailer = JMailBuilder.createDefault("randomPassword");
mailer.init();
System.out.println("Email : "+mailer.getSelf().getEmail());
int limit = 4; // The Limit for Messages to Fetch
mailer.fetchMessages( limit ,new MessageFetchedCallback() {
@Override
public void onMessagesFetched(List<Message> list) {
for (Message message : list){
// All Message Functions
}
}
@Override
public void onError(Response response) {
}
});
}catch (LoginException | MessageFetchException exception){
System.out.println("Exception Caught "+exception);
}
- Fetch All Messages
try {
JMailTM mailer = JMailBuilder.createDefault("randomPassword");
mailer.init();
System.out.println("Email : "+mailer.getSelf().getEmail());
mailer.asyncFetchMessages(new MessageFetchedCallback() {
@Override
public void onMessagesFetched(List<Message> list) {
for (Message message : list){
// Do anything with Messages
}
}
@Override
public void onError(Response response) {
}
});
}catch (LoginException exception){
System.out.println("Exception Caught "+exception);
}
- Fetch Limited Messages
try {
JMailTM mailer = JMailBuilder.createDefault("randomPassword");
mailer.init();
System.out.println("Email : "+mailer.getSelf().getEmail());
int limit = 4; // The Limit for Messages to Fetch
mailer.asyncFetchMessages(limit , new MessageFetchedCallback() {
@Override
public void onMessagesFetched(List<Message> list) {
for (Message message : list){
// Do anything with Messages
}
}
@Override
public void onError(Response response) {
}
});
}catch (LoginException exception){
System.out.println("Exception Caught "+exception);
}
Message message = mailer.getMessageById("ID_HERE");
- A Random Email
JMailTM mailer = JMailBuilder.createDefault("randomPassword");
mailer.init();
- Custom Email and Password
//First Fetch Domain
JMailTM mailer = JMailBuilder.createAndLogin("thisismychoice@"+ Domains.getRandomDomain().getDomainName() , "MyPassword");
mailer.init();
//Can Fetch Domains by List Too (Fetches the Domains)
List<Domain> domains = Domains.fetchDomains();
for(Domain domain : domains){
// All Domains
}
//Can Get Saved Domains by mailer.init()
List<Domain> domainList = Domains.getDomainList();
JMailTM mailer = JMailBuilder.login("YourEmail" , "YourPassword");
mailer.init();
mailer.delete(status->{
if(status) System.out.println("Account was Deleted");
});
Author : Shivzee
IDE Used : IntelliJ