0

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;
}

package

1 Answer 1

0

Make sure that your code contains a valid main function as the jar file needs this as an entry point. IDEs such as netbeans sometimes make it possible to run code without an main function for faster debug purposes, but starting the jar will then not work.

public class Main {
    // your function definitions here
    
    public static void main(String[] args){
            // Your function calls here
    }
}
Sign up to request clarification or add additional context in comments.

1 Comment

this is GUI Application having many java classes. i showed only mail sending function.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.