Loading [MathJax]/jax/output/CommonHTML/config.js
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >java email发: Couldn't connect to host?

java email发: Couldn't connect to host?

提问于 2019-07-03 07:43:51
回答 0关注 0查看 1.6K

代码:

import java.util.Properties;

import javax.mail.Authenticator;

import javax.mail.Message;

import javax.mail.MessagingException;

import javax.mail.PasswordAuthentication;

import javax.mail.Session;

import javax.mail.Transport;

import javax.mail.internet.InternetAddress;

import javax.mail.internet.MimeMessage;

/**

* 使用SMTP协议发送电子邮件

*/

public class SendMailTest {

public static void main(String[] args) throws MessagingException {

// 1.创建一个程序与邮件服务器会话对象 Session

Properties props = new Properties();

props.setProperty("mail.transport.protocol", "SMTP");

props.setProperty("mail.smtp.host", "smtp.163.com");

props.setProperty("mail.smtp.port", "465");

// 指定验证为true

props.setProperty("mail.smtp.auth", "true");

props.setProperty("mail.smtp.timeout", "1000");

props.put("mail.smtp.ssl.enable", "true");

// 验证账号及密码,密码对应邮箱授权码(163密码可行,qq必须授权码)

Authenticator auth = new Authenticator() {

public PasswordAuthentication getPasswordAuthentication() {

return new PasswordAuthentication("xxxxx@163.com", "xxxx");

}

};

Session session = Session.getInstance(props, auth);

// 2.创建一个Message,它相当于是邮件内容

Message message = new MimeMessage(session);

// 设置发送者

message.setFrom(new InternetAddress("xxxxx@163.com"));

// 设置发送方式与接收者

message.setRecipient(MimeMessage.RecipientType.TO, new InternetAddress("xxxxx@qq.com"));

// 设置主题

message.setSubject("邮件发送测试");

// 设置内容

message.setContent("Hello!", "text/html;charset=utf-8");

// 3.创建 Transport用于将邮件发送

Transport.send(message);

}

}

报错:‘’

Exception in thread "main" com.sun.mail.util.MailConnectException: Couldn't connect to host, port: smtp.163.com, 465; timeout -1;

nested exception is:

java.net.ConnectException: Connection timed out: connect

at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:2209)

at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:740)

at javax.mail.Service.connect(Service.java:388)

at javax.mail.Service.connect(Service.java:246)

at javax.mail.Service.connect(Service.java:195)

at javax.mail.Transport.send0(Transport.java:254)

at javax.mail.Transport.send(Transport.java:124)

at org.mark.demo.service.impl.SendMailTest.main(SendMailTest.java:48)

回答

成为首答用户。去 写回答
相关文章
Ubuntu14.04上Fig出现Couldn’t connect to Docker daemon …问题
在Ubuntu 14.04上正确安装的Docker和Fig后,Docker可以正常使用,但是在使用Fig的时候出现下面的错误
星哥玩云
2022/07/04
4470
python smtplib发email
#!/usr/bin/env python #coding: utf-8 import smtplib from email.mime.text import MIMEText from email.header import Header sender = 'tom' receiver = ['john@sina.com', 'lili@163.com'] subject = 'python email test' smtpserver = 'smt
py3study
2020/01/16
8460
TortoiseGit Couldn’t load this key(unable to open file)
在使用TortoiseGit 配置了ppk后,有一个Git仓库每次更新的时候都会提示下面的错误!
全栈程序员站长
2022/07/19
8500
TortoiseGit Couldn’t load this key(unable to open file)
couldn’t transfer artifact_could not convert from to
本地仓库有对应的jar包,但是maven install 一直提示 Could not transfer artifact。折腾了我老半天
全栈程序员站长
2022/09/23
6360
couldn’t transfer artifact_could not convert from to
解决SSH连接错误ssh connect to host port 22 No route to host
SSH(Secure Shell)是在Linux系统中常用的远程连接工具,但有时我们可能会遇到"ssh: connect to host port 22: No route to host"错误,表明无法建立SSH连接。本文将参考并引用howtouselinux.com上的文章,详细介绍如何解决这个问题,并提供解决方法和实例。
用户10665603
2023/07/31
7.7K0
ssh: connect to host localhost port 22: Connection refused
百度搜索了好多文章都没能搞定,最后还是通过 bing 搜索(国际版) 搞定的,这里分享一下解决方案。
披头
2022/08/22
1.4K0
ssh: connect to host localhost port 22: Connection refused
Docker启动容器报错: connect: no route to host
笔者在重启了Docker服务后,发现其中一个api容器起不来了,这个容器在内部链接了另外一个MySQL容器,而那个MySQL容器是已经正常运行了。笔者通过docker logs container查看api容器启动日志,发现了这个错误:
肓己
2021/08/12
3.7K0
SQL Error (1130): Host IP is not allowed to connect to this MySQL server
SQL Error (1130): Host '192.168.1.100' is not allowed to connect to this MySQL server
用户7657330
2020/08/14
1.1K0
CDN: trunk URL couldn‘t be downloaded的解决办法
不管是使用RN还是使用Flutter,在创建项目的时候,都会在原生工程中进行一些依赖,但是iOS在使用CocosPod安装依赖包的时候不同的版本下载包的仓库是不一样的,所以经常会报如下的错误。
xiangzhihong
2022/11/30
4.7K0
Solr java.sql.SQLException: null, message from server: "Host 'xxx' is not allowed to connect to thi
  * host=169.254.18.%:只允许169.254.18.网段的可以访问
