Could Not Connect to Smtp Host

Could not connect to SMTP host: smtp.gmail.com, port: 587; nested exception is: java.net.ConnectException: Connection timed out: connect

As I said, there's nothing wrong with your code. If anything, just to do some testing, try to drop the Authentication part to see if that works:

    public void sendPlainTextEmail(String host, String port,
final String userName, final String password, String toAddress,
String subject, String message) throws AddressException,
MessagingException {

// sets SMTP server properties
Properties properties = new Properties();
properties.put("mail.smtp.host", host);
properties.put("mail.smtp.port", port);
properties.put("mail.smtp.auth", "true");
properties.put("mail.smtp.starttls.enable", "true");
// *** BEGIN CHANGE
properties.put("mail.smtp.user", userName);

// creates a new session, no Authenticator (will connect() later)
Session session = Session.getDefaultInstance(properties);
// *** END CHANGE

// creates a new e-mail message
Message msg = new MimeMessage(session);

msg.setFrom(new InternetAddress(userName));
InternetAddress[] toAddresses = { new InternetAddress(toAddress) };
msg.setRecipients(Message.RecipientType.TO, toAddresses);
msg.setSubject(subject);
msg.setSentDate(new Date());
// set plain text message
msg.setText(message);

// *** BEGIN CHANGE
// sends the e-mail
Transport t = session.getTransport("smtp");
t.connect(userName, password);
t.sendMessage(msg, msg.getAllRecipients());
t.close();
// *** END CHANGE

}

That's the code I'm using every day to send dozens of emails from my application, and it is 100% guaranteed to work -- as long as smtp.gmail.com:587 is reachable, of course.

SMTP Error: Could not connect to SMTP host

It sounds like your web host is blocking outbound connections to smtp.gmail.com:465. Suggestions:

  1. Verify: If you have shell/terminal access to your web hosting server, try a telnet test to verify that they are in fact blocking this. Run telnet smtp.gmail.com 465

  2. Contact: Call or email your hosting provider and find out what SMTP server they provide for outbound relay. Make sure they know you want to use your @gmail.com address as the From/Reply-to address.

  3. Update code: Once your host provides you with a different mail server, update your code and try again.

If your web host doesn't allow outbound relay from its servers at all, then you need to look at switching hosts, if this is a requirement for your application.

PHPMailer: Could not connect to SMTP host

$mailer->Host = 'ssl://smtp.gmail.com:465';

Sending mail error, javax.mail.MessagingException: Could not connect to SMTP host: localhost, port: 25;

Error is self explainatory: javax.mail.MessagingException: Could not connect to SMTP host: localhost, port: 25;

You have no SMTP server on localhost, but you configure it there :

  // Assuming you are sending email from localhost
String host = "localhost";
...
// Setup mail server
properties.setProperty("mail.smtp.host", host);

So you must:

  • either configure a local SMTP server as a relay on your local system (Postfix or sendmail are two well knows servers)
  • of configure a dummy server that simply traces the mail request but does not even try to deliver mail (Python is known to have such dummy servers out of the box)
  • or configure your application with a server that you are allowed to use - contact your system admin in a corporate environment, or your ISP in an individual one. Anyway, you will need that even to configure a true relay.

Jenkins Email Plugin : Could not connect to SMTP host: smtp.gmail.com, port: 465;

Caused by: java.net.ConnectException: Connection timed out: connect

This doesn't have anything to do with recent security changes to the Mailer plugin, or to settings in Gmail — it's saying that your Jenkins server cannot connect to smtp.gmail.com:465. Presumably due to some issue within your network, or a firewall rule, or blocking by your ISP.

You should check with your network administrator, and ask them whether there's a more appropriate SMTP server that you should be using.



Related Topics



Leave a reply



Submit