[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 182
  • Last Modified:

problem sending email via java

Hi experts:

I have a java jar file that got automatically kicked off at scheduled times.  Each time the program finishes it job it sends out emails to a group of people on the mailing list. It has been working well until last week when I stop getting the mails. The strange thing is everybody else is still getting the mails except for me.
 I changed to a new PC and thus new Outlook Express last week. But I don't think that's the reason because I still got mails in the first a couple of days and I've checked no mails get to my account on the mail server.

I wrote a small class file in the same package to test sending a mail to myself and I got the following error:
javax.mail.MessagingException: Could not connect to SMTP host: <our mail server>, port 25;

I think port 25 is blocked by some firewall of our LAN because I tried telnet to the mail server using port 25 on several machines and failed.

There's no where in my code specifying port number and the program has been working fine and still is for everybody else.

What's going on?
0
sdc248
Asked:
sdc248
  • 12
  • 8
  • 8
  • +1
3 Solutions
 
colr__Commented:
If its windows and a new machine check wether your windows firewall has been turned on. If so, try turnign it off and retrying the connection.

colr__
0
 
colr__Commented:
Is the jar file running on your own machine, or on a server?

If it is working ok with everyone else, and the only thing that has changed in your network is your own machine, Id bet its an issue with your new setup.

What email API are you using?

colr__
0
 
Giant2Commented:
>The strange thing is everybody else is still getting the mails except for me.

Where the mail job take the address?
It could be some corruption on your only address, maybe.

Hope this could help you.
Bye, Giant.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
sdc248Author Commented:
The jar file is running on a server.

Firewall on my pc is turned off. I don't know how to check the Windows 2000 server. But both machine can't telnet with port 25.

I use javax.mail and javax.activation. Code is like below:

public static void sendEmail(String title, String content, String[] mailingList) {
            
try {
      Address[] addresses_to = new InternetAddress[mailingList.length];
                  
      for (int i=0; i<mailingList.length; i++) {
            addresses_to[i]= new InternetAddress(mailingList[i]);
      }
                        
      Properties props = new Properties();
      props.put("mail.host", "<our mail server>");
                  
      Session mailConnection = Session.getInstance(props, null);
      Message msg = new MimeMessage(mailConnection);      
      Address sender = new InternetAddress ("<accountID>", "system");
      msg.setContent(content, "text/plain");
      msg.setFrom(sender);
      msg.setRecipients(Message.RecipientType.TO, addresses_to);
      msg.setSubject(title);
                  
      Transport.send(msg);
                              
      System.out.println("email sent.");

} catch (Exception e) {
      e.printStackTrace();
      System.out.println("fail to send email.");
}
}
0
 
Giant2Commented:
If before suggest doesn't work, try to access your e-mail througth the net (I believe your e-mail server has an http access). If you see the mail, the problem is on your machine (firewall, like colr_ told you before, or net unaccessible).
Try to see your net.

Bye, Giant.
0
 
sdc248Author Commented:
My email address on the mailing list is fine...
0
 
Giant2Commented:
>But both machine can't telnet with port 25.
And are they answering to a ping?
0
 
sdc248Author Commented:
I checked my mails through the web, no mails on it. They didn't make it there.
0
 
sdc248Author Commented:
ping the mail server? yes.
0
 
Giant2Commented:
On the sender e-mail box do you see any error message?
0
 
Giant2Commented:
>I have a java jar file that got automatically kicked off at scheduled times...
>...The strange thing is everybody else is still getting the mails except for me...
>...I checked my mails through the web, no mails on it...
In your e-mail box there is nothing, so the e-mail to you doesn't start. So you must see some return error on your java jar program or in the e-mail box it uses to send e-mail.
0
 
sdc248Author Commented:
no..
0
 
Giant2Commented:
If no error, I think your e-mail was removed from the mailing list.
0
 
sdc248Author Commented:
I meant no error mesages came to the sender mail box.

As to java error message, see the question.
0
 
Giant2Commented:
But other e-mail (to other member of mailing list) are sent, isn't it?
0
 
colr__Commented:
Did you say you can't telnet into the server from ANY of the machine, even those that are recieving the email notification ok?

If this is the case, go to the server itself, and try telneting to localhost on port 25 to make sure the server is running ok. Can you manually send an email to your address via telnet? http://www.rdpslides.com/webresources/FAQ00035.htm.

colr__
0
 
sdc248Author Commented:
I can't telnet the mail server with port 25 on ANY machine including the application server.  But I can do it with port 8025. I just tested sending an email to myself through port 8025 and it works.

So what should I do next? Any way to set port number in my java code? I wonder how to do this safely since right now at least the true "clients" of the java program are getting mails...
0
 
colr__Commented:
If the rest of the clients are recieving the emails ok, then the port settings must be setup ok, otherwse none of you would be getting the emails.

Have you configured your outlok instalation to use port 8025 instead of the standard smtp port of 25 (which it uses by default, unless specified otherwise)?

colr__
0
 
colr__Commented:
In outlook express, go to the properties of the email acocunt. Click the advanced tab and check that SMTP is 8025.

colr__
0
 
sdc248Author Commented:
There's no account set up in Outlook or Outlook Express on the server. As to my PC, yes, I changed that this morning and now my Outlook Express is able to send/receive mails. But the problem is the mails from java never made it to the mail server, right?
0
 
colr__Commented:
No need for that, I'm trying to help.

What I was saying was that if the java program is succesfully sending to the other clients, then it must have the port number set correctly, so it must be something to do with your specific email address. Is this correct?

colr__
0
 
sdc248Author Commented:
Yes, I totally agree. Sorry if what I just said sounded offensive I didn't mean to.
0
 
sdc248Author Commented:
:>
0
 
Mayank SAssociate Director - Product EngineeringCommented:
You can set the "mail.smtp.port" property to 8025 in your code:

http://java.sun.com/products/javamail/javadocs/com/sun/mail/smtp/package-summary.html
0
 
Mayank SAssociate Director - Product EngineeringCommented:
Oh, sorry, didn't notice: >> "rest of the clients are recieving the emails ok"
0
 
colr__Commented:
I'm stumped I'm afraid.
colr__
0
 
Giant2Commented:
I think again:
>If no error, I think your e-mail was removed from the mailing list.
0
 
sdc248Author Commented:
Hi guys:

Mistery resolved.  The users have given me wrong information. They didn't notice that the mails from "notifications" account have stopped coming in until today. ="=   That is, NO BODY is receiving the mails from the application server.

I haven't been able to confirm with the guys who administrate our network, but to me it's quite obvious that they have done something (probably installing a firewall?) that blocks our network from connecting port 25. I could either have them open the port for the server, which I would prefer, or modify my code as mayankeagle suggests.

Sorry for the confusions, guys. Thank you for bearing with me and trying to help.
0
 
sdc248Author Commented:
I wish I could add more points to this question. I have learned a lot from this process.
0
 
colr__Commented:
Glad to help ;)

colr__
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 12
  • 8
  • 8
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now