use of org.apache.commons.mail.DefaultAuthenticator in project Java-Tutorial by gpcodervn.
the class SendMailSSL method main.
public static void main(String[] args) throws EmailException {
// Tạo đối tượng Email
Email email = new SimpleEmail();
// Cấu hình thông tin Email Server
email.setHostName(MailConfig.HOST_NAME);
email.setSmtpPort(MailConfig.SSL_PORT);
email.setAuthenticator(new DefaultAuthenticator(MailConfig.APP_EMAIL, MailConfig.APP_PASSWORD));
email.setSSLOnConnect(true);
// Người gửi
email.setFrom(MailConfig.APP_EMAIL);
// Người nhận
email.addTo(MailConfig.RECEIVE_EMAIL);
// Tiêu đề
email.setSubject("Testing Subject");
// Nội dung email
email.setMsg("Welcome to gpcoder.com");
// send message
email.send();
System.out.println("Message sent successfully");
}
use of org.apache.commons.mail.DefaultAuthenticator in project Java-Tutorial by gpcodervn.
the class SendAttachment method main.
public static void main(String[] args) throws EmailException, MalformedURLException {
// Tạo một đối tượng đính kèm
String filename = "data/myfile.txt";
EmailAttachment attachment = new EmailAttachment();
attachment.setPath(filename);
attachment.setURL(new URL("https://gpcoder.com"));
attachment.setDisposition(EmailAttachment.ATTACHMENT);
attachment.setDescription("Gp coder");
attachment.setName("gpcoder");
// Tạo đối tượng Email
MultiPartEmail email = new MultiPartEmail();
// Cấu hình
email.setHostName(MailConfig.HOST_NAME);
email.setSmtpPort(MailConfig.SSL_PORT);
email.setAuthenticator(new DefaultAuthenticator(MailConfig.APP_EMAIL, MailConfig.APP_PASSWORD));
email.setSSLOnConnect(true);
// Người gửi
email.setFrom(MailConfig.APP_EMAIL);
// Người nhận
email.addTo(MailConfig.RECEIVE_EMAIL);
// Tiêu đề
email.setSubject("Testing Subject");
// Nội dung email
email.setMsg("Welcome to gpcoder.com");
// Thêm đính kèm
email.attach(attachment);
// Gửi email
email.send();
System.out.println("Sent!");
}
use of org.apache.commons.mail.DefaultAuthenticator in project dubidubi by lzzzz4.
the class MailUtils method sendMail.
public static boolean sendMail(MailDTO dto) {
boolean isSucess = false;
Email email = new HtmlEmail();
email.setHostName("smtp.qq.com");
email.setSmtpPort(465);
email.setAuthenticator(new DefaultAuthenticator("1622472966@qq.com", "lyvihlbjmafcbdab"));
email.setSSLOnConnect(true);
try {
// 发件人
email.setFrom("1622472966@qq.com");
// 邮箱头
email.setSubject(dto.getTitle());
// 邮箱身体
email.setContent("<h2>hhhh公司的验证码</h2><br><p><strong>验证码为" + dto.getContent() + "</strong></p><br>谢谢您的姿瓷", "text/html;charset=utf-8");
// email.setContent("<img
// src='http://img.99mm.net/small/2017/2389.jpg'></img>",
// "text/html;charset=utf-8");
email.addTo(dto.getMail());
email.send();
isSucess = true;
} catch (EmailException e) {
e.printStackTrace();
}
return isSucess;
}
use of org.apache.commons.mail.DefaultAuthenticator in project dhis2-core by dhis2.
the class EmailMessageSender method getHtmlEmail.
// -------------------------------------------------------------------------
// Supportive methods
// -------------------------------------------------------------------------
private HtmlEmail getHtmlEmail(String hostName, int port, String username, String password, boolean tls, String sender) throws EmailException {
HtmlEmail email = new HtmlEmail();
email.setHostName(hostName);
email.setFrom(sender, getEmailName());
email.setSmtpPort(port);
email.setStartTLSEnabled(tls);
if (username != null && password != null) {
email.setAuthenticator(new DefaultAuthenticator(username, password));
}
return email;
}
use of org.apache.commons.mail.DefaultAuthenticator in project graylog2-server by Graylog2.
the class EmailFactory method applyConfig.
private <T extends Email> T applyConfig(T email) throws EmailException {
email.setCharset(EmailConstants.UTF_8);
email.setHostName(configuration.getHostname());
email.setSmtpPort(configuration.getPort());
if (configuration.isUseSsl()) {
email.setSslSmtpPort(Integer.toString(configuration.getPort()));
}
if (configuration.isUseAuth()) {
email.setAuthenticator(new DefaultAuthenticator(Strings.nullToEmpty(configuration.getUsername()), Strings.nullToEmpty(configuration.getPassword())));
}
email.setSSLOnConnect(configuration.isUseSsl());
email.setStartTLSEnabled(configuration.isUseTls());
email.setFrom(configuration.getFromEmail());
return email;
}
Aggregations