Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Mail problems  RSS feed

 
Ben Roy
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I really don't know all that much about this, but here's what's going on. I had written some code that I'm pretty sure worked. It looked like this:
//Set up an internet address
InternetAddress iAddy = new InternetAddress();
iAddy.setAddress(rcptEmail);
//set up some mail properties
Properties props = System.getProperties();
props.put("mail.transport.protocol", "smtp.my.com");
Session session = Session.getInstance(props, null);
//create a message
MimeMessage myMessage = new MimeMessage(session);
myMessage.setFrom(new InternetAddress("me@my.com"));
myMessage.setSubject("Some subject");
myMessage.setText("Some message text");
myMessage.setRecipient(Message.RecipientType.TO,iAddy);
//send the message
Transport.send(myMessage);
I try to use this now, and I get an error saying "Could not connect to SMTP host: localhost, port: 25;" This has me really confused. I don't know why it's trying to connect to localhost instead of smtp.my.com. The code before was in an EJB, and this is in a regular java class, which I realized could be the problem. Anyway, if someone can please help me out with a suggestion of how to get this to work, I would be most grateful.
NOTE: The problem has nothing to do with DNS, etc. I used fake addresses here on purpose.
 
Ben Roy
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bleh! I've been searching the docs for an hour+ and digging through all my old code from the last project...5 mins after I post here I finally find it. I must have an old copy of my code, because I don't see how that ever could have worked.
Correct is:
props.put("mail.smtp.host", "smtp.my.com");
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!