Is it possible to know a message sending fail in a java program.
Showing comments 1 to 6 of total 6 on page 1 of 1
Is there any way to resend the mail through a java program,If a mail sending fails?
I am using EmailMDB(Transport.send(msg)) to send mails.
Please let me know if anything more to be conveyed.
Thanks in advance.
May be this can help u..
Hey thanks flasum4u for the reply....:)
I am able to send mails using JavaMail...but my problem is, I would like to resend the mails if the delivery fails due to various reasons, like improper Email id's or it could be any other problem.
I just want to identify the message delivery failures and resend the message either to the recipients again or to the admin as a email.How could i do so?
I assume you're talking about tracking a mail after it's been sent. Correct me if I'm wrong here.
The way SMTP is implemented, this is not quite possible. Well, at least not without a considerable effort. If your program is talking to an SMTP relay (well most probably your SMTP server host), and the relay contacts the end-user SMTP host in real time while keeping you waiting, it has a chance of getting to know whether the delivery was successful.
However, this is not the case in the real life scenario. What the SMTP server you talk to does is, it accepts your mail for delivery and queues it. Later, when the polling iteration arrives, it sends the mail out to the next relay, or in some cases, directly to the final SMTP host. So, most probably, when you send an email, your SMTP server does not know whether it's going to be a success or not and hence you won't be able to decide it that time.
Now if you are really serious about this and you want it to be done, the only way I could think of now is like the following:
- Set the reply-to and return-path e-mail fields to one of your own POP3 email box address while you send the email. Also, set a unique hash (that matches with your stored database value) in one of the mail headers.
- Periodically poll the POP3 inbox for an incoming mail using POP3 protocol.
- If a mail has returned that contains a daemon delivery failure text as well as the matching hash you sent, you have a bounced mail.
It's pretty complicated and I wouldn't recommend doing it until in the real necessity. Let me know more information about what you are trying to build here and I can be of further assistance to you.
I have another doubt ....Is it good to use the concept of acknowledgment for this problem?If so how?.....cos i dont know how to do so.
Not sure whats the exact application you are working on.
But I used JavaMail for sending emails from my application.
But later I found out about JAMES
JAMES is Java Apache Mail Enterprise Server (james.apache.org/ )
Its an Open Source Project and provides lots of functionalities and
error handling capabilities (something which you are looking for).
Hope this Helps!!!
PS. Setting up the environment and Writing Email Client is very easy,
with source code freely available.