Send an email with Nokia 6610

I need to send an email with Nokia 6610 from a Jar app.
I want to ask only smtp server,destination email and email text.
How can i do ?

Thanks

perhaps that :


import java.net.*;
import java.io.*;

public class sendElvisMail {
public static void main(String s[]) {
   //
   //  Send fake mail from Elvis Presley
   //
   //  sendElvisMail [mail server] [recipient address]
   //               mail server can be hostname or IP address
   //
   //   ex.  sendElvisMail mail.company.com myFriend@somewhere.qc.ca
   //
   sendElvisMail t = new sendElvisMail();
   t.sendMail(s[0], s[1]);
   }

public void sendMail(String mailServer, String recipient) {
   try {
      Socket s = new Socket(mailServer, 25);
      BufferedReader in = new BufferedReader
          (new InputStreamReader(s.getInputStream(), "8859_1"));
      BufferedWriter out = new BufferedWriter
          (new OutputStreamWriter(s.getOutputStream(), "8859_1"));

      send(in, out, "HELO theWorld");
      // warning : some mail server validate the sender address
      //           in the MAIL FROm command, put your real address here
      send(in, out, "MAIL FROM: <Elvis.Presley@jailhouse.rock>");
      send(in, out, "RCPT TO: " + recipient);
      send(in, out, "DATA");
      send(out, "Subject: In the ghetto");
      send(out, "From: Elvis Presley <Elvis.Presley@jailhouse.rock>");
      send (out, "\n");
      // message body
      send(out, "I'm alive. Help me!");
      send(out, "\n.\n");
      send(in, out, "QUIT");
      s.close();
      }
   catch (Exception e) {
      e.printStackTrace();
      }
   }

 public void send(BufferedReader in, BufferedWriter out, String s) {
   try {
      out.write(s + "\n");
      out.flush();
      System.out.println(s);
      s = in.readLine();
      System.out.println(s);
      }
   catch (Exception e) {
      e.printStackTrace();
      }
   }

 public void send(BufferedWriter out, String s) {
   try {
      out.write(s + "\n");
      out.flush();
      System.out.println(s);
      }
   catch (Exception e) {
      e.printStackTrace();
      }
   }

[quote]I need to send an email with Nokia 6610 from a Jar app.
I want to ask only smtp server,destination email and email text.
How can i do ?

Thanks
[/quote]
? Can you download extra JAR’s onto the phone ?

If so, Sun has an official email API (javax.mail.* and friends) which you can find and download from java.sun.com. The version I usually use is about 350k in two jar files which you just drop into the directory (or preferably into your JVM’s EXT directory) - which is probably way too big for you? :slight_smile:

With that API, your code ends up something like this (copied and pasted from a real project):


      Properties mailConfig = new Properties();

      mailConfig.put( "mail.smtp.host", "localhost" );
      
      // Any special options, special message type, attachments, etc
      Session mailSession = Session.getInstance( mailConfig, null );
      MimeMessage confirmationMessage = new MimeMessage( mailSession );

      confirmationMessage.setText( "Email body" );
      confirmationMessage.setSubject( "re: something important" );

      // TO and FROM addresses
      Address recipientAddress = new InternetAddress( "java@sun.com" );
      confirmationMessage.addRecipient( Message.RecipientType.TO, recipientAddress );
      confirmationMessage.setFrom( new InternetAddress( "blah@sun.com" ) );

      // send!
      Transport.send( confirmationMessage );

350k … bloat bloat :stuck_out_tongue:

Sadly, with MIDP you can’t just drop extra library JAR files into the phone. The platform (MIDP + optional APIs like JSR-120 SMS API) that the phone ships with is all you have: everything else must be included in the MIDlet’s own JAR file.

The Nokia 6610 is a ‘Series 40’ phone, not a Symbian ‘Series 60’ phone. As such it has a MIDlet JAR file size restriction of 64KB, so Blah’s Java Mail API JAR would be too big, even if it worked with the MIDP APIs (which it won’t).

And the sample code that vrm posted is J2SE code, and uses J2SE’s java.net API which is not available in MIDP. So that won’t work either, sorry.

The Nokia 6610 supports MIDP 1.0, so the only networking protocol it supports is HTTP (client only). To write an e-mail MIDlet you’ll have to connect over HTTP to a custom servlet (or CGI script, etc.), and write the custom servlet to use code like vrm’s to access the real mail server.

MIDP 2.0 (supported in Nokia 5140, 6230, 6600, 6620, 7610, 7700, 9500) optionally supports socket networking, and these Nokia implementations include this option. It uses the CLDC ‘Generic Connection Framework’ rather than the J2SE java.net APIs, so the socket code for those phones will be slightly different to vrm’s example J2SE code.