Hello! I am using java mail API now to send emails from my project. I create a transport object and send messages. But they are sent if I automatically close the transport after sending. Smth like this //creating transport........ transport.sendMessage(msg, msg.getAllRecipients()); transport.close();
If I comment the last line the message is sent only after I exit the program which frees all the resources and threrefore implicitly closes the transport object. But I need to create one transport and hold it open unless the main JFrame is closed. Waiting for reply........ Thank you! Fedai!
newRec = new InternetAddress(Recipient); mailMsg.setText(Message); mailMsg.setRecipient(MimeMessage.RecipientType.TO, newRec); mailMsg.saveChanges(); mailTransp.sendMessage(mailMsg, mailMsg.getAllRecipients()); //mailTransp.close(); If I do not close mailTransp it's not sent, I mean I call saveChanges(). Is there a way of doing what I want not by means of Transport but transport = mailSession.getTransport("smtp")?
In both cases the debug is the same except for this. In case of closing the trasport object the last output is this .................................................. 250 Mail queued for delivery. QUIT 221 Closing connection. Good bye. In case of not closing just this ................................................ 250 Mail queued for delivery. In my project I start sending hundreds of messages upon one button click. This Transport.send(message) as the doc. says makes a new connection each time i.e. in creates a new transport object, connects to the server, sends the message. And I have a Retry button. But I dont want to connect to the server each time a user clicks the Retry button or sends again. This is ineffective. Waiting for reply........ Thank you very much!
Originally posted by fedai gandjaliyev: And I have a Retry button. But I dont want to connect to the server each time a user clicks the Retry button or sends again. This is ineffective.
I don't know what "ineffective" might mean there. So I can't say what to do differently. But if you mean there is a pause while the messages are sent, then why don't you have a separate thread that connects to the server and sends the messages? Have your GUI put the messages on the back of a queue and have that separate thread read them from the front of the queue.
All I need to do is the following. Connect to the SMTP server once and send messages over different periods of time and disconnect from it only when I exit the application. Transport.send(message) can be used to accomplish it. But according to the documentation for each it's "send" method it creates a separate connection. That means it is comparetively slow.
Can you hear that? That's my theme music. I don't know where it comes from. Check under this tiny ad: