aspose file tools*
The moose likes Java in General and the fly likes How do I know the email is Sending failed? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "How do I know the email is Sending failed?" Watch "How do I know the email is Sending failed?" New topic
Author

How do I know the email is Sending failed?

Mylsamy Shanmugam
Greenhorn

Joined: Jun 04, 2008
Posts: 8
Hi all,

I am using Java to send email to users.

The code is

SMTPTransport tr = (SMTPTransport) poSession.getTransport("smtps");
tr.connect(MailHost,FromMailId,Password);
tr.sendMessage(Message,Message.getAllRecipients());

FromMailId is from user mailid

Password is from user password.

Message is what can from user sent to toUser

Message.getAllRecipients() are to user mail id..

But how do i know whether the Email is Successfully Sent or Not?

Ex the User give the Email address as 'xxxx@gamil.com' instead of 'xxxx@gmail.com'

Is any method to identity this problem?

I am waiting for your valuable reply..

Thanks

Myl..
James Elsey
Ranch Hand

Joined: Dec 21, 2007
Posts: 228

I'm not aware of any easy way to check the @gmail.com is correct.

You could have a finite list of email providers to check against, it would work, but would be rather restrictive

You can reduce validation issues by taking a look at the EmailValidator class, particualry the isValid() method

that will prevent people using emails like abc@com, ab@ab etc. I believe it uses some kind of regex to make sure you have at least 3 parts to an email, such as X@Y.Z


Kind Regards, James. OCPJP 1.6 || My SCJP / OCJCP Study Notes
Interested in : SCJP, Google App Engine, Stripes, Android;|| My Bite-Size SCJP Study Blog
Lester Burnham
Rancher

Joined: Oct 14, 2008
Posts: 1337
You could use an embedded SMTP server like Aspirin. It's mail listener facility can be used to track whether mails have or have not been sent successfully.
Mylsamy Shanmugam
Greenhorn

Joined: Jun 04, 2008
Posts: 8
Thanks for your valuable reply James and Lester,

Sorry for my last post, Actually i want the delivery status of my email.

I know the delivery status notification ,When I send an email to toUser.

How can i know this?

Please help me out..


Lester Burnham
Rancher

Joined: Oct 14, 2008
Posts: 1337
The JavaEnterpriseEditionFaq points to a discussion about DSN; be aware that DSN for various reasons is not generally a reliable way to know whether someone has received or read an email.

An approach like Aspirin takes at least lets you know if the email couldn't be delivered due to to an incorrect email address or some other fundamental problem. Your initial problem statement ("how do i know whether the Email is Successfully Sent or Not?") sounded like that's what you want to accomplish.
Mylsamy Shanmugam
Greenhorn

Joined: Jun 04, 2008
Posts: 8
First sorry for my poor English.

My Problem is,

The from user knows the delivery status ( Failure only), when he has sent an Email to other user through our portal.

For example in our portal, One user log in as a Customer and he want to invite another user as a Candidate.

So he sent an email to him. But the mail is failed to sent, due to some problems like he made a spelling mistake in email address

(xxx@gamil.com instead of xxx@gmail.com ) or temporarily access the database problem.

In this situation, he knows the Mail Delivery status.

That is why I need.. Could you understand my lines.

Myl
Lester Burnham
Rancher

Joined: Oct 14, 2008
Posts: 1337
Yes, I understand what you're asking. That's why I recommended checking out Aspirin, which provides a means of getting notified if there is a problem with the email-sending part. Of course, being an SMTP server, it won't know anything about other issues (having to do with the DB, for example). You'd have to address those in your code.
Misha van Tol
Ranch Hand

Joined: Jan 02, 2010
Posts: 56

Have you tried to catch the SendFailedException?

See the JavaMail API for more info:
http://java.sun.com/products/javamail/javadocs/com/sun/mail/smtp/SMTPTransport.html#sendMessage(javax.mail.Message, javax.mail.Address[])
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

That only tells you if the server failed to send the email, not whether the recipient does not exist or the email failed somewhere outside the visibility of your program.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Mylsamy Shanmugam
Greenhorn

Joined: Jun 04, 2008
Posts: 8
Yes i tried SendFailedException, but it can not caught the error,

The error may be the Domain mismatch error, the recipient does not exist or the email failed somewhere outside the visibility.

 
 
subject: How do I know the email is Sending failed?
 
Similar Threads
SendFailedException with SMTP authentication
Not able to send mail using SMTPTransport
Calling a remote SMTP server
Calling a remote smtp server - anybody knows?
sending email to hotmail account using javamail API