Could not connect to SMTP host: localhost, port: 25;

1、错误描述

DEBUG: setDebug: JavaMail version 1.3.3
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "localhost", port 25, isSSL false
Exception in thread "main" javax.mail.MessagingException: Could not connect to SMTP host: localhost, port: 25;
  nested exception is:
	java.net.ConnectException: Connection refused: connect
	at 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、错误原因

从报错可知,无法连接SMTP服务主机

3、解决办法

配置正确的SMTP服务主机,保证服务连接上

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();

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-10-13 07:58:26

Could not connect to SMTP host: localhost, port: 25;的相关文章

ssh: connect to host localhost port 22: Connection refused (2)

命令:ssh localhost 错误信息:ssh: connect to host localhost port 22: Connection refused 错误原因: 1.sshd 未安装 2.sshd 未启动 3.防火墙 解决方法: 1.确定安装sshd:  sudo apt-get install openssh-server 2.启动sshd: net start sshd 3.检查防火墙设置 检验方法: 输入命令:ssh localhost 若成功,则表示安装成功,且连接通过: 转

Ubuntu下 ssh : connect to host localhost port 22:Connection refused

Ubuntu下测试ssh时使用ssh localhost 命令,出现错误提示connect to host localhost port 22:Connection refused 造成这个错误的原因可能是ssh-server未安装或者未启动.ubuntu 11.10 默认安装openssh-client,但是木有安装server 运行 ps -e | grep ssh,查看是否有sshd进程 如果没有,说明server没启动,通过 /etc/init.d/ssh -start 启动server

connection failed: socket,host=localhost,port=8100,tcpNoDelay=1: java.net.ConnectException: Connect

JAVA.openOffice.myeclipse 报错原因:没有启动openOffice服务. 解决办法: 运行→cmd,输入: cd C:\Program Files (x86)\OpenOffice 4\program 回车 再输入 soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;" -nofirststartwizard 回车 再重新run as/debug asjava源码,就好了. connect

Linux--ssh: connect to host localhost port 22: Connection refused

今日在进行SSH免密码登陆的时候,使用SSH进行测试,抛出下面异常 ssh: connect to host localhost port 22: Connection refused 在网上收了下,答复很多,基本都是 1.没启动SSH 2.没安装SSH 3.没关防火墙 4.-. ,千篇一律. 上面的解决方案我都看了,但是还是不好使. 调研了些关于SSH的资料,内容如下, SSH:是一种安全通道协议,主要用来实现字符界面的远程登录,远程复制等功能(使用TCP的22号端口).SSH协议对通信双方的

mac connect to host localhost port 22: Connection refused

在Mac OS X 10.10.5学习hadoop的过程中,输入命令ssh localhost得到 ssh: connect to host localhost port 22: Connection refused 解决方法是选择系统偏好设置->选择共享->点击远程登录 然后再输入命令ssh localhost发现已经解决问题 找到解决方案来自于 http://stackoverflow.com/questions/6313929/how-do-i-open-port-22-in-os-x-

ubuntu安装配置ssh-connect to host localhost port 22: Connection refused

在安装ssh,经常出现 ssh: connect to host localhost port 22: Connection refused 从以下几点去检查: 1.是否安装ssh-server: 打开"终端窗口",输入"sudo ps -e |grep ssh"-->回车-->有sshd,说明ssh服务已经启动,如果没有启动,输入"sudo service ssh start"-->回车-->ssh服务就会启动.若无ss

ssh: connect to host localhost port 22: Connection refused

1.确定安装sshd: [html] view plaincopy $ sudo apt-get install openssh-server 2.启动sshd: [html] view plaincopy $ sudo net start sshd [html] view plaincopy $ sudo ufw disable 检验方法: 输入命令: [html] view plaincopy $ ssh localhost 若成功,则表示安装成功,且连接通过: 转载:http://blog

用phpmailer发送邮件提示SMTP Error: Could not connect to SMTP host解决办法

之前做项目的时候做了一个用phpmailer发送邮件的功能<CI框架结合PHPmailer发送邮件>,昨天步署上线(刚开始用新浪云,嫌贵,换成阿里了),测试的时候,发送邮件却意外报错了.......... 我擦,没上线的时候好好的,次次成功,刚开始我以为是smtp地址的问题(我用的163邮箱),后来改成了QQ邮箱,发现还是没有用,没办法,只好问度娘了,后来看着百度上的答案才明白除了google的smtp服务器收到请求"smtp"会接受,其他的服务器就像我用的163,QQ什么

hadoop启动start-all.sh出错(master: ssh: connect to host master port 22: Connection refused)

当我们打开系统输入hadoop启动命令start-all.sh时出现以下错误: [[email protected] ~]# start-all.sh starting namenode, logging to /usr/local/hadoop/libexec/../logs/hadoop-root-namenode-master.out master: ssh: connect to host master port 22: Network is unreachable master: ss