How to Validate Address Not Found Mails(Sent Mails) in SMTP(Java)

30 Views Asked by At
@Override
public boolean sendOnboardingEmail(String emailTo, String onboardingDateTime, String userName) {
    Properties prop = System.getProperties();
    prop.put("mail.smtp.host", SMTP_SERVER);
    prop.put("mail.smtp.auth", "true");
    prop.put("mail.smtp.port", "587");
    prop.put("mail.smtp.starttls.enable", "true");
    prop.put("mail.smtp.ssl.trust", SMTP_SERVER);

    Session session = Session.getInstance(prop, null);
    Message msg = new MimeMessage(session);

    try {
        msg.setFrom(new InternetAddress(EMAIL_FROM));
        msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(emailTo, false));
        msg.setSubject(EMAIL_SUBJECT);
        msg.setText(EMAIL_TEXT);
        msg.setSentDate(new Date());

        SMTPTransport t = (SMTPTransport) session.getTransport("smtp");

        t.connect(SMTP_SERVER, EMAIL_FROM, PASSWORD);

        t.sendMessage(msg, msg.getAllRecipients());
        t.close();

        return true;
    }  catch (MessagingException e) {
        e.printStackTrace();
        return false;
    }
    
}

`I am using the above approach for sending emails, I have to validate emails that are sent or not sent, Valid emails have been sent but some emails have shown like the below in the inbox i.e., address not found(The response was: 550 5.1.1 The email account that you tried to reach does not exist. Please try double-checking the recipient's email address for typos or unnecessary spaces. Learn more at https://support.google.com/mail/?p=NoSuchUser y9-20020aa79e09000000b00687b0584e6bsor4586365pfq.1 - gsmtp)

can you suggest how to validate those mails (has sent or not)?`

0

There are 0 best solutions below