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
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