简体   繁体   中英

Sending email with java Apache Commons Mail through Lotus Notes

I'm having trouble with my e-mail configuration for sending e-mails using lotus notes in a java program. I know this is pretty much straight forward but i guess i'm missing something. My code is as follows;

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("recipient@company.com");
        email.setFrom("sender@agency.com");
        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();
  }
}

I keep on getting this error

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)

I'm guessing it's about my host but not really sure what to do about it. From my understanding your host should be your email client (ex. mail.smtp.google.com). But since this is Lotus Notes (it runs in our intranet btw) the implimentation will be different. I've seen other samples that use the "mail.smtp.host" as host but i can't get this one right.... It's my first time doing an e-mail program so i'm pretty much clueless about this.

您可以将在Intranet上运行的Domino服务器用作SMTP服务器,但首先您必须询问您的管理员是否已将Domino设置为允许SMTP - 同时请求正确的主机名和端口)。

setHostName requires the hostname or IP-address of a smtp server. And the exception makes it very clear what the issue is.

Lotus Notes is basicslly just a client and has nothing to do with what you are trying to accomplish.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM