0

im trying to build an application for a raspberry pi using JAVA ME Embeded latest version (8.0) to connect to gmail and read emails.

However I can't find any native support for that kind of operations on this platform. Can anyone tell me if it's possible to do?

Java version link: http://www.oracle.com/technetwork/java/embedded/javame/embed-me/overview/index.html (Developing on Eclipse using java me embeded sdk )

cbJava
  • 13
  • 4
  • I guess yes: http://paulmcpd.blogspot.de/2009/02/j2me-smtp-client-this-one-works.html – zapl Nov 27 '14 at 01:22
  • It's a good point, but i'm looking for a connection to my inbox, not just sending a email through an smtp server. Thanks. – cbJava Nov 27 '14 at 11:13
  • So you're looking for a POP3+SMTP or IMAP solution, your title says smtp only. google "j2me imap" and you'll find plenty of things like http://www.mujmail.org/index.php?a=4 for example. Not a library you can readily use but it's open source. – zapl Nov 27 '14 at 11:18
  • furthermore; http://stackoverflow.com/questions/1701098/which-library-is-used-to-access-the-gmail-emails-using-j2me JavaMail is said to be not working in several places. – zapl Nov 27 '14 at 11:26

1 Answers1

0

Yes, you can! It'll take a little work but it's definitely possible.

First, you'll need javax.mail.jar found here.

Next, you need to write something along the lines of this to write an email (more info can be found at the link above):

import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.swing.*;

public class EmailProgram {
    public static void main(String[] args) {
        String nameString, emailString;
        nameString = JOptionPane.showInputDialog("Enter your name", "John Doe");
        emailString = JOptionPane.showInputDialog("Enter your email", "john@doe.com");

        final String username = "REDACTED EMAIL ADDRESS";
        final String password = "REDACTED PASSWORD";

        Properties props = new Properties();
        props.put("mail.smtp.auth", "true");
        props.put("mail.smtp.starttls.enable", "true");
        props.put("mail.smtp.host", "smtp.gmail.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("REDACTED EMAIL ADDRESS"));
            message.setRecipients(Message.RecipientType.TO,
                InternetAddress.parse(emailString));
            message.setSubject("Your Grade");
            message.setText("Hi " + nameString + "!\n" + "Your grade has been calculated. It is ");

            Transport.send(message);

            System.out.println("Done");

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

    }
}
  • I have tried this, but I can't get the jar file (javax.mail.jar) to be deployed along with the rest of the application to the rasperry. Do you have any sugestions regarding this? Thanks :) – cbJava Nov 27 '14 at 11:16
  • Okay, a couple things to do/check: 1) put the javax file in the lib folder, then link it through eclipse once it's there. 2) Delete the project from Eclipse, then right click and import it and relink javax. 3) Make sure you're compiling before running. –  Nov 27 '14 at 14:45