DEBUG SMTP: could not connect to host "host.domain.uk", port: 25, response: 421
I am using the java mail libary to try and send a confirmation email at the end of my program to say that everything went ok.
I am getting the error 'DEBUG SMTP: could not connect to host "host.domain.uk", port: 25, response: 421'
Here's some code;
Code :
private static void emaillog(){
// SUBSTITUTE YOUR EMAIL ADDRESSES HERE!!!
String to = "admin@domain";
String from = "system@domain";
// SUBSTITUTE YOUR ISP'S MAIL SERVER HERE!!!
String host = "smtp.domain.uk";
// Create properties for the Session
Properties props = new Properties();
// If using static Transport.send(),
// need to specify the mail server here
props.put("mail.smtp.host", host);
// To see what is going on behind the scene
props.put("mail.debug", "true");
// Get a session
Session session = Session.getInstance(props);
try {
// Get a Transport object to send e-mail
Transport bus = session.getTransport("smtp");
// Connect only once here
// Transport.send() disconnects after each send
// Usually, no username and password is required for SMTP
bus.connect();
// bus.connect("smtp.domain.uk", "admin", emailPassword);
// Instantiate a message
Message msg = new MimeMessage(session);
// Set message attributes
msg.setFrom(new InternetAddress(from));
InternetAddress[] address = {new InternetAddress(to)};
msg.setRecipients(Message.RecipientType.TO, address);
// Parse a comma-separated list of email addresses. Be strict.
msg.setRecipients(Message.RecipientType.CC,
InternetAddress.parse(to, true));
// Parse comma/space-separated list. Cut some slack.
msg.setRecipients(Message.RecipientType.BCC,
InternetAddress.parse(to, false));
msg.setSubject("Test E-Mail through Java");
msg.setSentDate(new Date());
// Set message content and send
setTextContent(msg);
msg.saveChanges();
bus.sendMessage(msg, address);
bus.close();
}
catch (MessagingException mex) {
// Prints all nested (chained) exceptions as well
mex.printStackTrace();
// How to access nested exceptions
while (mex.getNextException() != null) {
// Get next exception in chain
Exception ex = mex.getNextException();
ex.printStackTrace();
if (!(ex instanceof MessagingException)) break;
else mex = (MessagingException)ex;
}
}
}
I have a multifunction printer that emails successfully with these settings
Reception Protocol : SMTP
E-mail Reception Interval : On
: 15minute(s)
Max. Reception E-mail Size : 2 MB
E-mail Storage in Server : Off
SMTP
To Top
SMTP Server Name : smtp.domain.uk
SMTP Port No. : 25
SMTP Authentication : Off
SMTP Auth. E-mail Address :
SMTP Auth. Encryption : Auto Select
POP before SMTP
To Top
POP before SMTP : Off
POP E-mail Address :
Timeout setting after POP Auth. : 300 milli-second
POP3/IMAP4
To Top
POP3/IMAP4 Server Name :
POP3/IMAP4 Encryption : Auto Select
E-mail Communication Port
To Top
POP3 Reception Port No. : 110
IMAP4 Reception Port No. : 143