Skip to content

aslamanver/android-email

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

SMTP Email for Android (Send emails from Android)

Just write few lines of code.

final String username = "yourname@yourcompany.com";
final String password = "yourpassword";

Properties props = new Properties();
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.host", "smtp.example.com");
props.put("mail.smtp.port", "587");

Session session = Session.getInstance(props, new javax.mail.Authenticator() {
    protected PasswordAuthentication getPasswordAuthentication() {
        return new PasswordAuthentication(username, password);
    }
});

try {

    Message message = new MimeMessage(session);
    message.setFrom(new InternetAddress("to@yourdomain.com"));
    message.setRecipients(Message.RecipientType.TO,
            InternetAddress.parse("to@yourdomain.com"));
    message.setSubject("Testing Subject");
    message.setText("Dear Dude,"
            + "\n\n I came from Android SMTP!");

    Transport.send(message);

    System.out.println("Done");

} catch (MessagingException e) {
    throw new RuntimeException(e);
}

Configure your email server and enjoy.

About

Send SMTP emails directly from Android using Java - (AndroidEmail)

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages