The JavaMail API can be utilized on Android using the following steps:
dependencies {
compile 'com.sun.mail:android-mail:1.5.5'
compile 'com.sun.mail:android-activation:1.5.5’
}
Properties props = new Properties();
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", "587");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.ssl.trust", "smtp.gmail.com");
Session session = Session.getInstance(props, new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("your_email@gmail.com", "your_password");
}
});
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress("your_email@gmail.com"));
message.addRecipient(Message.RecipientType.TO, new InternetAddress("recipient_email@example.com"));
message.setSubject("Test email from Android");
message.setText("Hello, this is a test email from Android!");
Transport.send(message);
Note: Make sure to perform network operations (such as sending emails) on a separate thread or using AsyncTask/Handler to avoid blocking the UI thread.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2023-07-12 13:53:20 +0000
Seen: 9 times
Last updated: Jul 12 '23
What are the typical approaches found in a Gradle build script?
What steps can be taken to increase the runtime of a debugger in NativeScript?
What is the method to show the dependencies in Java?
How can I incorporate BeanComparator into my gradle project?
What does the "Invalid source release 1.7" error mean when using gradle for compilation?