Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

javax.mail.MessagingException : Could not connect to SMTP host : mysmtpadd.com, port : 25

Posted on 2011-03-25
12
Medium Priority
?
1,284 Views
Last Modified: 2013-11-24
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.


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);
            }
        }
    }
}

Open in new window

Error.doc
0
Comment
Question by:meeramt
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 5
12 Comments
 
LVL 92

Expert Comment

by:objects
ID: 35219052
looks like the mail server isn't listening on port 25
try 465, or check what port the mail server is actually using
0
 
LVL 92

Expert Comment

by:objects
ID: 35219130
587 is another to try
0
 

Author Comment

by:meeramt
ID: 35221596
Mail properites on outlook is showing 25 as port...
Tried with both the ports but getting the same error.. :-(
0
Simplify Your Workload with One Tool

How do you combat today’s intelligent hacker while managing multiple domains and platforms? By simplifying your workload with one tool. With Lunarpages hosting through Plesk Onyx, you can:

Automate SSL generation and installation with two clicks
Experience total server control

 
LVL 92

Expert Comment

by:objects
ID: 35224018
does you network use a proxy
0
 

Author Comment

by:meeramt
ID: 35225591
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..
0
 
LVL 92

Expert Comment

by:objects
ID: 35225596
thats strange. Is outlook running on the same box
and do you have any firewalls
0
 

Author Comment

by:meeramt
ID: 35225601
outlook is running on same machine n firewall is turned off..
0
 

Accepted Solution

by:
meeramt earned 0 total points
ID: 35231016
There was a problem in my mail server so was not able to connect.. thanks a lot for the help...
0
 

Author Comment

by:meeramt
ID: 35231049
closing d question..
0
 

Author Comment

by:meeramt
ID: 35231519
closing this question as issue has been resolved.. thanks everyone for their time n opnion..
0
 
LVL 92

Expert Comment

by:objects
ID: 35236288
> 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
0
 

Author Closing Comment

by:meeramt
ID: 35304190
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...
0

Featured Post

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question