Hi,
I have problem with sending email. This is the exception that I have:
connect true
javax.mail.SendFailedException: Sending failed;
nested exception is:
class javax.mail.SendFailedException: Invalid Addresses;
nested exception is:
class javax.mail.SendFailedException: 550 5.7.1 Unable to relay for
[email protected] After scratching my head many times, I can not figure out this problem.
This is the code I had so far:
public void postMail(
String recipients[ ], String subject,
String message , String from) throws MessagingException, IOException
{
boolean debug = false;
//Set the host smtp address
Properties props = new Properties(); props.put("mail.smtp.host", �198.162.0.9�);
Session session = Session.getDefaultInstance(props, null);
session.setDebug(debug);
// create a message
Message msg = new MimeMessage(session);
//SMTPMessage msg = new SMTPMessage(session);
// set the from and to address
InternetAddress addressFrom = new InternetAddress(from);
msg.setFrom(addressFrom);
InternetAddress[] addressTo = new InternetAddress[recipients.length];
for (int i = 0; i < recipients.length; i++)
{
addressTo[i] = new InternetAddress(recipients[i]);
}
msg.setRecipients(Message.RecipientType.TO, addressTo);
// Optional : You can also set your custom headers in the Email if you Want
msg.addHeader("MyHeaderName", "myHeaderValue");
// Setting the Subject and Content Type
msg.setSubject(subject);
msg.setContent(message, "text/plain");
msg.setSentDate(new Date());
System.out.println(msg.getSubject() + " content = " + msg.getContent().toString());
// Get a Transport object to send e-mail
Transport bus = session.getTransport("smtp");
// Connect only once here
// Transport.send() disconnects after each send
// Usually, no username and password is required for SMTP
bus.connect();
System.out.println(" connect "+ bus.isConnected());// it connects here
Transport.send(msg);
}
public static void main(String[] args){
String[] to = {"
[email protected]"};
String from = "
[email protected]";
String subject = "testProgramEmail";
String msg =" This is a test";
TestPostEmailMsg testMe = new TestPostEmailMsg();
try {
testMe.postMail(to, subject, msg, from);
}catch(MessagingException msgEx){
msgEx.printStackTrace();
}catch(IOException ioEx){
ioEx.printStackTrace();
}
}
I can telnet to the smtp server and send mail from there in or outside the domain but when I run the program,
It throws exception as above.
Would any one shred me a light
Sincerely,
thanks