Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

send email

 
Leandro Coutinho
Ranch Hand
Posts: 423
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Rob Spoor
Sheriff
Pie
Posts: 20550
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Leandro Coutinho
Ranch Hand
Posts: 423
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20550
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 368
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
Leandro Coutinho
Ranch Hand
Posts: 423
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Satya. :]
 
Leandro Coutinho
Ranch Hand
Posts: 423
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic