aspose file tools*
The moose likes Other JSE/JEE APIs and the fly likes JavaMail Api Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "JavaMail Api" Watch "JavaMail Api" New topic
Author

JavaMail Api

Aleksandar Mitrev
Greenhorn

Joined: Mar 21, 2008
Posts: 25
I'm trying to create simple mail application using JavaMail API But I've encounter some problems
What I'm trying to do is: user A is sending mail to user B through some administration mail(ex. admin@mail.com) - the mail is actually send by the admin@mail.com so if user B has invalid mail the failed mail notification is send to admin@mail.com
What I want is the failed mail notification to be send to user A mail instead to the admin@mail.com. Is this possible?
I've tried it manual by implementing javax.mail.event.TransportListener and in public void messageNotDelivered(TransportEvent e) method creating my own costume failed notification mail and sending it to user A but the method was never invoked
Also I'm checking if it is possible to accomplish this with DeliveryStatus MessageHeaders MultipartReport but I can't find tutorial - examples
If you have some suggestion please help!
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18991
    
    8

Did you use the "setReplyTo" method of Message?

Also, you don't seem to understand how e-mail works. You give the message to your server -- that's what the "send" message does. Your server will then try to find the server for each of the "to" addresses on the message and give the message to those servers. However since any of those servers may be down at the time, your server will try for perhaps a couple of days before it gives up and deems the message to be undeliverable.

Naturally your JavaMail code doesn't wait for that to happen, it just gives the message to the server and returns. Similarly the other server, the one which your server decided belonged to one of the "to" addresses, may also tell you that it can't deliver the message. That may be because there is no such address on that server, or because that address's mailbox is full, or because it thinks your message is spam. That also happens later. The other server may send a return e-mail saying your message was undeliverable, or it may just discard the message silently.

As for the Delivery Status Reports, you can ask for one but the receiving server is not obliged to send you one.
Aleksandar Mitrev
Greenhorn

Joined: Mar 21, 2008
Posts: 25
Paul Clapham wrote:Did you use the "setReplyTo" method of Message?

Also, you don't seem to understand how e-mail works. You give the message to your server -- that's what the "send" message does. Your server will then try to find the server for each of the "to" addresses on the message and give the message to those servers. However since any of those servers may be down at the time, your server will try for perhaps a couple of days before it gives up and deems the message to be undeliverable.

Naturally your JavaMail code doesn't wait for that to happen, it just gives the message to the server and returns. Similarly the other server, the one which your server decided belonged to one of the "to" addresses, may also tell you that it can't deliver the message. That may be because there is no such address on that server, or because that address's mailbox is full, or because it thinks your message is spam. That also happens later. The other server may send a return e-mail saying your message was undeliverable, or it may just discard the message silently.

As for the Delivery Status Reports, you can ask for one but the receiving server is not obliged to send you one.

Yes I've used setReplyTo(setting the mail from user A) I also set SMTP server and is working fine if mail is send to valid email address.
If email is send to invalid mail the behavior is also expected - normal : failed mail notification is send to the sender. But like I said I don't want failed notification email to be send to the sender of the mail(admin@mail.com) but to other email(user A)
I've tried to put Transport.sent(message) in try-catch with thread delaying and hoping that javax.mail.SendFailedException(Invalid address) will be thrown and from there to make custom failed mail notification that will be sent to user A email
Also like I pointed above I've tried implementing javax.mail.event.TransportListener but messageNotDelivered method was never called
That are the cases that I've tried
The ideal will be to catch the failed mail notification and to change the recipient or somehow forward it
I hope you'll understand my English :)
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18991
    
    8

Aleksandar Mitrev wrote:The ideal will be to catch the failed mail notification and to change the recipient or somehow forward it


Apparently you didn't read anything I wrote.
Aleksandar Mitrev
Greenhorn

Joined: Mar 21, 2008
Posts: 25
Paul Clapham wrote:
Aleksandar Mitrev wrote:The ideal will be to catch the failed mail notification and to change the recipient or somehow forward it


Apparently you didn't read anything I wrote.

so nothing i guaranteed and can't be done
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18991
    
    8

Perhaps you are not old enough to remember dealing with the postal service in your country. In those days we would put something in an envelope, write the address where the envelope was supposed to go to in the middle of the envelope and the return address in the corner of the envelope, and put it in a box for the postal service to pick up and deliver. Later that day, or week, or month, the envelope would be delivered to the addressee. Or if the postal service could not deliver it for any reason (like for example an angry dog outside the place) they would return it to you with a notation about why not. And often that process would fail for various reasons.

It's the same process with e-mail. You give the message to the server and that's the end of the transaction. Sometimes you'll get messages in response at a later time, but those are separate transactions.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18991
    
    8

You should also check out the "mail.smtp.from" property (documented here).
Aleksandar Mitrev
Greenhorn

Joined: Mar 21, 2008
Posts: 25
Paul Clapham wrote:You should also check out the "mail.smtp.from" property (documented here).

Thanks for the replay
I think for my problem there Is no solution - not that I can find
My scenario that I want : having three mails mailA, mailB, mailC then sending mail from mailB to mailC and if the mailC dos not exist(invalid mail) the failed email notification is return to mailA
But the usual behavior is: the failed email notification is return to the sender mailB
I've tried some potential solutions for example setting: mimeMessage.setFrom("mailB"); mimeMessage.addRecipients("mailC"); mimeMessage.setReplyTo("mailA"); mimeMessage.setSender("mailA"); but no luck
My problem may depend a lot from the mail server and its configuration. Thanks anyway
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JavaMail Api