aspose file tools*
The moose likes Other JSE/JEE APIs and the fly likes Java Mail Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "Java Mail Problem" Watch "Java Mail Problem" New topic
Author

Java Mail Problem

AmitDBond Sethi
Greenhorn

Joined: Jun 06, 2008
Posts: 11
Hi All, Here is my problem that is bugging me from last two days. I am experimenting a simple java mail program. The code snippet is as follows.
Properties props = System.getProperties();
// -- Attaching to default Session, or we could start a new one --
props.put("mail.smtp.host", smtpServer);
Session session = Session.getDefaultInstance(props, null);
// -- Create a new message --
Message msg = new MimeMessage(session);
// -- Set the FROM and TO fields --
msg.setFrom(new InternetAddress(from));
msg.setRecipients(Message.RecipientType.TO,
InternetAddress.parse(to, false));
msg.setSubject(subject);
msg.setText(body);
// -- Set some other header information --
msg.setHeader("X-Mailer", "LOTONtechEmail");
msg.setSentDate(new Date());
// -- Send the message --
Transport.send(msg);
System.out.println("Message sent OK.");


But I am getting the following exception.
javax.mail.MessagingException: [EOF]
at com.sun.mail.smtp.SMTPTransport.issueCommand(SMTPTransport.java:1481)
at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1512)
at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:1054)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:634)
at javax.mail.Transport.send0(Transport.java:189)
at javax.mail.Transport.send(Transport.java:118)

I have checked that the smtp server I am using is up and running and I am able to successfully ping that from my local machine. Could any one please please help me out. Thanks.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42591
    
  65
Welcome to JavaRanch.

Make sure that none of "to", "from", "subject" and "body" are empty.

JavaMail problems can often be tracked down by calling "session.setDebug(true)" first, which will lead to lots of debugging output (and the actual SMTP commands) being printed to standard output.


Ping & DNS - my free Android networking tools app
AmitDBond Sethi
Greenhorn

Joined: Jun 06, 2008
Posts: 11
All the fields are ok. Also i turned the debug on as suggested and I got the following recorded on the log.
454 5.7.3 Client does not have permission to submit mail to this server.
DEBUG SMTP: got response code 454, with response: 454 5.7.3 Client does not have permission to submit mail to this server.
It seems to be a problem with the smtp server that I am using, but it is the same server on which my outlook is configured.
Do I have any alternatives...
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42591
    
  65
The code you posted does not include authentication; does the mail server require it? Most servers do nowadays.
[ June 06, 2008: Message edited by: Ulf Dittmer ]
AmitDBond Sethi
Greenhorn

Joined: Jun 06, 2008
Posts: 11
I am not sure, but yes you are right the server might require the authentication and I donot know what are the user ID and password for the smtp server, I am using. Can I get any free smtp serve, which I can install on my machine and have this thing running.
I know it ssounds crazzy but I dont see any solution...
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

You can use James, which is an open source SMTP server.

Alternatively, you can use Dumbster as a good test harness.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42591
    
  65
Originally posted by AmitDBond Sethi:
I am not sure, but yes you are right the server might require the authentication and I donot know what are the user ID and password for the smtp server, I am using.

Earlier you said that Outlook works fine with this server. If the server requires authentication, you must have entered the username/password when setting up Outlook - checking its settings should at least reveal the username (if not the password).
NarayanaRao Konakalla
Greenhorn

Joined: Jan 29, 2008
Posts: 13
Hi
I am facing the same problem.
I am able to send and receive mails from the same sever, but when I write a java mail program to send mails I get an exception. I used authentication also. I set from address, to address and mail body content also.
Please help me with a solution for this.
Below are the debug statements and also please find the peice of code i used.


[4/17/09 15:28:27:609 IST] 0000002a SystemOut O mail body is Hi...
This is a test mail from IQN.
[4/17/09 15:28:29:703 IST] 0000002a SystemOut O DEBUG: setDebug: JavaMail version 1.3.1
[4/17/09 15:28:29:703 IST] 0000002a SystemOut O DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
[4/17/09 15:28:29:718 IST] 0000002a SystemOut O to address is kamal.lochanpanda@wipro.com
[4/17/09 15:28:29:718 IST] 0000002a SystemOut O to address is narayana.konakalla@wipro.com
[4/17/09 15:28:37:234 IST] 0000002a SystemOut O DEBUG SMTP: useEhlo true, useAuth false
[4/17/09 15:28:37:234 IST] 0000002a SystemOut O DEBUG SMTP: trying to connect to host "hostname", port 25

