Failed to send email using javamail api on linux
Here is my code it works on windows machine but it doesn't work on linux ... it doesn't throw any exceptions .. on linux
public void alert(String recipient, String subject , String error){
final String username = customize.getString("alertSenderEmail");
final String password = customize.getString("alertSenderPassword");
Properties props = new Properties();
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.auth", "true");
props.put("mail.debug", "false");
props.put("mail.smtp.host", "smtp1.qualitykiosk.com");
props.put("mail.smtp.port", "25");
Session session = Session.getInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
session.setDebug(true);
String[] receivers = recipient.split(",");
for (String receiver : receivers) {
try {
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(username));
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(receiver));
message.setSubject(subject);
message.setText(error);
Transport.send(message);
System.out.println("Done");
} catch (MessagingException e) {
//throw new RuntimeException(e);
}
}
}
Mistake -:
DEBUG: setDebug: JavaMail version 1.4ea
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "smtp1.qualitykiosk.com", port 25, isSSL false
220 ESMTP ESMTP
DEBUG SMTP: connected to host "smtp1.qualitykiosk.com", port: 25
EHLO
501 Syntax: EHLO hostname
HELO
501 Syntax: HELO hostname
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "smtp1.qualitykiosk.com", port 25, isSSL false
220 ESMTP ESMTP
DEBUG SMTP: connected to host "smtp1.qualitykiosk.com", port: 25
EHLO
501 Syntax: EHLO hostname
HELO
501 Syntax: HELO hostname
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "smtp1.qualitykiosk.com", port 25, isSSL false
220 ESMTP ESMTP
DEBUG SMTP: connected to host "smtp1.qualitykiosk.com", port: 25
EHLO
501 Syntax: EHLO hostname
HELO
501 Syntax: HELO hostname
source to share
This can happen if Java / JavaMail is unable to determine your current hostname. Use the property mail.smtp.localhost
to explicitly specify the hostname for EHLO
/ HELO
.
From https://javamail.java.net/nonav/docs/api/com/sun/mail/smtp/package-summary.html :
mail.smtp.localhost
String
The local hostname used in the SMTP HELO or EHLO command. By defaultInetAddress.getLocalHost().getHostName()
. Usually you don't need to install if your JDK and your naming service are configured correctly.
As a longer term solution, you may need to figure out why InetAddress.getLocalHost().getHostName()
(apparently) it is not returning the hostname.
source to share