@Signature public PHtmlEmail setFrom(String email, String name, String charset) throws EmailException { htmlEmail.setFrom(email, name, charset); return this; }
@Signature public PHtmlEmail setFrom(String email) throws EmailException { htmlEmail.setFrom(email); return this; }
@Signature public PHtmlEmail setFrom(String email, String name) throws EmailException { htmlEmail.setFrom(email, name); return this; }
HtmlEmail email = new HtmlEmail(); email.setHostName(mailserver); email.setAuthentication(username, password); email.setSmtpPort(port); email.setFrom(fromEmail); email.addTo(to); email.setSubject(subject); email.setTextMsg(textBody); email.setHtmlMsg(htmlBody); email.setDebug(true); email.send();
@Override public Email setFrom(String sender) { try { wrappedEmail.setFrom(sender); } catch (EmailException e) { throw new IllegalArgumentException("Could not set the sender of the email.", e); } return this; }
HtmlEmail email = new ImageHtmlEmail(); email.setHostName("mail.myserver.com"); email.addTo("jdoe@somewhere.org", "John Doe"); email.setFrom("me@apache.org", "Me"); email.setSubject("Test email with inline image"); // embed the image and get the content id URL url = new URL("http://www.apache.org/images/asf_logo_wide.gif"); String cid = email.embed(url, "Apache logo"); // set the html message email.setHtmlMsg(htmlEmailTemplate, new File("").toURI().toURL(), false);
private void createAndSendAlertEmail(String body) { try { log.info(String.format("Sending alert email to [%s]: %s", config.getRecipients(), body)); HtmlEmail email = new HtmlEmail(); email.setTextMsg(body); email.setFrom("esper-is-awesome@example.com"); email.setTo(Arrays.asList(new InternetAddress(config.getRecipients()))); email.setHostName(config.getHost()); email.setSmtpPort(config.getPort()); email.send(); } catch (Exception ex) { log.warn("Could not create or send email", ex); } } }
private boolean send(String title, String content, List<String> receivers) { try { HtmlEmail email = new HtmlEmail(); email.setAuthentication(Configuration.MAIL_SENDER_USERNAME, Configuration.MAIL_SENDER_PASSWORD); email.setHostName(Configuration.MAIL_SENDER_SMTP_HOST); email.setSmtpPort(Configuration.MAIL_SENDER_SMTP_PORT); email.setFrom(Configuration.MAIL_SENDER_USERNAME, Configuration.MAIL_SENDER_NAME); email.setSubject(title); email.setHtmlMsg(content); email.addTo(receivers.stream().toArray(String[]::new)); email.setCharset("UTF-8"); email.setSSLOnConnect(false); email.send(); logger.info("send mail to {} success", JSON.toJSONString(receivers)); return true; } catch (Exception e) { logger.error("send mail to {} fail, caused by", JSON.toJSONString(receivers), e); return false; } } }
public HtmlEmail buildHtmlEmail(String emailAddress, String displayName) throws Exception { HashMap<String, String> configMap = acqConifMap(); String hostName = configMap.get(EmailItemEnum.EMAIL_HOST.getItemKey()); String userName = configMap.get(EmailItemEnum.EMAIL_USERNAME.getItemKey()); String userPwd = configMap.get(EmailItemEnum.EMAIL_PWD.getItemKey()); // Create the email message HtmlEmail email = new HtmlEmail(); email.setAuthentication(userName, userPwd); email.setHostName(hostName); email.addTo(emailAddress, displayName); email.setFrom("msg@51xianqu.net", "CMDB"); email.setSubject("工单消息~"); email.setCharset("UTF-8"); // set the alternative message email.setTextMsg("Your email client does not support HTML messages"); return email; }
HtmlEmail email = new HtmlEmail(); email.setSubject("<your subject>"); email.setHtmlMsg("<your html message body>"); email.setHostName("<host>"); email.setFrom("<from_address>"); email.addTo("<recipient_address>"); email.send();
verify(mailMock).setSmtpPort(25); verify(mailMock).setAuthentication("user", "passwd"); verify(mailMock).setFrom("sender@example.com", "Sender Name"); verify(mailMock).addTo("test@example.com"); verify(mailMock).setSubject(any(String.class));
public static void main(String[] args) throws EmailException, MalformedURLException { // 创建 Email Message HtmlEmail email = new HtmlEmail(); email.setHostName("mail.myserver.com"); email.addTo("jdoe@somewhere.org", "John Doe"); email.setFrom("me@apache.org", "Me"); email.setSubject("Test email with inline image"); // 嵌入图片 URL url = new URL("http://www.apache.org/images/asf_logo_wide.gif"); String cid = email.embed(url, "Apache logo"); // 发送 HTML 内容 email.setHtmlMsg("<html>The apache logo - <img src=\"cid:"+cid+"\"></html>"); // 设置替代消息 email.setTextMsg("Your email client does not support HTML messages"); // 发送 email.send(); } }
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; }
HtmlEmail htmlEmail = new HtmlEmail(); htmlEmail.setHostName("smtp.gmail.com"); htmlEmail.setSmtpPort(587); htmlEmail.setDebug(true); htmlEmail.setAuthenticator(new DefaultAuthenticator("userId", "password")); htmlEmail.setTLS(true); htmlEmail.addTo("recipient@gmail.com", "recipient"); htmlEmail.setFrom("sender@gmail.com", "sender"); htmlEmail.setSubject("Send HTML email with body content from URI"); htmlEmail.setHtmlMsg(responseBody); htmlEmail.send();
private HtmlEmail createNewEmail(final SessionInfo session) throws EmailException { final HtmlEmail email = new HtmlEmail(); email.setCharset(Defaults.CHARSET.displayName()); // otherwise the e-mail contents are mangled email.setHostName(getSmtpHostname()); email.setSmtpPort(getSmtpPort()); email.setStartTLSRequired(isStartTlsRequired()); email.setSSLOnConnect(isSslOnConnectRequired()); if (isAuthenticationRequired()) { final String username = getSmtpUsername(); LOGGER.debug("Will contact SMTP server as '{}'.", username); email.setAuthentication(getSmtpUsername(), getSmtpPassword()); } else { LOGGER.debug("Will contact SMTP server anonymously."); } email.setFrom(getSender(), session.getName()); email.addTo(getRecipient()); return email; }
private HtmlEmail createNewEmail(final SessionInfo session) throws EmailException { final HtmlEmail email = new HtmlEmail(); email.setCharset(Defaults.CHARSET.displayName()); // otherwise the e-mail contents are mangled email.setHostName(getSmtpHostname()); email.setSmtpPort(getSmtpPort()); email.setStartTLSRequired(isStartTlsRequired()); email.setSSLOnConnect(isSslOnConnectRequired()); if (isAuthenticationRequired()) { final String username = getSmtpUsername(); LOGGER.debug("Will contact SMTP server as '{}'.", username); email.setAuthentication(getSmtpUsername(), getSmtpPassword()); } else { LOGGER.debug("Will contact SMTP server anonymously."); } email.setFrom(getSender(), session.getName()); email.addTo(getRecipient()); return email; }
private HtmlEmail createDefaultHtmlEmail() throws EmailException { final HtmlEmail htmlEmail = new HtmlEmail(); htmlEmail.setHostName(this.strTestMailServer); htmlEmail.setSmtpPort(this.getMailServerPort()); htmlEmail.setFrom("a@b.com"); htmlEmail.addTo("c@d.com"); return htmlEmail; } }
private static void initializeEmail(EmailSettings emailSettings) throws EmailException { _logger.info("{}", emailSettings); email = new HtmlEmail(); email.setHostName(emailSettings.getSmtpHost()); email.setSmtpPort(emailSettings.getSmtpPort()); if (emailSettings.getSmtpUsername() != null && emailSettings.getSmtpUsername().length() > 0) { email.setAuthenticator(new DefaultAuthenticator( emailSettings.getSmtpUsername(), emailSettings.getSmtpPassword())); } if (emailSettings.getEnableSsl()) { if (emailSettings.getUseStartTLS()) { email.setStartTLSEnabled(emailSettings.getEnableSsl()); } else { email.setSSLOnConnect(emailSettings.getEnableSsl()); } } email.setFrom(emailSettings.getFromAddress()); }
private static void initializeEmail(EmailSettings emailSettings) throws EmailException { _logger.info("{}", emailSettings); email = new HtmlEmail(); email.setHostName(emailSettings.getSmtpHost()); email.setSmtpPort(emailSettings.getSmtpPort()); if (emailSettings.getSmtpUsername() != null && emailSettings.getSmtpUsername().length() > 0) { email.setAuthenticator(new DefaultAuthenticator( emailSettings.getSmtpUsername(), emailSettings.getSmtpPassword())); } if (emailSettings.getEnableSsl()) { if (emailSettings.getUseStartTLS()) { email.setStartTLSEnabled(emailSettings.getEnableSsl()); } else { email.setSSLOnConnect(emailSettings.getEnableSsl()); } } email.setFrom(emailSettings.getFromAddress()); }
import org.apache.commons.mail.DefaultAuthenticator; import org.apache.commons.mail.EmailException; import org.apache.commons.mail.HtmlEmail; import play.mvc.Controller; import play.mvc.Result; public class MailController extends Controller { public Result sendEmail() throws EmailException { HtmlEmail email = new HtmlEmail(); String authuser = "..........@gmail.com"; String authpwd = "XXXXXX"; email.setSmtpPort(587); email.setAuthenticator(new DefaultAuthenticator(authuser, authpwd)); email.setDebug(true); email.setHostName("smtp.gmail.com"); email.setFrom("from@gmail.com", "SenderName"); email.setSubject("TestMail"); email.setHtmlMsg("<html><body><h1>welcome to u</h1></body></html>"); email.addTo("to@gmail.com", "receiver name"); email.setTLS(true); email.send(); return play.mvc.Results.ok("Success"); } }