Reputation: 17
I am working in email response but unable to find any solution.I need to get response when email failure or success in Java. Code-->
Properties props = new Properties();
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.port", "587");
Session session = Session.getInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
try {
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress("[email protected]"));
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse("[email protected]"));
message.setSubject("Testing Subject");
message.setText("Dear Mail Crawler,"
+ "\n\n No spam to my email, please!");
Transport.send(message);
Upvotes: 1
Views: 1564
Reputation: 17849
If an Exception is raised you can catch it in your exception hanlding:
try{
....
Transport.send(message);
....
}catch(Exception ex){
//You can catch exception here and deal with it
}
Some popular exception types include:
Upvotes: 0
Reputation: 52185
Emails are fire and forget, meaning that once you send it, there is no way to get an exception out of it should it fail or some return code/value should it succeed.
As far as I know:
<img src="..../image/someuniqueid"...
. You could then assign image id's to recipients. When they open the email, your server will be hit together with the unique ID you have provided in your email. This will let you know when was an email opened and by which recipient.Upvotes: 1