Sending email with java Apache Commons Mail through Lotus Notes

て烟熏妆下的殇ゞ 提交于 2020-01-04 03:53:20

问题


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.


回答1:


You can use your Domino server running on your intranet as SMTP server but first you have to ask your admin if Domino has been set up to allow SMTP - and at the same time ask for the proper host name and port).




回答2:


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.



来源:https://stackoverflow.com/questions/14038819/sending-email-with-java-apache-commons-mail-through-lotus-notes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!