[4/17/09 15:28:37:250 IST] 0000002a SystemOut O 220 hostname ready Fri, 17 Apr 2009 15:26:04 +0530
[4/17/09 15:28:37:250 IST] 0000002a SystemOut O DEBUG SMTP: connected to host "hostname", port: 25

[4/17/09 15:28:37:250 IST] 0000002a SystemOut O EHLO D-149443
[4/17/09 15:28:37:250 IST] 0000002a SystemOut O 250-hostname Hello [10.150.100.96]
250-TURN
250-SIZE
250-ETRN
250-PIPELINING
250-DSN
250-ENHANCEDSTATUSCODES
250-8bitmime
250-BINARYMIME
250-CHUNKING
250-VRFY
250-X-EXPS GSSAPI NTLM LOGIN
250-X-EXPS=LOGIN
250-AUTH GSSAPI NTLM LOGIN
250-AUTH=LOGIN
250-X-LINK2STATE
250-XEXCH50
250 OK
[4/17/09 15:28:37:265 IST] 0000002a SystemOut O DEBUG SMTP: Found extension "TURN", arg ""
[4/17/09 15:28:37:265 IST] 0000002a SystemOut O DEBUG SMTP: Found extension "SIZE", arg ""
[4/17/09 15:28:37:265 IST] 0000002a SystemOut O DEBUG SMTP: Found extension "ETRN", arg ""
[4/17/09 15:28:37:265 IST] 0000002a SystemOut O DEBUG SMTP: Found extension "PIPELINING", arg ""
[4/17/09 15:28:37:265 IST] 0000002a SystemOut O DEBUG SMTP: Found extension "DSN", arg ""
[4/17/09 15:28:37:265 IST] 0000002a SystemOut O DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
[4/17/09 15:28:37:265 IST] 0000002a SystemOut O DEBUG SMTP: Found extension "8bitmime", arg ""
[4/17/09 15:28:37:265 IST] 0000002a SystemOut O DEBUG SMTP: Found extension "BINARYMIME", arg ""
[4/17/09 15:28:37:265 IST] 0000002a SystemOut O DEBUG SMTP: Found extension "CHUNKING", arg ""
[4/17/09 15:28:37:265 IST] 0000002a SystemOut O DEBUG SMTP: Found extension "VRFY", arg ""
[4/17/09 15:28:37:265 IST] 0000002a SystemOut O DEBUG SMTP: Found extension "X-EXPS", arg "GSSAPI NTLM LOGIN"
[4/17/09 15:28:37:265 IST] 0000002a SystemOut O DEBUG SMTP: Found extension "X-EXPS=LOGIN", arg ""
[4/17/09 15:28:37:265 IST] 0000002a SystemOut O DEBUG SMTP: Found extension "AUTH", arg "GSSAPI NTLM LOGIN"
[4/17/09 15:28:37:265 IST] 0000002a SystemOut O DEBUG SMTP: Found extension "AUTH=LOGIN", arg ""
[4/17/09 15:28:37:265 IST] 0000002a SystemOut O DEBUG SMTP: Found extension "X-LINK2STATE", arg ""
[4/17/09 15:28:37:265 IST] 0000002a SystemOut O DEBUG SMTP: Found extension "XEXCH50", arg ""
[4/17/09 15:28:37:265 IST] 0000002a SystemOut O DEBUG SMTP: Found extension "OK", arg ""
[4/17/09 15:28:40:734 IST] 0000002a SystemOut O in send
[4/17/09 15:28:42:500 IST] 0000002a SystemOut O after save changes
[4/17/09 15:28:43:484 IST] 0000002a SystemOut O DEBUG SMTP: use8bit false
[4/17/09 15:28:43:484 IST] 0000002a SystemOut O MAIL FROM:<narayana.konakalla@wipro.com>
[4/17/09 15:28:43:500 IST] 0000002a SystemOut O 454 5.7.3 Client does not have permission to submit mail to this server.



NarayanaRao Konakalla
Greenhorn

Joined: Jan 29, 2008
Posts: 13
Hi
The problem is solved after adding the line below.

props.put("mail.smtp.auth", "true");


Thanks.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java Mail Problem