1. Error description
DEBUG:setDebug:JavaMail version 1.3.3debug:getprovider () returning JAVAX.MAIL.PROVIDER[TRANSPORT,SMTP, Com.sun.mail.smtp.smtptransport,sun Microsystems, Inc]debug Smtp:useehlo True, Useauth TrueDEBUG smtp:trying to connect To host ' localhost ', port, Isssl falseexception in thread ' main ' javax.mail.MessagingException:Could not connect to S MTP Host:localhost, port:25; Nested exception is:java.net.ConnectException:Connection Refused:connectat Com.sun.mail.smtp.SMTPTransport.openServer (smtptransport.java:1227) at Com.sun.mail.smtp.SMTPTransport.protocolConnect (smtptransport.java:322) at Javax.mail.Service.connect ( service.java:236) at Javax.mail.Service.connect (service.java:137) at Com.you.mail.model.SendMessage.sendMessage ( SENDMESSAGE.JAVA:70) at Com.you.mail.model.SendMessage.main (sendmessage.java:89)
2. Cause of error
Unable to connect to SMTP service host from error
3. Solutions
Configure the correct SMTP service host to ensure that the service is connected
String Server = "smtp.163.com"; String username = ""; String password = ""; Transport Transport = Session.gettransport () transport.connect (server, username, password); Transport.sendmessage ( Message, message.getrecipients (Message.RecipientType.TO)); Transport.close ();
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Could not connect to SMTP host:localhost, port:25;