• Post Reply Bookmark Topic Watch Topic
  • New Topic

Java mail error  RSS feed

 
Nee Kat
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am new to Java mail. I have just tried a program from the java mail tutorial but I am geeting this error:

Exception in thread "main" javax.mail.MessagingException: Could not connect to S
MTP host: localhost, port: 25;

I have tried connecting to the mail server using coldfusion and I was able to do it. Also I am able to ping it so it is not a connectivity issue.

There must be an error in which I have specified the parameters.

Please help

Thanks,
Nee
Here is the program:

import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.*;
public class MailExample {
public static void main (String args[]) throws Exception {
String host = "smtp.ems.att.com";
String from = "neekat@att.com";
String to = "neekat@att.com";

// Get system properties
Properties props = System.getProperties();

// Setup mail server

props.put("smtp.ems.att.com", host);

// Get session
Session session = Session.getDefaultInstance(props, null);

// Define message

MimeMessage message = new MimeMessage(session);

// Set the from address

message.setFrom(new InternetAddress("neerajkathuria@att.com"));

// Set the to address

message.addRecipient(Message.RecipientType.TO, new InternetAddress("neerajkathuria@att.com"));

// Set the subject

message.setSubject("Hello JavaMail");


// Set the content

message.setText("Welcome to JavaMail");

// Send message

Transport.send(message);
}
}
 
Arun Prasath
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You cant ping the smtp server and say its alive.
SMTP server runs on port 25 by default. For testing whether an smtp server is running or not, you can try using telnet.

"telnet smtp.server 25"

This tries to connect to port number 25.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you trying to connect via a proxy by any chance?
 
Jas Oberai
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Nee Kat,
I am using the same program and getting the same error exactly.Can you just let me know if you were able to resolve that problem.
Thanks.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!