I have a problem, which is that when I send an attachment via Gmail inside NetBeans, the program works and sends messages as it should, but when I try to run the jar file from NetBeans, the program does not show the dialog box that prints the number 3. This means that the problem starts from this line MultiPartEmail email = new MultiPartEmail(); The program remains in execution without throwing the exception or printing the number 3.
Knowing that the program uses several libraries, all of which work as they should From jar file.
I also tried a library javax-mail.jar. I encountered the same problem, as the program works well inside NetBeans, but the jar file does not work in sending messages only.
This is my Full class code:
package FTPEmail;
import org.apache.commons.mail.DefaultAuthenticator;
import org.apache.commons.mail.EmailAttachment;
import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.MultiPartEmail;
import java.io.IOException;
public class SendAttachment {
public SendAttachment(String attachment, String subject, String msg) throws IOException {
final String sender = "[email protected]";
final String receiver = "[email protected]";
final String password = "abc123abc123abc1";
Tools.Text.dialogErrorNumber("1");
try {
EmailAttachment emailAttachment = new EmailAttachment();
emailAttachment.setPath(attachment);
emailAttachment.setDisposition(EmailAttachment.ATTACHMENT);
emailAttachment.setDescription("Attachment");
Tools.Text.dialogErrorNumber("2");
MultiPartEmail email = new MultiPartEmail();
Tools.Text.dialogErrorNumber("3");
email.setHostName("smtp.gmail.com");
Tools.Text.dialogErrorNumber("4");
email.setSmtpPort(465);
Tools.Text.dialogErrorNumber("5");
email.setAuthenticator(new DefaultAuthenticator(sender, password));
Tools.Text.dialogErrorNumber("6");
email.setSSLOnConnect(true);
Tools.Text.dialogErrorNumber("7");
email.addTo(receiver);
Tools.Text.dialogErrorNumber("8");
email.setFrom(sender);
Tools.Text.dialogErrorNumber("9");
email.setSubject(subject);
Tools.Text.dialogErrorNumber("10");
email.setMsg(msg);
Tools.Text.dialogErrorNumber("11");
// attach the file
email.attach(emailAttachment);
Tools.Text.dialogErrorNumber("12");
// send the email
email.send();
} catch (EmailException e) {
Tools.Text.dialogErrorNumber(e.getMessage());
Tools.Text.dialogErrorNumber("0060");
}
}
}