gpt4 book ai didi

java - 无法发送邮件 - javax.mail.NoSuchProviderException : smtp

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:38:25 27 4
gpt4 key购买 nike

我正在尝试使用带有此代码的 apache james 发送电子邮件

public static void main(String[] args)
{

String user = "sumit"; // Newly created user on JAMES
String password = "sumit"; // user password

String fromAddress = "sumit@localhost"; // newlycreateduser@localhost
String toAddress = "sumitjain91@gmail.com";

// Create a mail session
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);
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 Server");
message.setText("Luke, I'm your father!!");
Transport.send(message);

System.out.println("Email sent successfully");
}
catch (MessagingException e)
{
e.printStackTrace();
}
}

我收到以下异常

javax.mail.NoSuchProviderException: smtp
at javax.mail.Session.getService(Session.java:784)
at javax.mail.Session.getTransport(Session.java:720)
at javax.mail.Session.getTransport(Session.java:660)
at javax.mail.Session.getTransport(Session.java:640)
at javax.mail.Session.getTransport(Session.java:697)
at javax.mail.Transport.send0(Transport.java:192)
at javax.mail.Transport.send(Transport.java:124)
at mail.Main.main(Main.java:44)

请帮忙

最佳答案

基于一些 googling ...

您的问题听起来像是类路径问题。

验证您的类路径中是否只有一个版本的 mail.jar 和 activation.jar。

关于java - 无法发送邮件 - javax.mail.NoSuchProviderException : smtp,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5473188/

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