javamail send error

P

priyom

Hi,

I am using javamail 1.4 API to send messages through a SMTP server.
The problem is I get the following error:

550 5.7.1 Unable to relay for (e-mail address removed)
(I have changed the actual address here-but it's a valid address)

Note: The Outgoing server requires authentication.
Probably I'm going wrong there...
Is there any way to verify if authentication has succeeded or not?

One more thing, there is no problem accessing Inbox - Incoming mail
(IMAP) works absolutely fine ...

Here is the code:



package Mail;

import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
import javax.swing.*;
import com.sun.mail.smtp.SMTPMessage;

// Send a simple, single part, text/plain e-mail
public class TestEmail {

public static void main(String[] args) {

String to = "(e-mail address removed)";
String from = "(e-mail address removed)";
String host = "a.b.c.d";//actual host string is entered here

// Create properties, get Session
Properties props = new Properties();

props.put("mail.smtp.host", host);
// To see what is going on behind the scene
props.put("mail.debug", "true");
Session session = Session.getInstance(props);

try {
// Instantiate a message
SMTPMessage msg = new SMTPMessage(session);

//Set message attributes
msg.setFrom(new InternetAddress(from));
InternetAddress[] address = {new InternetAddress(toBofa)};
msg.setRecipients(Message.RecipientType.TO, address);
msg.setSubject("Test E-Mail through Java");
msg.setSentDate(new Date());



// Set message content
msg.setText("This is a test of sending a " +
"plain text e-mail through Java.\n" +
"Here is line 2.");


// to enable authentication
Transport tr = session.getTransport("smtp");
String username="domain\username";//here actual domain and
username are entered
String password=JOptionPane.showInputDialog("Enter pwd for
"+username);

try {
System.out.println("Trying to connect...");
tr.connect(host, username, password);
System.out.println("Hopefully
connected..."+tr.toString());
}
catch (AuthenticationFailedException ex)
{
JOptionPane.showMessageDialog(null,"Transport connect
failed");
}
JOptionPane.showMessageDialog(null,"Authenticated");
msg.saveChanges();
tr.sendMessage(msg, msg.getAllRecipients());
tr.close();
// end of authentication snippet

}
catch (MessagingException mex) {
// Prints all nested (chained) exceptions as well
mex.printStackTrace();
}
}
}

Output:
DEBUG SMTP: trying to connect to host "a.b.c.d", port 25, isSSL false
220 <host string> Microsoft ESMTP MAIL Service, Version: 5.0.2195.6713
ready at Wed, 8 Feb 2006 08:31:49 -0600
DEBUG SMTP: connected to host "a.b.c.d", port: 25
..
..
..
..
MAIL FROM:<[email protected]>
250 2.1.0 (e-mail address removed)....Sender OK
RCPT TO:<[email protected]>
550 5.7.1 Unable to relay for (e-mail address removed)
DEBUG SMTP: Invalid Addresses
DEBUG SMTP: (e-mail address removed)
DEBUG SMTP: Sending failed because of invalid destination addresses
RSET
250 2.0.0 Resetting
 
N

Nigel Wade

priyom said:
Hi,

I am using javamail 1.4 API to send messages through a SMTP server.
The problem is I get the following error:

550 5.7.1 Unable to relay for (e-mail address removed)
(I have changed the actual address here-but it's a valid address)

Note: The Outgoing server requires authentication.
Probably I'm going wrong there...
Is there any way to verify if authentication has succeeded or not?

How is authentication configured on your mail server?

A client must only attempt authentication if the server offers it. This will be
done in response to an EHLO message sent by the client. The response to this
indicates the services offered by the mail server. If AUTH is not among them
then it is incorrect for the client to attempt authentication.

Some mail servers will offer AUTH on the normal SMTP port of 25 and some will
only offer it on the mail submission port, 587. You can find out using telnet
what services your mail server offers on those ports. Telnet to port 25 and
send it a EHLO request. If the response doesn't include AUTH then try the same
on port 587. If that does include AUTH then you need to modify your smtp
Transport connection set the port to 587. If neither include AUTH then you need
to contact Microsoft and ask them what non-standard authentication scheme they
have implemented for mail submission in Exchange/Outlook.
One more thing, there is no problem accessing Inbox - Incoming mail
(IMAP) works absolutely fine ...

That's an entirely different protocol, on a different port, for reading mail.
.....
Output:
DEBUG SMTP: trying to connect to host "a.b.c.d", port 25, isSSL false
220 <host string> Microsoft ESMTP MAIL Service, Version: 5.0.2195.6713
ready at Wed, 8 Feb 2006 08:31:49 -0600
DEBUG SMTP: connected to host "a.b.c.d", port: 25
.
.
.
.
MAIL FROM:<[email protected]>
250 2.1.0 (e-mail address removed)....Sender OK
RCPT TO:<[email protected]>
550 5.7.1 Unable to relay for (e-mail address removed)
DEBUG SMTP: Invalid Addresses
DEBUG SMTP: (e-mail address removed)
DEBUG SMTP: Sending failed because of invalid destination addresses
RSET
250 2.0.0 Resetting

You've missed out the interesting bits...
 
P

priyom

The port connection requires port 25.
I connect using LAN
In Microsoft Outlook, Email accounts->More Settings->Outgoing Server
Tab->"Outgoing server requires authentication" Chk Box is checked
"Log on using" Radio btn is selected and my username/password
(different from login) are entered

The interesting bits I missed out:
Hope this helps
Looking forward to your response...

EHLO <My computer name>
250-<server name> Hello [<some address>]
250-TURN
250-ATRN
250-SIZE 20480000
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-XEXCH50
250-X-LINK2STATE
250 OK
DEBUG SMTP: Found extension "TURN", arg ""
DEBUG SMTP: Found extension "ATRN", arg ""
DEBUG SMTP: Found extension "SIZE", arg "20480000"
DEBUG SMTP: Found extension "ETRN", arg ""
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "DSN", arg ""
DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
DEBUG SMTP: Found extension "8bitmime", arg ""
DEBUG SMTP: Found extension "BINARYMIME", arg ""
DEBUG SMTP: Found extension "CHUNKING", arg ""
DEBUG SMTP: Found extension "VRFY", arg ""
DEBUG SMTP: Found extension "X-EXPS", arg "GSSAPI NTLM LOGIN"
DEBUG SMTP: Found extension "X-EXPS=LOGIN", arg ""
DEBUG SMTP: Found extension "AUTH", arg "GSSAPI NTLM LOGIN"
DEBUG SMTP: Found extension "AUTH=LOGIN", arg ""
DEBUG SMTP: Found extension "XEXCH50", arg ""
DEBUG SMTP: Found extension "X-LINK2STATE", arg ""
DEBUG SMTP: Found extension "OK", arg ""
 
G

Gordon Beaton

I am using javamail 1.4 API to send messages through a SMTP server.
The problem is I get the following error:

550 5.7.1 Unable to relay for (e-mail address removed)
(I have changed the actual address here-but it's a valid address)

The fact that your address is valid is not sufficient, since a
correctly configured mail server will only accept mail to or from its
own mail domain.

This is to prevent senders outside the domain from using the server to
"relay" mail to recipients who are also outside the domain.

At leat one of the addresses (to or from) must belong to a domain that
the server is willing to relay for (e.g. its own domain).

/gordon
 
P

priyom

"The fact that your address is valid is not sufficient, since a
correctly configured mail server will only accept mail to or from its
own mail domain."
-What I meant was it's not an address problem. I am in the same domain,
connecting through LAN and trying to send a mail to myself, which I
presume would be in the same domain (I do have an ID created in the
domain with send capability)
 
N

Nigel Wade

priyom said:
The port connection requires port 25.
I connect using LAN
In Microsoft Outlook, Email accounts->More Settings->Outgoing Server
Tab->"Outgoing server requires authentication" Chk Box is checked
"Log on using" Radio btn is selected and my username/password
(different from login) are entered

The interesting bits I missed out:
Hope this helps
Looking forward to your response...

EHLO <My computer name>
250-<server name> Hello [<some address>] ....
250-X-EXPS GSSAPI NTLM LOGIN
250-X-EXPS=LOGIN
250-AUTH GSSAPI NTLM LOGIN
250-AUTH=LOGIN ....
DEBUG SMTP: Found extension "X-EXPS", arg "GSSAPI NTLM LOGIN"
DEBUG SMTP: Found extension "X-EXPS=LOGIN", arg ""
DEBUG SMTP: Found extension "AUTH", arg "GSSAPI NTLM LOGIN"
DEBUG SMTP: Found extension "AUTH=LOGIN", arg ""
DEBUG SMTP: Found extension "XEXCH50", arg ""
DEBUG SMTP: Found extension "X-LINK2STATE", arg ""
DEBUG SMTP: Found extension "OK", arg ""


Ok, so it is advertising AUTH on port 25. That should allow the client to
attempt authentication. Now you need to find out if it being attempted. Unless
the debug info includes whether auth was attempted, and succeeded, it won't be
simple.

For this type of problem I generally use a network sniffer such as Ethereal.
This allows you to capture the packets sent and received by your computer, and
look at both sides of the conversation to see what is actually being sent over
the wire. If you are ok to do this, I would recommend you install Ethereal and
use that. You can find it at http://www.ethereal.com/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,062
Latest member
OrderKetozenseACV

Latest Threads

Top