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();
ApacheCommonsEmail(String hostname, int smtpPort, boolean useSsl, boolean useTls, String user, String password, HtmlEmail wrappedEmail) { this.wrappedEmail = wrappedEmail; this.wrappedEmail.setHostName(hostname); this.wrappedEmail.setSmtpPort(smtpPort); this.wrappedEmail.setSSLOnConnect(useSsl); this.wrappedEmail.setStartTLSEnabled(useTls); if (!isNullOrEmpty(user) && !isNullOrEmpty(password)) { this.wrappedEmail.setAuthentication(user, password); } this.wrappedEmail.setDebug(false); }
email.setHostName(hostName); email.setSmtpPort(Integer.parseInt(smtpPort)); email.setDebug(true); Iterator it = toEmails.keySet().iterator(); while (it.hasNext()) {
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();
public void sendHtmlEmail(String toEmail, String toName, String subject, String htmlMsg, String senderMail, String senderName, String mail_userName, String mail_password, String smtpPort) throws Exception { try { HtmlEmail email = new HtmlEmail(); MailServerInfo msi = (MailServerInfo)serverinfos.get(this.getMailDomain(senderMail)); String hostName = msi.getSmtpServer(); String sender_Mail = senderMail == null ? msi.getMailSender() : senderMail; String sender_Name = senderName == null ? msi.getMailSenderName() : senderName; String mailUserName = mail_userName == null ? msi.getMail_userName() : mail_userName; String mailPassword = mail_password == null ? msi.getMail_password() : mail_password; email.setAuthentication(mailUserName, mailPassword); email.setHostName(hostName); email.setSmtpPort(Integer.parseInt(smtpPort)); email.addTo(toEmail, toName); email.setFrom(sender_Mail, sender_Name); email.setSubject(subject); // email.setContent("HtmlEmail", "text/plain; charset=utf-8"); email.setHtmlMsg(htmlMsg); email.setTextMsg("Your email client does not support HTML messages"); email.setDebug(true); email.send(); } catch (EmailException e) { e.printStackTrace(); throw e; } }
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"); } }
email.setDebug(true);