aspose file tools*
The moose likes Other JSE/JEE APIs and the fly likes java mail throws Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "java mail throws " Watch "java mail throws " New topic
Author

java mail throws

nothing vu
Greenhorn

Joined: Nov 13, 2008
Posts: 1
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
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19718
    
  20

"nothing vu",

Please read your private messages regarding an important announcement.

Thank you,

Rob


As for your problem, your exception says quite a lot:

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

Your mail server does not allow other PCs to send email to other domains. That's why it works from telnet - it's not relaying but sending itself.

You'll have to check your mail server configuration to solve this problem I'm afraid.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Mourouganandame Arunachalam
Ranch Hand

Joined: Oct 29, 2008
Posts: 396
As "Rob" mentioned, you (or your sys admin) need to check your SMTP server configuration for relaying.

Refer to this url for better understanding of mail relay.

Mourougan


Mourougan
Open Source leads to Open Mind
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java mail throws