• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Jj Roberts
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Himai Minh
  • Carey Brown
  • salvin francis

java mail throws

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 22037
108
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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.
 
Ranch Hand
Posts: 398
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic