• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

How to Make Sure Class Finishes in Spite of Exception

 
Ranch Hand
Posts: 2278
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In the following class how can I make sure the class completes its process eventhough on of the addresses might be bogus?

 
Sheriff
Posts: 22853
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1) use a List<InternetAddress>
2) wrap the creation of the separate addresses in a try-catch block inside the loop; when successful add to the List.
3) when done convert the List into an array:
 
Sheriff
Posts: 28413
102
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a strong suspicion that your concern is not merely that the processing of that method terminates normally. I suspect your real question is that even if some of the e-mail addresses are bogus, you want the message to be sent to the remaining good e-mail addresses regardless of that.

Assuming that's the actual background for the post, let me refer you to this part of the JavaMail API documentation. Scroll down and read the description for the "mail.smtp.sendpartial" property. Does that help?
 
Steve Dyke
Ranch Hand
Posts: 2278
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:I have a strong suspicion that your concern is not merely that the processing of that method terminates normally. I suspect your real question is that even if some of the e-mail addresses are bogus, you want the message to be sent to the remaining good e-mail addresses regardless of that.

Assuming that's the actual background for the post, let me refer you to this part of the JavaMail API documentation. Scroll down and read the description for the "mail.smtp.sendpartial" property. Does that help?



Thanks,

I have added this to my email code.

 
Rob Spoor
Sheriff
Posts: 22853
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Never write "new Boolean(true)", "new Boolean(false)" or "new Boolean(b)" where "b" is any boolean variable. Use Boolean.TRUE, Boolean.FALSE or Boolean.valueOf(b) instead. That will use one of the two pre-existing objects Boolean.TRUE and Boolean.FALSE.

In fact, never use any of the Boolean constructors; they both have a matching valueOf method that uses the cached values.
 
Paul Clapham
Sheriff
Posts: 28413
102
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And in this case you don't use anything to do with Boolean. If you look again at the documentation which I linked to you'll see this:

The SMTP protocol provider supports the following properties, which may be set in the JavaMail Session object. The properties are always set as strings; the Type column describes how the string is interpreted.


You might want to read the rest of that documentation page while you're at it, too. You never know what you might find in documentation.
 
Steve Dyke
Ranch Hand
Posts: 2278
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:And in this case you don't use anything to do with Boolean. If you look again at the documentation which I linked to you'll see this:

The SMTP protocol provider supports the following properties, which may be set in the JavaMail Session object. The properties are always set as strings; the Type column describes how the string is interpreted.


You might want to read the rest of that documentation page while you're at it, too. You never know what you might find in documentation.



I beleive I have the sendpartial property set correctly now but still don't have the results I need. When the address array is being created in the loop I need it to skip bad email addresses.

 
Paul Clapham
Sheriff
Posts: 28413
102
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Steve Dyke wrote:I beleive I have the sendpartial property set correctly now but still don't have the results I need.



I'm not so sure you have it set correctly. Why do you set it to "True" instead of "true"?

When the address array is being created in the loop I need it to skip bad email addresses.



How about if you explain why? It would also help if you explained the technical terms "bad" and "bogus" as applied to e-mail addresses.
 
Steve Dyke
Ranch Hand
Posts: 2278
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:

Steve Dyke wrote:I beleive I have the sendpartial property set correctly now but still don't have the results I need.



I'm not so sure you have it set correctly. Why do you set it to "True" instead of "true"?

When the address array is being created in the loop I need it to skip bad email addresses.



How about if you explain why? It would also help if you explained the technical terms "bad" and "bogus" as applied to e-mail addresses.



Okay, I set property to 'true'. I don't really have a reason why I typed in 'True'.

When a user logs onto my app there is a prference section where the user can type in an e-mail address. This is not a required field(yet) nor do I have code set in place for validation. In spite of this there are functions in the app that refer to the file where e-mail addresses are stored and build arrays for auto sent messages. I need my e-mail code to skip records where the e-mail address is empty and where the address was not keyed in correctly, example spaces or invalid characters.
 
Paul Clapham
Sheriff
Posts: 28413
102
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay. Then I don't see why you shouldn't write code which skips those things. Something like (pseudocode)

reply
    Bookmark Topic Watch Topic
  • New Topic