我在使用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」作爲主機的示例,但我無法得到這一個正確的.... 這是我第一次做電子郵件程序,所以我非常無知這個。