Please help, javax mail project sending email when running it from netbeans, but when running directly from executable jar file then mail not going. and also not working on any other PC and server.
note:- JOptionPane showing that message sent successful. but recipient not received any mail.
public static void sendMail(String recepient) throws Exception{
System.out.println("Preaparing to send Email");
Properties properties = new Properties();
properties.put("mail.smtp.auth", "true");
properties.put("mail.smtp.starttls.enable", "false");
properties.put("mail.smtp.host", "mail.xyz.in");
properties.put("mail.smtp.port", "587");
final String myAccountEmail = Sender;
final String password = email_pass;
Session session = Session.getInstance(properties, new Authenticator(){
@Override
protected PasswordAuthentication getPasswordAuthentication(){
return new PasswordAuthentication(myAccountEmail, password);
}
});
Message message = prepareMessage(session,myAccountEmail,recepient);
Transport.send(message);
System.out.println("Message Send Successful");
JOptionPane.showMessageDialog(null, "Successful");
}
private static Message prepareMessage(Session session,String myAccountEmail, String recepient) {
try{
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(myAccountEmail));
message.setRecipient(Message.RecipientType.TO, new InternetAddress(recepient));
message.setSubject(sub);
BodyPart messageBodyPart1 = new MimeBodyPart();
messageBodyPart1.setText(msg);
Multipart multipartObject = new MimeMultipart();
multipartObject.addBodyPart(messageBodyPart1);
message.setContent(multipartObject);
return message;
}
catch(Exception e){JOptionPane.showMessageDialog(null, e.toString());
e.printStackTrace();
}
return null;
}
