13 Replies Latest reply: Apr 25, 2008 6:02 AM by 807591 RSS

    Check if mail address exists

    807591
      Hi all...

      Well, I need to check if an email address exists, not if the address has a valid syntax or not.

      For example, if I try to send an email to this address: jjjfeurh@jweh.hjw (which doesn't exist, of course). How can I check it?!

      This is the portion of code I'm using...
      public int send() {
         try {
           logger.info( "Preparando el envio del mensaje.");
           lastErrorMessage="";
           
           // Se establece como host el servidor le�do.
           Properties correoProp = getConfigProperties();
                
           // Se crea una sesi�n y el mensaje.
           Session sesion = Session.getDefaultInstance (correoProp, null);
           MimeMessage mimeMsg = new MimeMessage (sesion);
           try {
                // Se establece el remitente
                if (processSender()!=null) {               
                     InternetAddress  from = new InternetAddress  (processSender());
                     mimeMsg.setFrom (from);
                }     
                               
                //Se establecen los destinatarios
                for(int t=0;t<this.getRecipients().size();t++) {          
                     InternetAddress to = new InternetAddress(processRecipient(t));
                     mimeMsg.addRecipient(Message.RecipientType.TO, to);
                     logger.info( "Asunto: "+this.getSubject() + " Destinatario: "+this.getRecipients().get(t));               
                }
                     
                // Se establece el asunto
                mimeMsg.setSubject(processSubject());
                     
                // Se procesa el contenido                
                processContent(mimeMsg);
                     
                // Se env�a el correo 
                Transport.send (mimeMsg);
                          
                logger.info( "Asunto: "+this.getSubject() + " Mensaje enviado por "+processSender());
                return SUCCESS;
           
           } catch (AddressException ae){
                logger.error ("Error producido al enviar el correo: ", ae);
                lastErrorMessage=ae.getMessage();
                
                // Diferencia entre errores si devuelve 1 o 2
                // Error de falta de persona que envia
                if( "1".equals(ae.getRef())) {
                     return ERROR_SENDER;
                }
                          
                return ADDRESS_ERROR;
           } catch (MessagingException me)     {
                logger.error ("Error producido al enviar el correo: ", me);
                lastErrorMessage=me.getMessage();                    
                return SENDING_ERROR;
           }
            catch (Exception e)     {
                logger.error ("Error producido al enviar el correo: ", e);
                lastErrorMessage=e.getMessage();                    
                return UNKNOWN_ERROR;
           }
           
         } 
         catch (Exception ioe) {
           logger.error ("Error generado al acceder al fichero CORREO.properties ", ioe);
           lastErrorMessage=ioe.getMessage();               
           return CONFIG_ERROR;
         }          
      }
      I have searched all around internet but didn't find anything that could help me..

      Thanks in advance :)
        • 1. Re: Check if mail address exists
          807591
          except receiving a msg from mailer daemon which will told you that the adress does not exist, i think you can t do anything about it
          • 2. Re: Check if mail address exists
            807591
            calvino_ind wrote:
            except receiving a msg from mailer daemon which will told you that the adress does not exist,
            Which can take literally hours since email servers can have a retry policy that waits longer and longer between attempts to deliver the mail.
            • 3. Re: Check if mail address exists
              807591
              Thanks for your reply so soon..
              And how can I know that? Because there is nothing that I can control there... I only can see that I received a message from mailer daemon in the outlook :P but I want to see it in the code...

              Maybe I don't explain well.. Sorry for my english :)
              • 4. Re: Check if mail address exists
                807591
                sabre150 wrote:
                Which can take literally hours since email servers can have a retry policy that waits longer and longer between attempts to deliver the mail.
                So there is no solution to this?
                • 5. Re: Check if mail address exists
                  791266
                  carmensp85 wrote:
                  Thanks for your reply so soon..
                  And how can I know that? Because there is nothing that I can control there... I only can see that I received a message from mailer daemon in the outlook :P but I want to see it in the code...

                  Maybe I don't explain well.. Sorry for my english :)
                  Why do you want to do this? Can't you send a verification mail, and let the user click on a link in the mail to verify that the address exists, and that the user wants to register.

                  Kaj
                  • 6. Re: Check if mail address exists
                    807591
                    carmensp85 wrote:
                    sabre150 wrote:
                    Which can take literally hours since email servers can have a retry policy that waits longer and longer between attempts to deliver the mail.
                    So there is no solution to this?
                    Not that I am aware of.

                    It can be even worse than this because it is possible for some receiving servers to be configured so as to put any email addresses they cannot deliver locally into a general account so that the system admins can check for spam attacks.

                    Edited by: sabre150 on Apr 25, 2008 10:03 AM
                    • 7. Re: Check if mail address exists
                      jwenting
                      kajbj wrote:
                      carmensp85 wrote:
                      Thanks for your reply so soon..
                      And how can I know that? Because there is nothing that I can control there... I only can see that I received a message from mailer daemon in the outlook :P but I want to see it in the code...

                      Maybe I don't explain well.. Sorry for my english :)
                      Why do you want to do this? Can't you send a verification mail, and let the user click on a link in the mail to verify that the address exists, and that the user wants to register.
                      Spamlist generation.
                      If there were some service that can tell whether an email address exists or not, spammers wouldn't have to deal with the millions of bounce messages they get.
                      They could just bombard that service with requests for every legal combination of characters that can make up an email address and get a list of known good addresses as a result.

                      There is no other use.
                      • 8. Re: Check if mail address exists
                        807591
                        So.. in conclusion:

                        There is nothing I can do to check if a mail was received successfully at this address: jjjfeurh@jweh.hjw

                        right?
                        • 9. Re: Check if mail address exists
                          807591
                          looks like no
                          • 10. Re: Check if mail address exists
                            jwenting
                            Indeed. Email is not a request/response mechanism so there is no way to ascertain reception.
                            And failure can only be determined IF the receiving system is configured to send a failure message, which is in not mandatory (and in many cases disabled to prevent abuse).

                            The only thing you can do is include a request for a delivery receipt. But mail servers and clients are not required to honour such requests, so you can't rely on them (I've myself set up my mail applications to automatically reject requests for receipts for example).
                            • 11. Re: Check if mail address exists
                              807591
                              Well, thank you so much for all your replies, you all were really helpful.

                              And...
                              jwenting wrote:
                              Indeed. Email is not a request/response mechanism so there is no way to ascertain reception.
                              And failure can only be determined IF the receiving system is configured to send a failure message, which is in not mandatory (and in many cases disabled to prevent abuse).

                              The only thing you can do is include a request for a delivery receipt. But mail servers and clients are not required to honour such requests, so you can't rely on them (I've myself set up my mail applications to automatically reject requests for receipts for example).
                              How can I do this?
                              • 12. Re: Check if mail address exists
                                791266
                                How can I do this?
                                Did you read the rest of the post? It will seldom work.
                                • 13. Re: Check if mail address exists
                                  807591
                                  Yep, I read it all from the top to the bottom......

                                  I thought that maybe there was another method rather than have to ask for the user to send a message or click a link notificating that the email was received...

                                  Well, thanks.

                                  Edited by: carmensp85 on Apr 25, 2008 4:02 AM