• 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
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Liutauras Vilda
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Piet Souris

EMail program Java-Connection

 
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
I tried to send a message through  Java Created EmailProgram  But
the connection is to be obtaiiined as you can see the following error
Please help
Thanks
As
CRMK




**********************************************
[code]
Exception in thread "main" java.net.ConnectException: Connection refused: connec
t
       at java.net.DualStackPlainSocketImpl.connect0(Native Method)
       at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketI
mpl.java:79)
       at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.ja
va:350)
       at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocket
Impl.java:206)
       at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java
:188)
       at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
       at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
       at java.net.Socket.connect(Socket.java:589)
       at java.net.Socket.connect(Socket.java:538)
       at java.net.Socket.<init>(Socket.java:434)
       at java.net.Socket.<init>(Socket.java:211)
       at MailMessage.connect(MailMessage.java:280)
       at MailMessage.<init>(MailMessage.java:110)
       at MailMessage.main(MailMessage.java:370)
*****************************************
[/code}
 
Bartender
Posts: 1868
81
Android IntelliJ IDE MySQL Database Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are a few too many unknowns at this point in time so maybe you can answer a few questions?
  • Connection refused could be because the email server that you are using did not like you trying to connect at that point in time. Are you 100% that the email server is working as correctly?
  • Are you sure that the account which you are using to connect to the mail server is a valid account?
  • Are you able to provide us with the code that is connecting to the email server?
  • Are you able to provide us with the code that is trying to send out the email message?

  • It can be helpful to the rest of us if you use the codetags (https://coderanch.com/wiki/659781/Code-Tags) and good indentation when posting code.
    It can be helpful to use the Preview button, which is just left of the Submit button to verify that your post looks proper and sound the way you want it to.
    I use the Preview button all of the time, which helps me cut down on mistakes.
     
    Ranch Hand
    Posts: 218
    5
    MS IE Notepad Suse
    • Likes 1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hi Comal,
    as I'm a bit more into the whole topic about java and e-mail I can give you some input:

    It seems you're tryin to connect to the server directly instead of use java mail api. I recommend you to use it. It handles many things for you so you don't have to speak smtp to the target server directly.
    So I guess your code some looks some like this:


    Rather strange your Source is over 370 lines long but the very basics doesn't work.

    There're a couple of reasons the connection is refused:

    - You're tryin to directly connect to the target SMTP server - and maybe this connection gets refused cause the server only accepts connections from other "registered" SMTP servers but refuses connections from private IP ranges - simple spam protection.
    - If you're try to connect to a SMTP server of your mail provider - you maybe try to connect to the wrong port. A SMTP server usualy has following ports opened:
    TCP/25 - to receive mails from other SMTP servers - normaly plain unencrypted - but could also provide STARTTLS feature
    TCP/465 - to accept mail-submission from registered clients - secured by socket level TLS
    TCP/587 - same as above - but mostly used with STARTTLS command instead of socket level TLS

    Here's a sample:

    Obviously you need java mail api in your classpath to compile and run.
    Try to get my sample working - and post stacktraces if you encounter exceptions so we can narrow down the problem.

    Hope it helps in any way.

    Matt
     
    Comal Rajagopalaratnam Muthukumar
    Ranch Hand
    Posts: 401
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Matt Wong wrote:Hi Comal,
    as I'm a bit more into the whole topic about java and e-mail I can give you some input:

    It seems you're tryin to connect to the server directly instead of use java mail api. I recommend you to use it. It handles many things for you so you don't have to speak smtp to the target server directly.
    So I guess your code some looks some like this:


    Rather strange your Source is over 370 lines long but the very basics doesn't work.

    There're a couple of reasons the connection is refused:

    - You're tryin to directly connect to the target SMTP server - and maybe this connection gets refused cause the server only accepts connections from other "registered" SMTP servers but refuses connections from private IP ranges - simple spam protection.
    - If you're try to connect to a SMTP server of your mail provider - you maybe try to connect to the wrong port. A SMTP server usualy has following ports opened:
    TCP/25 - to receive mails from other SMTP servers - normaly plain unencrypted - but could also provide STARTTLS feature
    TCP/465 - to accept mail-submission from registered clients - secured by socket level TLS
    TCP/587 - same as above - but mostly used with STARTTLS command instead of socket level TLS

    Here's a sample:

    Obviously you need java mail api in your classpath to compile and run.
    Try to get my sample working - and post stacktraces if you encounter exceptions so we can narrow down the problem.

    Hope it helps in any way.

    Matt



    Hi
    Thanks.However
    I shall try to use the code  as suggested .
    But very importantly the input should be via stream data
    for easy functioning that i have shown below.please suggest alter native if socket usage may be cause for error like  connection
    refusal erc
    As
    CRMK











     
    Matt Wong
    Ranch Hand
    Posts: 218
    5
    MS IE Notepad Suse
    • Likes 1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Well, I wouldn't try to implement raw smtp by myself - use java mail lib instead.
    Did you tried to telnet localhost:25 ?
    This might work on a linux machine as usual there should be a mail deamon runnung - but on windows you have to setup a mail server first as windows doesn't have any MTA pre-installed.
    Anyway: we still need some more information to help you.
     
    Comal Rajagopalaratnam Muthukumar
    Ranch Hand
    Posts: 401
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Matt Wong wrote:Well, I wouldn't try to implement raw smtp by myself - use java mail lib instead.
    Did you tried to telnet localhost:25 ?
    This might work on a linux machine as usual there should be a mail deamon runnung - but on windows you have to setup a mail server first as windows doesn't have any MTA pre-installed.
    Anyway: we still need some more information to help you.


    Hi
    Thanks.
    The following codes are shown just randomly to indicate
    the use of data gramsocket
    But this is a different prg .Howere contexrually it might help as to port
    selection is rather difficult as said by you
    This is for your perusal
    Also sample.png enclosed
    As
    CRMK
    ***********************************

    sample.png
    [Thumbnail for sample.png]
    Please forward the sample to Matt Wong
     
    Comal Rajagopalaratnam Muthukumar
    Ranch Hand
    Posts: 401
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Matt Wong wrote:Well, I wouldn't try to implement raw smtp by myself - use java mail lib instead.
    Did you tried to telnet localhost:25 ?
    This might work on a linux machine as usual there should be a mail deamon runnung - but on windows you have to setup a mail server first as windows doesn't have any MTA pre-installed.
    Anyway: we still need some more information to help you.


    Hi
    On same lines
    the prg  (from java3)on execution,produces a minor error though it started connecting
    this time
    as shown
    Shall be thankfull if the error  for  (mail-host) substituted with a suitable  alternative .
    I tried local host but invain

    Thanks
    As
    CRMK

     
    Matt Wong
    Ranch Hand
    Posts: 218
    5
    MS IE Notepad Suse
    • Likes 1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Sorry, but your posts some get more and more away from your initial question I don't know what you're try to say or ask anymore.
    I've replied to your question why you get a connection reset with a few guesses and ask you to provide us some more information. But unfortunatly your last two posts doesn't help as they don't seem to relate to your initial problem.
    If you're still asking for some help please try to re-order your question and additional code so we can follow up again.
     
    Comal Rajagopalaratnam Muthukumar
    Ranch Hand
    Posts: 401
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Matt Wong wrote:Hi Comal,
    as I'm a bit more into the whole topic about java and e-mail I can give you some input:
    It seems you're tryin to connect to the server directly instead of use java mail api. I recommend you to use it. It handles many things for you so you don't have to speak smtp to the target server directly.
    Matt



    Hi
     In fact I tried three programs in  java  to forwatd a sample meesaege. but none of them gave fruitful result. inlieu
     of the follwing points
     
     !)MailMessage that was having connection problem and complicated with lmore line of code
      2)ServerFrame.java -->that was a j-chat. software in GUI environment,acknowledging  Datagram Service
       requiring different systems of network
     3)Send Mail.java  the  third one supposed to be easy but hardly this also had problem
     
     Since you seem to inform about your  rich comprehension about this topic,
     
     i  did show  all of these to get any one  prg cleared atlleast Also i am not well versed in certian nomenclature used in prgs
     So please help me if  you can make  the follwing prg  error free
     Hope this suffices for a favourable  solution
     Thanks
     As
     CRMK
       
     







     
    Comal Rajagopalaratnam Muthukumar
    Ranch Hand
    Posts: 401
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Matt Wong wrote:Well, I wouldn't try to implement raw smtp by myself - use java mail lib instead.
    Did you tried to telnet localhost:25 ?
    This might work on a linux machine as usual there should be a mail deamon runnung - but on windows you have to setup a mail server first as windows doesn't have any MTA pre-installed.
    Anyway: we still need some more information to help you.



    Hi
    Please correct the prg(email)  for sending the trailer message.


    Thanks
    As
    CRMK
     
    Consider Paul's rocket mass heater.
    reply
      Bookmark Topic Watch Topic
    • New Topic