How to check if email address really exists by sending mail in java

Our web application sends an email to each user who enters their email id. But how can I make sure that the email id entered by the user is valid. In fact, what we do when a user enters an email id is to send a link to his email id to activate the account. I have a code for sending emails. But this does not give me any errors, even if the mail id does not exist. Please tell us how to solve the problem? If the email id does not exist, it should give some error.

I am attaching a code

    package csv;
    import javax.mail.PasswordAuthentication;
    import java.util.Properties;
    import javax.activation.DataHandler;
    import javax.activation.DataSource;
    import javax.activation.FileDataSource;
    import javax.mail.BodyPart;
    import javax.mail.Message;
    import javax.mail.MessagingException;
    import javax.mail.Multipart;
    import javax.mail.Session;
    import javax.mail.Transport;
    import javax.mail.internet.AddressException;
    import javax.mail.internet.InternetAddress;
    import javax.mail.internet.MimeBodyPart;
    import javax.mail.internet.MimeMessage;
    import javax.mail.internet.MimeMultipart;

    public class email {

public void send(String recipeintEmail, 
        String subject, 
        String messageText,String[] attachments) 
        throws MessagingException, AddressException {
    /*
       It is a good practice to put this in a java.util.Properties 
       file and encrypt password. Scroll down 
       to comments below to see 
       how to use java.util.Properties in JSF context. 
    */
    String senderEmail = "our email address";
    String senderMailPassword = "password";
    String gmail = "smtp.gmail.com";

    Properties props = System.getProperties();

    props.put("mail.smtp.user", senderEmail);
    props.put("mail.smtp.host", "smtp.gmail.com");
    props.put("mail.smtp.port", "465");
    props.put("mail.smtp.starttls.enable", "true");
    props.put("mail.smtp.debug", "true");
    props.put("mail.smtp.auth", "true");
    props.put("mail.smtp.socketFactory.port", "465");
    props.put("mail.smtp.socketFactory.class", 
          "javax.net.ssl.SSLSocketFactory");
    props.put("mail.smtp.socketFactory.fallback", "false");

    // Required to avoid security exception.
    email.MyAuthenticator authentication = 
          new email.MyAuthenticator(senderEmail,senderMailPassword);
    Session session = 
          Session.getDefaultInstance(props,authentication);
    session.setDebug(true);

    MimeMessage message = new MimeMessage(session);

    BodyPart messageBodyPart = new MimeBodyPart();      
    messageBodyPart.setText(messageText);

    // Add message text
    Multipart multipart = new MimeMultipart();
    multipart.addBodyPart(messageBodyPart);

    // Attachments should reside in your server.
    // Example "c:\file.txt" or "/home/user/photo.jpg"

    for (int i=0; i < attachments.length; i++) {        

        messageBodyPart = new MimeBodyPart();       
        DataSource source = new FileDataSource(attachments[i]);
        messageBodyPart.setDataHandler(new DataHandler(source));
        messageBodyPart.setFileName(attachments [i]);          
        multipart.addBodyPart(messageBodyPart) ;  
    }



    message.setContent(multipart);                
    message.setSubject(subject);
    message.setFrom(new InternetAddress(senderEmail));
    message.addRecipient(Message.RecipientType.TO,
        new InternetAddress(recipeintEmail));

    Transport transport = session.getTransport("smtps");
    transport.connect(gmail,465, senderEmail, senderMailPassword);
    transport.sendMessage(message, message.getAllRecipients());

    transport.close();

}

private class MyAuthenticator extends javax.mail.Authenticator {
    String User;
    String Password;
    public MyAuthenticator (String user, String password) {
        User = user;
        Password = password;
    }

    @Override
    public PasswordAuthentication getPasswordAuthentication() {
        return new javax.mail.PasswordAuthentication(User, Password);
    }
}


public static void main(String args[]) throws MessagingException
{
    // email e=new email();
   // String at[]={"c:/COPYRIGHT.txt"};
  //  e.send("xyz@gmail.com", "hello","test"  )");
}

}
+5
5

regex , / MX, , , . , .

+3

. , , /.

URL-, , / , .

+4

, , , , . , .

. , , , , , (, Yahoo, GMail, AOL ..), , ( ) . , .

+2

java mail API .

try {
        //
        // Create InternetAddress object and validated the supplied
        // address which is this case is an email address.
        InternetAddress internetAddress = new InternetAddress(email);
        internetAddress.validate();
        isValid = true;
    } 

catch (AddressException e) {           System.out.println( " catch - :" + email ");       }

java Mail API http://www.oracle.com/technetwork/java/index-138643.html

+1

. - .

, , - . , , .

: http://www.oracle.com/technetwork/java/faq-135477.html#bounce

:

: , . "" ?

A: , ( MIME /, . RFC1892) -, . RFC1211 , .

, . ( ) .

, ​​, , . -, , , .

"" , . ( , JavaMail.) JavaMail ; . NOTES.txt JavaMail.

There are many methods and heuristics to solve this problem - none of them are perfect. One method is Envelope Return Path Variables, described in http://cr.yp.to/proto/verp.txt .

0
source

All Articles