我在使用Lotus程序中的莲花笔记发送电子邮件时遇到了电子邮件配置问题。我知道这很简单,但我想我错过了一些东西。我的代码如下;通过Lotus Notes发送带有Java Apache Commons邮件的电子邮件
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.SimpleEmail;
public class MailClass {
public void SendMail() {
SimpleEmail email = new SimpleEmail();
try {
email.setHostName("mail.smtp.host");
email.addTo("[email protected]");
email.setFrom("[email protected]");
email.setSubject("Hello World");
email.setMsg("This is a simple test of commons-email");
email.send();
} catch (EmailException ex) {
Logger.getLogger(MailClass4.class.getName()).log(Level.SEVERE, null, ex);
}
}
public static void main(String[] args) {
MailClass main = new MailClass();
main.SendMail();
}
}
我不断收到此错误
SEVERE: null
org.apache.commons.mail.EmailException: Sending the email to the following server failed : mail.smtp.host:25
at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1242)
...
Caused by: javax.mail.MessagingException: Unknown SMTP host: mail.smtp.host;
nested exception is:java.net.UnknownHostException: mail.smtp.host at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1970)
我猜这是关于我的主机,但真的不知道该怎么办才好。根据我的理解,您的主机应该是您的电子邮件客户端(例如mail.smtp.google.com)。但是,由于这是Lotus Notes(它在我们的Intranet btw中运行),实现会有所不同。我已经看到其他使用“mail.smtp.host”作为主机的示例,但我无法得到这一个正确的.... 这是我第一次做电子邮件程序,所以我非常无知这个。