• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

SocketException with JavaMail

 
Ranch Hand
Posts: 197
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm trying to write a simple java mail program to send only with the foll code



but i keep getting the following error:

 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is not a Servlet issue.
Moving to Other Java APIs where the Javamail savvy hang out.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Since you're trying to connect to "localhost", you must have a mail server under your control on your local machine. Can you connect to it using other means (e.g. a mail client)? Do any messages show up in its log files?
 
kwame Iwegbue
Ranch Hand
Posts: 197
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not trying to connect through local host. I would simply like to have simple application for sending email. I will later make it a servlet. can you pls help with some ideas.
 
Sheriff
Posts: 28370
99
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by kwame Iwegbue:
I'm not trying to connect through local host.

But the debug output from JavaMail says specifically

trying to connect to host "localhost", port 25

You need to set the "smtp.mail.host" property to the name or IP address of the computer where your SMTP server is running. Check with its administrator if you are not sure of what name or address you should be using.
 
kwame Iwegbue
Ranch Hand
Posts: 197
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
props.put("smtp.mail.host", host);

I thought this refers to the receipients smtp and host. for example when sending mail to someone with yahoo email, then should use props.put("smtp.yahoo.com", 'mail.yahoo.com');
or something like this
 
Paul Clapham
Sheriff
Posts: 28370
99
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No. It is the name of the server that YOU will be using to SEND e-mail messages.

So, before you spend any more time on this project, make sure that you have access to one. Talk to the administrator of the server to make sure that you can use it.
 
kwame Iwegbue
Ranch Hand
Posts: 197
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you paul.

so i guess from a regular desktop/private computer, that would be "localhost".
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by kwame Iwegbue:
Thank you paul.

so i guess from a regular desktop/private computer, that would be "localhost".


Yes, but you should ofcourse have mail server software running on your regular desktop/private computer (i.e., localhost) if you want to do that. If you don't have mail server software running, it's not going to work. Have a look at Apache Jakarta James for example, a free and open source mail server.

Originally posted by kwame Iwegbue:
props.put("smtp.mail.host", host);

I thought this refers to the receipients smtp and host. for example when sending mail to someone with yahoo email, then should use props.put("smtp.yahoo.com", 'mail.yahoo.com');
or something like this


No, it would be:

props.put("smtp.mail.host", "mail.yahoo.com");

if mail.yahoo.com is indeed an SMTP mail server that you can access.
[ January 16, 2006: Message edited by: Jesper de Jong ]
 
Paul Clapham
Sheriff
Posts: 28370
99
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by kwame Iwegbue:
so i guess from a regular desktop/private computer, that would be "localhost".

Probably not.

Here's how e-mail works. You give your e-mail message to a mail server and tell it who the recipients are. It finds their mail server, if it can, and between the two servers your message gets transferred from your server to the recipients' server.

Now here's the problem with that idea. All of those e-mail servers are accessible from the Internet. They have to be so that they can find each other and transfer messages. That means that anybody anywhere on the Internet can connect to any e-mail server and ask it to send a message to anybody else. This ability has been abused by people named "spammers" who use other people's servers to send out mass mailings that try to cheat people. So public e-mail servers won't let your program use them to send messages unless you have been pre-approved in some way.

In your case you don't have your own server. And even if you install your own server it probably isn't going to be trusted by other servers, for various technical reasons (I'm not writing an entire magazine article here). If you don't have access to an SMTP server that already exists, then you are wasting your time. If you are writing this program for a company, then that company should have an e-mail server that you can use. As I already said, you need to talk to the administrator of that server to get yourself approved to use it. But if you're just writing it for personal use, you are going to find it a lot more difficult to get access to a server.
 
kwame Iwegbue
Ranch Hand
Posts: 197
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank you paul.

I finally got a hold of my comapany's SMTP, and the app works now!!!
 
You get good luck from rubbing the belly of a tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic