aspose file tools*
The moose likes Other JSE/JEE APIs and the fly likes sending mail to multiple receipients 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 "sending mail to multiple receipients" Watch "sending mail to multiple receipients" New topic
Author

sending mail to multiple receipients

bhuvan sundar
Ranch Hand

Joined: Mar 02, 2005
Posts: 104
Hi Ranchers,

My requirement is as follows:

I've a To address and multiple CC addressess and BCC addressess. Now, when I try to send mail, the mail should be sent to all valid addressess and the invalid ones should be caught in the exception.

Please help me to do this using JavaMail API.

Thanks in Advance..
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

So what's your problem? Is it that obvious garbage addresses are causing an exception, and none of the addressees are getting the message? Or is it that you want the server to instantly check whether all the addresses correspond to valid accounts on servers that actually exist, and tell you right away? Or is it something else? The term "valid" for an e-mail address is rather vague.
bhuvan sundar
Ranch Hand

Joined: Mar 02, 2005
Posts: 104
The problem is, the junk addresses cause the exception and because of this, none of the mentioned addresses receive the message. I want to avoid this and send mail to all addresses except the junk ones.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41877
    
  63
It's rather unusual that an email wouldn't be sent to a valid address just because the one of the other addresses was invalid.
What kind of validation do you perform before sending? Regular expressions are a common way. This one weeds out a lot of junk: [\\p{L}0-9_-]+(\\.[\\p{L}0-9_-]+)*@([\\p{L}0-9_-]+\\.)+[a-zA-Z]{2,7}


Ping & DNS - my free Android networking tools app
bhuvan sundar
Ranch Hand

Joined: Mar 02, 2005
Posts: 104
If I'm right, regular expressions are used to validate the format of the addresses. For example, the email id is a.b@c.com. While entering the id in CC field, it is entered as ab@c.com and z.y@c.com(which is a valid one) in the TO field. Now, when i hit send, mail should be sent to z.y@c.com which is a valid id and exception should be thrown for ab@c.com. But, what i get is only the exception for the invalid id and not the mail for the valid id.

Hope I'm clear of the problem i'm facing...
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41877
    
  63
This seems more of a configuration issue of the email server. Like I said, email servers normally retry sending emails which pose problems, but deliver to the other addresses in the list just fine. Maybe you can run a few tests against your server with a regular email client, to see how it behaves in this regard.
bhuvan sundar
Ranch Hand

Joined: Mar 02, 2005
Posts: 104
It is possible in SMTPMessage. It has a method setSendPartial() which takes a boolean and if this is set to true, mail will be sent to valid addresses and exception is thrown for invalid ones.
 
Consider Paul's rocket mass heater.
 
subject: sending mail to multiple receipients