简体   繁体   中英

Problem sending mail with Apache Commons email

I'm trying to send a simple text email using commons email

    Email email = new SimpleEmail();
    email.setHostName("smtp.gmail.com");
    email.setSmtpPort(587);
    email.setAuthenticator(new DefaultAuthenticator("user@gmail.com", "123456"));
    email.setTLS(true);
    email.setFrom(from);
    email.setSubject(subject);
    email.setMsg(mesage);
    email.addTo("to@gmail.com");
    email.send();

But when I try to send the email ,I get this exception: 在此输入图像描述

Am I missing something?

Yes, you need the JavaMail API JAR as well (this is the javax.mail package).

Commons Email sits on top of the JavaMail API and makes it a little less awful to use.

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