JavaMail - Transport.send blocks...

Discussion in 'Java' started by Abraham Khalil, Sep 21, 2003.

  1. Transport.send blocks till it return after sending email.
    Having that in the run statement of the thread and calling interrupt
    doesn't do jack. Does someone know a way to interrupt it, maybe
    opening the same socket on the host and port and call close? Haven't
    tried it but let me know if their's a way.

    Thanks
     
    Abraham Khalil, Sep 21, 2003
    #1
    1. Advertisements

  2. I can't really answer your primary question, but can say that your
    theory will never work: you can't close one connection by opening and
    closing a completely different one. That's akin to trying to break a
    telephone call by calling one of the numbers from a third telephone,
    and then hanging up.

    If you have access to the actual open socket currently used by the
    connection you can close it, causing blocked methods to throw
    exceptions. I don't know if Javamail makes the socket available though.

    /gordon
     
    Gordon Beaton, Sep 21, 2003
    #2
    1. Advertisements

  3. Abraham Khalil

    Gary M Guest

    (Abraham Khalil) wrote in
    Suggestion:

    1. Don't use the static Transport.send method, instead instantiate
    SMTPTransport directly, which you'll notice has close() method that the
    abstract Transport does not. You will use this object reference, in 3
    below.

    2. Create your own class that sends the message. In this class implement
    then TransportListener and ConnectionListener interface. Before sending a
    message it subscribes to the SMTPTransport obj as a ConnectionListener
    and TransportListener.

    3. Then use the various transport and connection listener methods to
    check if an interupt has been requested. If so call the
    SMTPTransport.close() method.

    This will give you the ability to stop the message being sent at various
    predefined points in the transportation and connection process, so it is
    not a true 'interrupt at any point'. I this would be bad net practice,
    FWIW.

    One way to get the a true interrupt is to create a local proxy that
    simply forwards all data from the Transport->local SocketListener then
    localSocket -> remote SMTP Host. You would register this local proxy as
    the SMTP server in Javamail. Then you can check for a string of
    characters you decide will signal an interrupt before you relay it and
    you can send the SMTP QUIT command to the remote host to be polite about
    things. I am not sure but I believe this is a reasonable netfriendly way
    of doing things.

    HTH.

    Gary
     
    Gary M, Sep 21, 2003
    #3
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.