gpt4 book ai didi

java - 使用 Apache James 无法发送电子邮件

转载 作者:太空宇宙 更新时间:2023-11-04 08:17:29 24 4
gpt4 key购买 nike

我正在尝试使用 apache james 发送电子邮件,但电子邮件未送达。下面是我的代码。

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

public class test {

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

String user = "test";

String password = "test";
String fromAddress = "test@localhost";
String toAddress = "test@gmail.com";
Properties properties = new Properties();
properties.put("mail.smtp.host", "localhost");
properties.put("mail.smtp.port", "25");
properties.put("mail.smtp.username", user);
properties.put("mail.smtp.password", password);
properties.put("mail.transport.protocol", "smtp");

Session session = Session.getDefaultInstance(properties, null);

try
{
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(fromAddress));
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(toAddress));
message.setSubject("Email from our JAMEs");
message.setText("hiiiiii!!");
Transport.send(message);
System.out.println("Email sent");
}
catch (MessagingException e)
{
e.printStackTrace();
}
}
}

还在 apache james 中添加了测试用户,并具有密码测试。请求您同样帮助我。

最佳答案

我认为由此引起的问题:

电子邮件服务器在接受任何邮件之前都会执行反向 DNS 查询。他们检查电子邮件来自的域的 IP 以及电子邮件真正来自的 IP。

如果域的 IP 和电子邮件发件人的 IP 不匹配,邮件服务器会认为该电子邮件是垃圾邮件。

这里,由于您的域(localhost)不是有效地址,因此当电子邮件服务器发送反向 DNS 查询时未获取 IP 并认为您的邮件是垃圾邮件。

有关更多信息,请查看:http://wiki.junkemailfilter.com/index.php/Fixing_Reverse_DNS

关于java - 使用 Apache James 无法发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10172502/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com