×

Discussion Board

Results 1 to 9 of 9

Thread: sending email

  1. #1
    Regular Contributor
    Join Date
    Aug 2005
    Posts
    204

    sending email

    Hi
    I look for information about sending an email via j2me.
    is it possible ???
    how ?
    any links / examples / tutorials will help me a lot ,

    Thank you very much :-)

  2. #2
    Regular Contributor
    Join Date
    Jan 2004
    Posts
    82

    Re: sending email

    Yes it's possible.
    Implement the SMTP protokoll using a SocketConnection.

  3. #3
    Regular Contributor
    Join Date
    Aug 2005
    Posts
    204

    Re: sending email

    Thanks
    do you know where I can find information about this implementation ?

  4. #4
    Regular Contributor
    Join Date
    Aug 2005
    Posts
    204

    Re: sending email

    I found an example using a Socket and converted it into SocketConnection ,
    the problem is that I cant open the Socket :
    String url = "mail.company.com:25"; // also tried "socket://mail.company.com:25" ...
    mailSocket= (SocketConnection)Connector.open(url); // here I get an exception
    do you know what I should change here ?

    Thanks

  5. #5
    Nokia Developer Champion
    Join Date
    Mar 2005
    Location
    Paris
    Posts
    814

    Re: sending email

    ...
    ok, let's see
    make can you change here ?
    the name of the variables ? or may be the classes used ?
    ok, that's just easier
    you need to change the url to make it point on an SMTP server that will accept your connection (which is not so easy)
    if you don't know one you can use, you can install one on your computer, and use your IP as url, if you don't have a dynamic IP.
    basically that's it

    may be you can post the rest of your code so that we check what is to be changed and adapted to your situation

  6. #6
    Regular Contributor
    Join Date
    Aug 2005
    Posts
    204

    Re: sending email

    Thank you njzk2
    below is the rest of the code.
    I don't understand what you mean about an smtp server which would accept my connection.
    if it is a valid smtp server it should accept requests , shouldn't it ?

    Code:
    private void processRequest() throws Exception
    {
    	Date date=new Date();
    	PrintStream out=null;
    	String line = null;
    	DataInputStream in=null;
    	SocketConnection  MailSocket=null;
    	//attach to the server
    	try
            {
    		String url = "mail.company.com:25"; // also tried "socket://mail.company.com:25" ...
    		SocketConnection sc = null;
    		InputStream is = null;
    		MailSocket= (SocketConnection)Connector.open(url);
    		dbgInfo.append("Connector.open");
            }
    	catch(Exception e){}
    	//get an output stream
    	try{out =  new PrintStream(MailSocket.openOutputStream());
    	catch (Exception e){}
    	try{in=new DataInputStream(MailSocket.openInputStream());}
    	catch (Exception e){}
    	//read the server greeting
    	try{line=in.readUTF();}
    	catch (Exception e){}
    	//check each response
    	out.println("HELO emc");
    	//read the response
    	try{line=in.readUTF();}
    	catch (Exception e){}
    	//say who the mail is from
    	out.println("MAIL FROM: <me@net.com>");
    	//read the response
    	try{line=in.readUTF();}
    	catch (Exception e){}
    	//say who it is to
    	out.println("RCPT TO: <me@net.com>" );
    	//read the response
    	try{line=in.readUTF();}
    	catch (Exception e){}
    	//data about to come
    	out.println("DATA");
    	//see what the server says
    	try{line=in.readUTF();}
    	catch (Exception e){}
    	//send the contents passed in and heading information
    	out.println("Date: "+date.toString());
    	out.println("From:Me ");
    	out.println("To:Me ");
    	out.println("Subject: This is the subject");
    	out.println(" ");
    	out.println("bla bla bla");
    	out.println(".");
    	//should be 250 ok, as per the RFC
    	try{line=in.readUTF();}
    	catch (Exception e) {}
    	//disconnect
    	out.println("QUIT");
    	try{line=in.readUTF();}
    	catch (Exception e){}
    	//close connection
    	try{in.close(); MailSocket.close();}
    	catch (Exception e){}
    	out.close();
    }

  7. #7
    Nokia Developer Champion
    Join Date
    Mar 2005
    Location
    Paris
    Posts
    814

    Re: sending email

    basically, that's it
    you need to specifiy your smtp, then replace FROM : me@net.com by the email address you use as sender, and TO : me@net.com by the address you want to send the mail to.
    then the mail.company.com should be replaced by the smtp server's url, which should look like that actually
    not any smtp will accept your connection, for example in an enterprise, it will usually accept only connetion from the inside, and for a isp, it will accept connections from a group of IPs that are the suscribers' IPs. (for example, you can use aol smtp, which might be smpt.aol.com or mail.aol.com, only if aol is your isp and that your are conneting for the computer with the one you use this internet connection, and not from anywhere else in the world).

    that's what i mean about an smtp server which would accept your connection

    later on, you might find out that on some smtps you will need authentification, but i don't know exactlly how to do that (should be something like loginassword@mail.company.com, like for an ftp connection)

  8. #8
    Regular Contributor
    Join Date
    Aug 2005
    Posts
    204

    Re: sending email

    Thanks
    lets say that I find a compatable SMTP server ,
    lets say the server is mail.aaa.com
    what should be the format in the url var ?
    "socket://mail.aaa.com" ?
    "socket://mail.aaa.com:25" ?
    "smtp.aaa.com:25" ?
    something else ?

  9. #9
    Nokia Developer Champion
    Join Date
    Mar 2005
    Location
    Paris
    Posts
    814

    Re: sending email

    the third one should be ok, but the second is probably better

Similar Threads

  1. Sending an image over email
    By jeclarim in forum Symbian
    Replies: 3
    Last Post: 2006-12-15, 20:25
  2. Email Sending Progress
    By mew1979 in forum Symbian
    Replies: 0
    Last Post: 2005-04-13, 16:15
  3. Sending Email over GPRS
    By pankajmahto in forum Symbian
    Replies: 0
    Last Post: 2004-07-29, 07:48
  4. sending email with midp device
    By doggett78 in forum Mobile Java Networking & Messaging & Security
    Replies: 1
    Last Post: 2003-10-31, 13:57
  5. Sending Email from SMS - Urgent
    By chiradeep_basu in forum General Messaging
    Replies: 1
    Last Post: 2002-09-23, 00:35

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •