• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

javax.mail.SendFailedException: Invalid Addresses; nested exception is:

 
Ranch Hand
Posts: 851
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,



Calling this method like this:

My this working fine but when there is a invalid address then its throwing the following error and quit the loop that results all rest of the emails unsent.

javax.mail.SendFailedException: Invalid Addresses; nested exception is:
com.sun.mail.smtp.SMTPAddressFailedException: 550 sorry, no mailbox here by that name. (#5.7.17)



Is there any way to get all:
1) successfully sent mail addresses
2) invalid address
3) valid but unsent address
4) That is most important to log the aforementioned emails in a file
5) Must not quit the loop until & unless my program is not sending all listed emails

Please advise

Thanks in anticipation
 
Ranch Hand
Posts: 146
2
Mac Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Farakh khan wrote:Is there any way to get all:
1) successfully sent mail addresses
2) invalid address
3) valid but unsent address


Why not catch the exception and store its details in a collection for processing later? You can do the same for sent emails, etc.

Farakh khan wrote:Must not quit the loop until & unless my program is not sending all listed emails


Can you post the conditions for the loop that is unexpectedly terminating?
 
Farakh khan
Ranch Hand
Posts: 851
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I was googling and found very useful link that is related to my question http://stackoverflow.com/questions/15131868/how-resolve-address-invalid-exception

Now what I written this code in the catch block:


Can you post the conditions for the loop that is unexpectedly terminating?


I am making call to SendEmail class from other classes like:


Thanks for your reply
 
Farakh khan
Ranch Hand
Posts: 851
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can anybody please help while my following code writing garbage to a file

 
Farakh khan
Ranch Hand
Posts: 851
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to write to a file the record of emails that are validSentAddresses + validUnsentAddresses + invalidAddresses to refine our record in database as well as to know check invalidAddresses

Please advise.

Thanks in anticipation
 
Marshal
Posts: 28226
95
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
Your second-to-last post doesn't write to any files, so saying that code is "writing garbage to a file" and saying nothing else is something which can't be answered in any way. Perhaps you could produce some actual code and show us what it actually does? Just saying something is "garbage" is unhelpful, we need to see what's happening.
 
Farakh khan
Ranch Hand
Posts: 851
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am sorry to not post my full code. I made some changes and here is my code:



Best regrads
 
Paul Clapham
Marshal
Posts: 28226
95
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. And does that code do something which you don't like? If so, what?

By the way I see you're only using the first of the valid unsent addresses and only the first of the invalid addresses, but perhaps that's just something quick to test the code? But what happens if one of those arrays has no elements?
 
Farakh khan
Ranch Hand
Posts: 851
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your reply.

I read in javax.mail API and found that if we set property of reportSuccess to true then it must read sendFailedException. I set tis property but still no success. All 3 files that am writing are still blank.

What condition I use if record is null?

Thanks again
 
Paul Clapham
Marshal
Posts: 28226
95
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

Farakh khan wrote:I read in javax.mail API and found that if we set property of reportSuccess to true then it must read sendFailedException. I set tis property but still no success. All 3 files that am writing are still blank.



I find that very hard to believe. You've passed a non-blank "to" address into that method and when you use your code to write it to a file, the file is blank? That suggests to me that either your code is wrong or you're looking at the wrong file. Clearly it can't be anything to do with JavaMail because none of the code involved in writing that "to" address is JavaMail code.

What condition I use if record is null?



I don't understand what "record" means there or where you might be using some condition based on its nullity.
 
Farakh khan
Ranch Hand
Posts: 851
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote: I find that very hard to believe. You've passed a non-blank "to" address into that method and when you use your code to write it to a file, the file is blank? That suggests to me that either your code is wrong or you're looking at the wrong file. Clearly it can't be anything to do with JavaMail because none of the code involved in writing that "to" address is JavaMail code.



I was checking JavaMailAPI that stats :
SMTPAddressSucceededException:This exception is chained off a SendFailedException when the mail.smtp.reportsuccess property is true.

This will cause Transport.send to always throw SendFailedException.

So what I change in my code is as below:
I added:

and removed this part:

Finally, Now the catch block is like:


I again tried and run this code but still nothing written in files


I don't understand what "record" means there or where you might be using some condition based on its nullity.


This was in response to your message with timestamp Yesterday 9:47:17 PM i.e. listed below

By the way I see you're only using the first of the valid unsent addresses and only the first of the invalid addresses, but perhaps that's just something quick to test the code? But what happens if one of those arrays has no elements?



Thanks for giving me your precious time
 
Paul Clapham
Marshal
Posts: 28226
95
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

Farakh khan wrote:Thanks for giving me your precious time



Did you know that when you write this in a post, it sounds like you're being sarcastic? I'm going to assume you aren't, for now...

Anyway what we have so far is that you've changed some code to something else, but you haven't explained what problems remain. One problem that I can see is that your code still assumes there's exactly one valid sent address, exactly one valid unsent address, and exactly one invalid address.
 
Farakh khan
Ranch Hand
Posts: 851
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

Now this is the final code that I was able to write:


I tested this code and found its overwriting to the file instead of adding new records

 
Paul Clapham
Marshal
Posts: 28226
95
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

Farakh khan wrote:I tested this code and found its overwriting to the file instead of adding new records



Yes, that's what your printReport() method does. If you want it to append to the file instead of creating a new file every time, you should change it to do that. One of those classes you used (BufferedWriter, OutputStreamWriter, FileOutputStream) has a constructor which allows you to append, but I don't remember which one. Check the API documentation.
 
Farakh khan
Ranch Hand
Posts: 851
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I changed the method as following. Its working fine and appending records instead of overwriting
but throws the following exception:
 
Paul Clapham
Marshal
Posts: 28226
95
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeah. Why are you trying to flush the stream AFTER you close it?
 
Farakh khan
Ranch Hand
Posts: 851
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks from the bottom of my heart. I am really learning everyday. Coderanch is my best and favorite forum
 
Paul Clapham
Marshal
Posts: 28226
95
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
Glad you got all your issues sorted out. By the way I found it interesting that you found the Files.newBufferedWriter method... that's obviously superior to the old version which you originally used, in at least three ways. And not only that, I didn't know it existed. That's one of the things about Java, the language designers keep including useful features which greatly simplify the old ways of doing things, and it's hard to keep up with them.
 
Farakh khan
Ranch Hand
Posts: 851
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am working in java since 1996 and still assuming I am learning. Its really a jest of computer science. In my era there was structure programming and OOP was looking very news and modern but now am seeing AOP (Aspect Oriented Programming). I love that java producers not only working to update their existing modules but always providing cutting edge new ideas as well.
 
Farakh khan
Ranch Hand
Posts: 851
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Today I ran this code on our production server and seen its writing only validSentAddresses.txt because either its sent or not then my code is writing "to" variable in the file that is email address that we don't know this will be sent or not.

Please advise how I modify my code to must throw sendFailException to write validSent, validUnsent and validNotSent emails

 
reply
    Bookmark Topic Watch Topic
  • New Topic