(e-mail address removed) (Abraham Khalil) wrote in
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.
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