How to send email from EV3 using WIFI

This is where you talk about the EV3 software itself, installation issues, and programming talk.

Moderators: roger, gloomyandy, skoehler

fredsiva
New User
Posts: 4
Joined: Thu Nov 09, 2017 7:24 am

How to send email from EV3 using WIFI

Postby fredsiva » Thu Nov 09, 2017 7:28 am

Hi,

first, let me thank all of you for Lejos, which is just fabulous. I am using 0.091 on an EV3 with an Edimax Wifi dongle, Java8 and Eclipse Neon on my Mac.

How can I send an email from the EV3 program? I try to import javax.mail but it looks to be absent from the JRE (ejre-8u1-linux-arm-15_may_2015.tar) I am using.

thanks for your advices,
Frédéric

User avatar
gloomyandy
leJOS Team Member
Posts: 5899
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: How to send email from EV3 using WIFI

Postby gloomyandy » Thu Nov 09, 2017 8:49 am

Hi,
firstly a couple of things...
1. What version of Java do you have installed on your EV3? Most people will be using Java 7 not Java 8 as it is considerably easier to install a Java 7 JRE than build and install a Java 8 JRE.
2. You should ensure that whatever version of Java you have on the EV3 you have the matching JDK installed in your eclipse setup and that your leJOS projects use this JDK when building.

You should take some time to understand the various Java profiles that are available. In particular take a look at the Java SE and the Java SE Embedded profiles. The EV3 runs the Embedded profile. As a result of this packages like javax.mail are not included as standard. This package is only standard in Java EE

You should also take some time to understand how Java packages are implemented. In this case Java.mail is an add on package that will require you to add jars to both your eclipse and EV3 setup, it may also require you to add native components to the EV3 (but I'm not sure about that), doing this is not a trivial task, and requires you to be familiar with Java and to some extent with Linux). You can find the Java.mail project here:
https://javaee.github.io/javamail/

I have no experience of using this package and so can't really offer any more help. Email can get very complicated, very quickly. As an alternative to sending email directly from the EV3 you may want to consider using some other system as a proxy, run a program on that system that talks to your code on the EV3 and obtains the information you wish to send via email and have the proxy perform the actual email construction and sending of the mail.

Good luck!
leJOS news https://lejosnews.wordpress.com/

fredsiva
New User
Posts: 4
Joined: Thu Nov 09, 2017 7:24 am

Re: How to send email from EV3 using WIFI

Postby fredsiva » Thu Nov 09, 2017 1:58 pm

thanks for the quick answer.

I will search for info on uploading external jars.

User avatar
gloomyandy
leJOS Team Member
Posts: 5899
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: How to send email from EV3 using WIFI

Postby gloomyandy » Thu Nov 09, 2017 2:42 pm

Before you go too far I would suggest that you understand how the jars work. In particular check to see if they make use of any native code or expect to have any services running on the local OS. Either of these will likely make getting things working much more difficult.
leJOS news https://lejosnews.wordpress.com/

fredsiva
New User
Posts: 4
Joined: Thu Nov 09, 2017 7:24 am

Re: How to send email from EV3 using WIFI

Postby fredsiva » Thu Nov 09, 2017 8:12 pm

Does not look too good indeed..

I managed to get the javax.mail and javax.activation loaded on the brick using the Eclipse Features (Neat BTW), but the program crashes as per the console trace here:

Output redirected
Executing jrun -cp /home/lejos/programs/TestRelayEV3.jar lejos.internal.ev3.EV3Wrapper TestRelayEV3 in /home/lejos/programs
java.lang.NoClassDefFoundError: java/awt/datatransfer/Transferable
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at TestRelayEV3.SendEmail(TestRelayEV3.java:50)
at TestRelayEV3.test(TestRelayEV3.java:105)
at TestRelayEV3.main(TestRelayEV3.java:26)


I presume that the Native method identified above means it is using some OS service that the EV3 does not offer, right?

User avatar
gloomyandy
leJOS Team Member
Posts: 5899
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: How to send email from EV3 using WIFI

Postby gloomyandy » Thu Nov 09, 2017 9:38 pm

Actually that looks more like a java class that is not included in the Java SE Embedded profile (none of the AWT classes are supported).
leJOS news https://lejosnews.wordpress.com/

fredsiva
New User
Posts: 4
Joined: Thu Nov 09, 2017 7:24 am

Re: How to send email from EV3 using WIFI

Postby fredsiva » Fri Nov 10, 2017 10:36 pm

Tadaa! Got it to work, but with a few changes:

- not using javax.mail, but the straight SMTP protocol on a stream
- getting a free email from SMTP2GO, since the authentication is lot lighter than gmail
- using a single external jar "base64coder.jar" to encore username and pwd (not sure it is really necessary with SMTP2GO)


Here is the code

public void sendingEmailUsingSocket() {
int port = 25;

try {
Socket socket = new Socket("176.58.103.10", port); // IP of mail.smtp2go.com

String username = Base64Coder.encodeString("mysmtp_loging");
String password = Base64Coder.encodeString("mysmtp_password");

DataOutputStream dos = new DataOutputStream(socket.getOutputStream());
DataInputStream isDI = new DataInputStream(socket.getInputStream());
BufferedReader is = new BufferedReader(new InputStreamReader(isDI));

// dos.writeBytes("EHLO "+ InetAddress.getLocalHost().getHostName() + "\r\n");
dos.writeBytes("EHLO 10.0.1.1\r\n");
dos.writeBytes("AUTH LOGIN");
dos.writeBytes("\r\n");
dos.writeBytes(username);
dos.writeBytes("\r\n");
dos.writeBytes(password);
dos.writeBytes("\r\n");
dos.writeBytes("MAIL FROM:<ev3.siva@gmail.com>\r\n");
dos.writeBytes("\r\n");
dos.writeBytes("RCPT TO: <frederic.siva@gmail.com>\r\n");
dos.writeBytes("DATA\r\n");
dos.writeBytes("Subject: Email test\r\n");
dos.writeBytes("Test using bare socket from EV3");
dos.writeBytes("\r\n.\r\n");
dos.writeBytes("QUIT\r\n");
dos.flush();

String responseline;

while((responseline = is.readLine())!=null) {
System.out.println("R = " + responseline);
}

is.close();
dos.close( );
socket.close( );
}
catch (IOException ex) {
System.out.println("ERROR");
System.out.println(ex);
ex.printStackTrace();
}
}


Improvements:
- do a DNS resolution on the SMTP server name.
- get rid of the Base64coder if not really necessary


I am so happy!


Return to “EV3 Software”

Who is online

Users browsing this forum: No registered users and 1 guest