java - 我可以使用 Java 代码从 Windows Server 2012 RS 发送邮件吗?
问题描述
我最初尝试编写代码以从 localhost 发送邮件,但我不确定如何设置服务器。浏览了有关此的帮助主题,并没有太大帮助。
是否可以编写 Java 代码从 Windows Server 2012 发送邮件?
如果没有,请帮我在我的 Windows Server 2012 中设置 localhost。我迷路了。
这是我使用的代码:
public static void main(String[] args) throws AddressException, MessagingException {
Properties props = new Properties();
props.put("mail.smtp.host", "10.204.10.116");
props.put("mail.smtp.port", "443");
props.put("mail.debug", "true");
Session session = Session.getDefaultInstance(props);
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress("abc@gmail.com"));
message.setRecipient(RecipientType.TO, new InternetAddress("xyz@gmail.com"));
message.setSubject("Notification");
message.setText("Successful!", "UTF-8"); // as "text/plain"
message.setSentDate(new Date());
Transport.send(message);
}
}
这是我得到的错误:
Exception in thread "main" javax.mail.MessagingException: Could not connect to SMTP host: 10.204.10.116, port: 443;
nested exception is:
java.net.ConnectException: Connection timed out: connect
不知道我应该如何处理这个错误。
解决方案
推荐阅读
- python - 从两个元组python3创建单个元组
- binary-search-tree - 二叉搜索树 - Javascript - 两个节点之间的距离
- excel - 动态创建的表单控件标签上的 MouseMove 事件
- core-data - 我可以使用单个 privateQueueConcurrencyType 托管对象上下文而没有主队列的 MOC 吗?
- git - Git 发出的这条 LF 和 CRLF 警告信息是什么意思?
- java - 程序制作的 Big-O 运行时
- html - 如何划分html页面
- sql - 如何获取表中两列的唯一值计数?
- python - 用多列熔化 Df
- android - 有没有更好更简单的方法来优化 kotlin 中的辅助回调和处理程序代码?