meeramt
asked on
javax.mail.MessagingException : Could not connect to SMTP host : mysmtpadd.com, port : 25
I am getting an error while sending the mail from my java application
I have attached the error document. Please help soon.
Thanks in advance.
I have attached the error document. Please help soon.
Thanks in advance.
import java.util.Properties;
import javax.activation.*;
import javax.mail.Authenticator;
import javax.mail.Message;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.AddressException;
import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
public class Mail {
public static void main(String[] args) {
try {
new Email().sendSimpleMail("Test from Java", "meerapkotecha@gmail.com", "info@milindvthakkar.com", "Testing...");
}
catch(Throwable e) {
e.printStackTrace();
}
}
public static class Email {
public void sendSimpleMail(String subject, String to, String from,String messageText) throws AddressException, MessagingException {
Properties mailProps = new Properties();
mailProps.put("mail.transport.protocol", "smtp");
mailProps.put("mail.smtp.starttls.enable", "true");
mailProps.put("mail.smtp.host", "mail.milindvthakkar.com");
mailProps.put("mail.smtp.auth", "true");
mailProps.put("mail.smtp.user", "info@milindvthakkar.com");
mailProps.put("mail.debug", "true");
mailProps.put("mail.smtp.port", "25");
mailProps.put("mail.smtp.debug", "true");
Authenticator auth = new MailAuthenticator();
Session session = Session.getDefaultInstance(mailProps, auth);
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.setRecipient(Message.RecipientType.TO, new InternetAddress(to));
message.setSubject(subject);
message.setContent(messageText, "text/html");
Transport.send(message);
}
private class MailAuthenticator extends javax.mail.Authenticator {
public PasswordAuthentication getPasswordAuthentication() {
String user = "info@milindvthakkar.com";
String pwd = "abcd";
return new PasswordAuthentication(user, pwd);
}
}
}
}
Error.doc
587 is another to try
ASKER
Mail properites on outlook is showing 25 as port...
Tried with both the ports but getting the same error.. :-(
Tried with both the ports but getting the same error.. :-(
does you network use a proxy
ASKER
no.. it does not use any proxy.. the mail server is accessed through internet only.. we do not use any proxy to connect to it..
thats strange. Is outlook running on the same box
and do you have any firewalls
and do you have any firewalls
ASKER
outlook is running on same machine n firewall is turned off..
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
closing d question..
ASKER
closing this question as issue has been resolved.. thanks everyone for their time n opnion..
> but experts confirmed that there is not problem in the code so checked the connectivity...
so award them points for helping. We have no way of knowing you have connectivity issues
so award them points for helping. We have no way of knowing you have connectivity issues
ASKER
I was facing the error because of server issue at my end... but experts confirmed that there is not problem in the code so checked the connectivity...
try 465, or check what port the mail server is actually using