Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Richard Torres   on Apr 22 In Java Category.

  
Question Answered By: Shaun Thomas   on Apr 22

I have a problem in j2ee, I'm doing a project writing an email

system, when i want to send a mail, I have this error:


java.rmi.UnexpectedException: Unexpected exception in

examples.mailHelper.sendMail():
javax.mail.SendFailedException: Sending failed;
nested exception is:
javax.mail.SendFailedException: Invalid Addresses;
nested exception is:
javax.mail.SendFailedException: 550 5.7.1 Unable to relay
for
abs@localhost

this is my method for sending mail:

public void sendMail(messageVO msgVO) throws Exception
{

System.out.println("1");
javax.naming.InitialContext ctx = new

javax.naming.InitialContext();
System.out.println("2");
javax.mail.Session mail_session = (javax.mail.Session)

ctx.lookup("MyMailSession");
System.out.println("3");
/* java.util.Properties props = new java.util.Properties();
props.put("mail.smtp.host", "localhost");
props.put("mail.smtp.port", ""+25);
Session session = Session.getDefaultInstance(props,
null);
*/

MimeMessage msg = new MimeMessage(mail_session);
System.out.println("4");
msg.setRecipients(Message.RecipientType.TO,

InternetAddress.parse(msgVO.toAddress_VO));
System.out.println("5");
msg.setFrom(new InternetAddress(msgVO.fromAddress_VO));
System.out.println("6");
msg.setSubject(msgVO.messageSubject_VO);
System.out.println("7");
msg.setText(msgVO.messageBody_VO);
System.out.println("8");
Transport.send(msg);
System.out.println("9");

Store store = mail_session.getStore();
System.out.println("10");
store.connect();
System.out.println("11");
Folder f = store.getFolder("Sent");
System.out.println("12");
if (!f.exists()) f.create(Folder.HOLDS_MESSAGES);
System.out.println("13");
f.appendMessages(new Message[] {msg});
System.out.println("14");

mailSessionHome mailSesHome = (mailSessionHome)

lookUp.lookUpHome
("ejb.mailSessionRemoteHome",mailSessionHome.class );
mailSessionRemote mailSes = mailSesHome.create();

mailFolderVO mailFldVO = mailSes.findOrCreateOutbox();
mailSes.saveMessage(mailFldVO,msgVO);

}

Share: 

 

This Question has 9 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on Read and write data on a smart card Or get search suggestion and latest updates.


Tagged: