Hi everyone, I'm trying to test out Javamail by sending myself an email with Gmail's SMTP server. I've followed Send email with SMTPS (eg. Google GMail) (Javamail) - Real's Java How-to but I'm still getting an error. My code and the console output is below
Java Code:
package sendMail;

import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;

public class Send {
	public static void main(String args[]) throws Exception {
		new Send().test();
	}
	
	public void test() throws Exception {
		Properties prop = new Properties();
		prop.put("mail.transport.protocol", "smtps");
		prop.put("mail.smtps.host", "smtp.gmail.com");
		prop.put("mail.smtps.auth", "true");
	
		Session mailSession = Session.getDefaultInstance(prop);
		mailSession.setDebug(true); // ***************************************************
		Transport transport = mailSession.getTransport();
		
		MimeMessage message = new MimeMessage(mailSession);
		message.setSubject("Testing javamail plain");
		message.setContent("Test", "text/plain");
		message.addRecipient(Message.RecipientType.TO, new InternetAddress("fred_liu@scotiacapital.com"));
		
		transport.connect("smtp.gmail.com", 465, "fredtestscotia@gmail.com", "PASSWORDHERE");
		transport.sendMessage(message, message.getRecipients(Message.RecipientType.TO));
		transport.close();
	}
}
The output is
DEBUG: setDebug: JavaMail version 1.4.4
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport ,Sun Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "smtp.gmail.com", port 465, isSSL true
Exception in thread "main" javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 465;
nested exception is:
java.net.ConnectException: Connection timed out: connect
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTra nsport.java:1934)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SM TPTransport.java:638)
at javax.mail.Service.connect(Service.java:295)
at sendMail.Send.test(Send.java:27)
at sendMail.Send.main(Send.java:9)
Caused by: java.net.ConnectException: Connection timed out: connect
at java.net.TwoStacksPlainSocketImpl.socketConnect(Na tive Method)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress( Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at sun.security.ssl.SSLSocketImpl.connect(Unknown Source)
at sun.security.ssl.BaseSSLSocketImpl.connect(Unknown Source)
at com.sun.mail.util.SocketFetcher.createSocket(Socke tFetcher.java:288)
at com.sun.mail.util.SocketFetcher.getSocket(SocketFe tcher.java:231)
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTra nsport.java:1900)
... 4 more
How can I fix this?