nothing vu

Greenhorn
+ Follow
since Nov 13, 2008
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by nothing vu

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 chungcongvu@gmail.com

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 = {"chungcongvu@gmail.com"};
String from = "chung.vu@mydomain.com";
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
12 years ago