GeeCON Prague 2014*
The moose likes Servlets and the fly likes Problem with sending E-mail Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Servlets
Bookmark "Problem with sending E-mail" Watch "Problem with sending E-mail" New topic
Author

Problem with sending E-mail

Azz Romaysa
Ranch Hand

Joined: Dec 08, 2004
Posts: 66
Hi,

I've a problem with sending an E-mail to multiple reciepients.

This is the method that gets all the E-mail addresses I have:


Here I call my methode:


My Mail.java:


And this is the Exception what I still get:



Could soemone help me to fix this problem???

Abu Romaysa,
Carl Trusiak
Sheriff

Joined: Jun 13, 2000
Posts: 3340
You are getting the toString of the String array and not the String at an array position:


Change this to:

Try it again.


I Hope This Helps
Carl Trusiak, SCJP2, SCWCD
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

You seem to be trying to pass an array of strings to a constructor which does not accept string arrays in Mail.java:

Thats not going to work.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Azz Romaysa
Ranch Hand

Joined: Dec 08, 2004
Posts: 66
Thanks for your replays,

I tried what you said but still get this Exception:
Carl Trusiak
Sheriff

Joined: Jun 13, 2000
Posts: 3340
Print out the list of email addresses you are sending this to. That should clarify things
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

So the addresses are now valid SMTP email addresses (otherwise you'd still see the AddressException) but your SMTP server is sending back a 550 message. That means the requested action cannot be taken, because the mailbox is unavailable to whichever user tried to preform the action, either because it doesn't exist or access is denied (you can find this out by reading the right RFC by the way).
Carl Trusiak
Sheriff

Joined: Jun 13, 2000
Posts: 3340
InternetAdress validates the String is a valid Internet Address and not a valid Email address (not even in form) A lot of Strings are valid Internet Addresses but, not a validly formed email address. The failure he is getting now is caused by one of the Strings in the list. It appears to be a comma or empty String. Scrubbing a List of String to ensure each is a valid appearing email address takes a bit more work.
Azz Romaysa
Ranch Hand

Joined: Dec 08, 2004
Posts: 66
Yes the problem is in the method that gets the e-mails addresses from the database.

When I printed out the result of my array I got this: [Ljava.lang.String;@d17ec3
and that means an invalid e-mail address.

is something wrong with my methode?

Carl Trusiak
Sheriff

Joined: Jun 13, 2000
Posts: 3340
You need to read up on Arrays in Java but, try this:

Azz Romaysa
Ranch Hand

Joined: Dec 08, 2004
Posts: 66
Thanks Carl,

Here is what I got when I tried to send an e-mail:

Address # 0 : null
Address # 1 : null
[ January 31, 2005: Message edited by: Azz Romaysa ]
Azz Romaysa
Ranch Hand

Joined: Dec 08, 2004
Posts: 66
Thanks very very much ...

The problem is fixed. The problem was in the method that gets the e-mail addresses, it returned a null, cause the way how I converted my Vector to an Array was wrong.

This has fixed the problem: String[] mijnEmails = (String[]) emails.toArray(new String[emails.size()]);

Abu Romaysa,
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336


InternetAdress validates the String is a valid Internet Address and not a valid Email address (not even in form) A lot of Strings are valid Internet Addresses but, not a validly formed email address. The failure he is getting now is caused by one of the Strings in the list. It appears to be a comma or empty String. Scrubbing a List of String to ensure each is a valid appearing email address takes a bit more work

Well actually the InternetAddresses class parses the String to ensure its RFC822 compliant, unless you tell it not to. 822 compliant == a valid SMTP email address. Passing a null to the constructor is not valid, unless you do as Azz Romaysa has done and concatenate a blank string onto it.
 
GeeCON Prague 2014
 
subject: Problem with sending E-mail