Arebirth
2020/06/19
1.3K0
Could not connect to Redis No route to host问题解决
最近一台电脑突然系统崩溃了,想做个新增节点的实验。由于之前装的都是ubuntu操作系统,于是想选个异构的REDHAT试试。
sparkexpert
2022/05/07
8900
ssh远程连接失败_ssh connect to host port 22
不少人在ssh连接远程机器时遇到过ssh_exchange_identification: Connection closed by remote host的问题,在网上找了一堆教程试了都不行,博主总结了常见的几种解决方法(以Ubuntu18.04为例)。
全栈程序员站长
2022/09/27
4.1K0
MySQL故障案例 | mysqldump: Couldn’t execute ‘SELECT COLUMN_NAME
https://dev.mysql.com/doc/refman/8.0/en/mysqldump.html#option_mysqldump_column-statistics
凡人学运维
2022/06/22
1.1K0
远程mysql_java.sql.SQLException: null, message from server: "Host 'xxx' is not allowed to connect
其实道理很简单,也就是说,远程的机器B不允许机器A访问他的数据库。也就是说,我们要解决这个问题,就是要让机器B的数据库允许
Hongten
2018/09/13
8640
远程mysql_java.sql.SQLException: null, message from server: "Host 'xxx' is not allowed to connect
ssh: connect to host github.com port 22: Connection refused
这与 ssh 的运行机制有关,找到 known_hosts 文件中对应 ip 的 RSA 并删除便可解决。
攻城狮杰森
2022/07/09
1.3K0
解决MySQL ERROR 1130 : Host 'XXXX' is not allowed to connect to this MySQL server
问题解决:登入mysql后,更改 "mysql" 数据库里的 "user" 表里的 "host" 项,从"localhost"改称"%",然后重启mysql这样就允许所有的远程机器进行访问了。 第一步:修改mysql表的host mysql -u root -proot mysql>use mysql; mysql>update user set host = '%' where user = 'root'; mysql>flush privileges; mysql>select host, use
挑战者
2018/06/29
3.8K3
怎么让Linux发邮件? Linux怎么发email
往下鼠标滚轮滚动会有四个服务我们看第二个IMAP服务 点击开启服务 验证你的信息 发个短信就行!
全栈程序员站长
2022/11/01
7.3K0
怎么让Linux发邮件? Linux怎么发email
异常解决——GitLab : ssh: connect to host port 22: Connection refused
自己搭了一个Gitlab服务器,在把本地项目上传到gitlab上,进行push的时候,提示ssh: connect to host port 22: Connection refused
执笔记忆的空白
2020/12/24
8.8K1
Xcode 报警告:The operation couldn’t be completed. (LaunchServicesError error 0.)
问题:Xcode7.2.1修改bundle identifier 后,运行报The operation couldn’t be completed. (LaunchServicesError erro
LeeCen
2018/10/11
1.3K0
Xcode 报警告:The operation couldn’t be completed. (LaunchServicesError error 0.)
如何解决ssh connect to host port 22 Connection refused
遇到 "ssh: connect to host host port 22: Connection refused" 错误通常意味着SSH服务器未运行或无法在指定端口上进行连接。以下是解决此问题的故障排除步骤:
用户10665603
2023/07/31
17.4K0

相似问题

提示 Couldn't resolve host 怎么办?

1628

ssh: connect to host port 22: Connection refused?

45.5K

Android SDK 集成报异常Couldn't load _imcore_jni_gyp?

1639

导入云通讯中的jar包,报:Couldn't load qalcodecwrapper: findLibrar...?

1353

2003 (HY000): Can't connect to MySQL server on?

0276
相关问答用户
腾讯 | 技术专家擅长2个领域
萃橙科技 | 合伙人擅长4个领域
擅长4个领域
添加站长 进交流群

领取专属 10元无门槛券

AI混元助手 在线答疑

扫码加入开发者社群
关注 腾讯云开发者公众号

洞察 腾讯核心技术

剖析业界实践案例

扫码关注腾讯云开发者公众号
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档