aspose file tools*
The moose likes Sockets and Internet Protocols and the fly likes send email Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "send email" Watch "send email" New topic
Author

send email

Leandro Coutinho
Ranch Hand

Joined: Mar 04, 2009
Posts: 417
This code is from the book Just Java 2 6th edition.


The original code doesn't contain EHLO. But it was given an error: Use HELO/EHLO first, so I put in front of all println calls.
Now it shows the following:
F:\dev\java>java email
220 smtp.my_isp.com ESMTP
250-SRVMGZ01-JFA.my_isp.com
250-PIPELINING
250-SIZE 10240000

What am I doing wrong? How can I send email?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42274
    
  64
How can I send email?

By using the JavaMail API which handles all these details and much more for you. The http://faq.javaranch.com/java/JavaEnterpriseEditionFaq has lots of links to tutorials and example code.


Ping & DNS - my free Android networking tools app
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19718
    
  20

A bit surprising that Ulf didn't mention this (as he usually is the first one to do so ), but don't println to a socket.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Leandro Coutinho
Ranch Hand

Joined: Mar 04, 2009
Posts: 417
Rob Prime wrote:A bit surprising that Ulf didn't mention this (as he usually is the first one to do so ), but don't println to a socket.

Thank you!
So I think Peter van der Linden didn't test on Mac

I was able to send email using JavaMail. I used gmail smtp and worked.
But I would like to send email using socket. Just to learn.

Is it possible to send email with the code I posted? If yes, so what do I need to change to make it work?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19718
    
  20

There are 4 things you need to specify:
- from address
- to address(es)
- subject
- body

There are commands for each of these (recv or something for the to) but I can't really remember the commands for starting these. Perhaps Google can help you out.
Satya Maheshwari
Ranch Hand

Joined: Jan 01, 2007
Posts: 368
Ulf Dittmer wrote:
How can I send email?

By using the JavaMail API which handles all these details and much more for you. The http://faq.javaranch.com/java/JavaEnterpriseEditionFaq has lots of links to tutorials and example code.


Here's some sample code for using Java Mail Api



Thanks and Regards
Leandro Coutinho
Ranch Hand

Joined: Mar 04, 2009
Posts: 417
Thanks Satya. :]
Leandro Coutinho
Ranch Hand

Joined: Mar 04, 2009
Posts: 417
Leandro Coutinho wrote:
Rob Prime wrote:A bit surprising that Ulf didn't mention this (as he usually is the first one to do so ), but don't println to a socket.

Thank you!
So I think Peter van der Linden didn't test on Mac

Peter mentions this issue later in the chapter. I don't want to be unfair with the author. It's an excellent book by the way.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: send email