Java Code Examples for org.apache.commons.mail.HtmlEmail#setMsg()
The following examples show how to use
org.apache.commons.mail.HtmlEmail#setMsg() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SendMailUtil.java From jeewx-boot with Apache License 2.0 | 6 votes |
/** * 发送普通邮件 * @param toMailAddr 收信人地址 * @param subject email主题 * @param message 发送email信息 */ public static boolean sendCommonMail(String toMailAddr, String subject, String message) { HtmlEmail hemail = new HtmlEmail(); try { SystemProperties systemProperties = ApplicationContextUtil.getBean(SystemProperties.class); hemail.setHostName(systemProperties.getSmtpHost()); hemail.setSmtpPort(getSmtpPort(systemProperties.getSender())); hemail.setCharset(charSet); hemail.addTo(toMailAddr); hemail.setFrom(systemProperties.getSender(), fromName); hemail.setAuthentication(systemProperties.getUser(), systemProperties.getPwd()); hemail.setSubject(subject); hemail.setMsg(message); hemail.send(); log.info("send email to "+toMailAddr+" OK!"); return true; } catch (Exception e) { e.printStackTrace(); log.info("send email to "+toMailAddr+" error!"+ e.toString()); return false; } }
Example 2
Source File: MailUtil.java From JARVIS with MIT License | 6 votes |
public void send(Mail mail) throws EmailException { // ����email HtmlEmail email = new HtmlEmail(); // ������SMTP���ͷ����������֣�163�����£�"smtp.163.com" email.setHostName(mail.getHost()); // �ַ����뼯������ email.setCharset(Mail.ENCODEING); // �ռ��˵����� email.addTo(mail.getReceiver()); // �����˵����� email.setFrom(mail.getSender(), mail.getName()); // �����Ҫ��֤��Ϣ�Ļ���������֤���û���-���롣�ֱ�Ϊ���������ʼ��������ϵ�ע�����ƺ����� email.setAuthentication(mail.getUsername(), mail.getPassword()); // Ҫ���͵��ʼ����� email.setSubject(mail.getSubject()); // Ҫ���͵���Ϣ������ʹ����HtmlEmail���������ʼ�������ʹ��HTML��ǩ email.setMsg(mail.getMessage()); //��Ӹ��� if(mail.getAttachment()!=null) email.attach(mail.getAttachment()); // ���� email.send(); System.out.println(mail.getSender() + " �����ʼ��� " + mail.getReceiver()); }
Example 3
Source File: SendMailUtil.java From Shop-for-JavaWeb with MIT License | 6 votes |
/** * 发送普通邮件 * * @param toMailAddr * 收信人地址 * @param subject * email主题 * @param message * 发送email信息 */ public static void sendCommonMail(String toMailAddr, String subject, String message) { HtmlEmail hemail = new HtmlEmail(); try { hemail.setHostName(getHost(from)); hemail.setSmtpPort(getSmtpPort(from)); hemail.setCharset(charSet); hemail.addTo(toMailAddr); hemail.setFrom(from, fromName); hemail.setAuthentication(username, password); hemail.setSubject(subject); hemail.setMsg(message); hemail.send(); System.out.println("email send true!"); } catch (Exception e) { e.printStackTrace(); System.out.println("email send error!"); } }
Example 4
Source File: SendMailUtil.java From jeewx with Apache License 2.0 | 6 votes |
/** * 发送普通邮件 * @param toMailAddr 收信人地址 * @param subject email主题 * @param message 发送email信息 */ public static void sendCommonMail(String toMailAddr, String subject, String message) { HtmlEmail hemail = new HtmlEmail(); try { hemail.setHostName(getHost(from)); hemail.setSmtpPort(getSmtpPort(from)); hemail.setCharset(charSet); hemail.addTo(toMailAddr); hemail.setFrom(from, fromName); hemail.setAuthentication(username, password); hemail.setSubject(subject); hemail.setMsg(message); hemail.send(); org.jeecgframework.core.util.LogUtil.info("email send true!"); } catch (Exception e) { e.printStackTrace(); org.jeecgframework.core.util.LogUtil.info("email send error!"); } }
Example 5
Source File: SendMailUtil.java From jeecg with Apache License 2.0 | 6 votes |
/** * 发送普通邮件 * @param toMailAddr 收信人地址 * @param subject email主题 * @param message 发送email信息 */ public static void sendCommonMail(String toMailAddr, String subject, String message) { HtmlEmail hemail = new HtmlEmail(); try { hemail.setHostName(getHost(from)); hemail.setSmtpPort(getSmtpPort(from)); hemail.setCharset(charSet); hemail.addTo(toMailAddr); hemail.setFrom(from, fromName); hemail.setAuthentication(username, password); hemail.setSubject(subject); hemail.setMsg(message); hemail.send(); org.jeecgframework.core.util.LogUtil.info("email send true!"); } catch (Exception e) { e.printStackTrace(); org.jeecgframework.core.util.LogUtil.info("email send error!"); } }
Example 6
Source File: MailUtil.java From open-capacity-platform with Apache License 2.0 | 5 votes |
/** * * @param toAddress 收件人邮箱 * @param mailSubject 邮件主题 * @param mailBody 邮件正文 * @return */ public static boolean sendMail(String toAddress, String mailSubject, String mailBody){ try { // Create the email message HtmlEmail email = new HtmlEmail(); //email.setDebug(true); // 将会打印一些log //email.setTLS(true); // 是否TLS校验,,某些邮箱需要TLS安全校验,同理有SSL校验 //email.setSSL(true); email.setHostName(PropertiesUtil.getString("xxl.job.mail.host")); if ("true".equals(PropertiesUtil.getString("xxl.job.mail.ssl"))) { email.setSslSmtpPort(PropertiesUtil.getString("xxl.job.mail.port")); email.setSSLOnConnect(true); } else { email.setSmtpPort(Integer.valueOf(PropertiesUtil.getString("xxl.job.mail.port"))); } email.setAuthenticator(new DefaultAuthenticator(PropertiesUtil.getString("xxl.job.mail.username"), PropertiesUtil.getString("xxl.job.mail.password"))); email.setCharset(Charset.defaultCharset().name()); email.setFrom(PropertiesUtil.getString("xxl.job.mail.username"), PropertiesUtil.getString("xxl.job.mail.sendNick")); email.addTo(toAddress); email.setSubject(mailSubject); email.setMsg(mailBody); //email.attach(attachment); // add the attachment email.send(); // send the email return true; } catch (EmailException e) { logger.error(e.getMessage(), e); } return false; }
Example 7
Source File: EmailUtils.java From frpMgr with MIT License | 5 votes |
/** * 发送邮件 * @param toAddress 接收地址 * @param subject 标题 * @param content 内容 * @return */ public static boolean send(String fromAddress, String fromPassword, String fromHostName, String sslOnConnect, String sslSmtpPort, String toAddress, String subject, String content) { try { HtmlEmail htmlEmail = new HtmlEmail(); // 发送地址 htmlEmail.setFrom(fromAddress); // 密码校验 htmlEmail.setAuthentication(fromAddress, fromPassword); // 发送服务器协议 htmlEmail.setHostName(fromHostName); // SSL if ("true".equals(sslOnConnect)) { htmlEmail.setSSLOnConnect(true); htmlEmail.setSslSmtpPort(sslSmtpPort); } // 接收地址 htmlEmail.addTo(toAddress); // 标题 htmlEmail.setSubject(subject); // 内容 htmlEmail.setMsg(content); // 其他信息 htmlEmail.setCharset("utf-8"); // 发送 htmlEmail.send(); return true; } catch (Exception ex) { logger.error(ex.getMessage(), ex); } return false; }
Example 8
Source File: MailUtil.java From zuihou-admin-boot with Apache License 2.0 | 5 votes |
/** * @param toAddress 收件人邮箱 * @param mailSubject 邮件主题 * @param mailBody 邮件正文 * @return */ public static boolean sendMail(String toAddress, String mailSubject, String mailBody) { try { // Create the email message HtmlEmail email = new HtmlEmail(); //email.setDebug(true); // 将会打印一些log //email.setTLS(true); // 是否TLS校验,,某些邮箱需要TLS安全校验,同理有SSL校验 //email.setSSL(true); email.setHostName(XxlJobAdminConfig.getAdminConfig().getMailHost()); if (XxlJobAdminConfig.getAdminConfig().isMailSSL()) { email.setSslSmtpPort(XxlJobAdminConfig.getAdminConfig().getMailPort()); email.setSSLOnConnect(true); } else { email.setSmtpPort(Integer.valueOf(XxlJobAdminConfig.getAdminConfig().getMailPort())); } email.setAuthenticator(new DefaultAuthenticator(XxlJobAdminConfig.getAdminConfig().getMailUsername(), XxlJobAdminConfig.getAdminConfig().getMailPassword())); email.setCharset("UTF-8"); email.setFrom(XxlJobAdminConfig.getAdminConfig().getMailUsername(), XxlJobAdminConfig.getAdminConfig().getMailSendNick()); email.addTo(toAddress); email.setSubject(mailSubject); email.setMsg(mailBody); //email.attach(attachment); // add the attachment email.send(); // send the email return true; } catch (EmailException e) { logger.error(e.getMessage(), e); } return false; }
Example 9
Source File: MailUtil.java From zuihou-admin-cloud with Apache License 2.0 | 5 votes |
/** * @param toAddress 收件人邮箱 * @param mailSubject 邮件主题 * @param mailBody 邮件正文 * @return */ public static boolean sendMail(String toAddress, String mailSubject, String mailBody) { try { // Create the email message HtmlEmail email = new HtmlEmail(); //email.setDebug(true); // 将会打印一些log //email.setTLS(true); // 是否TLS校验,,某些邮箱需要TLS安全校验,同理有SSL校验 //email.setSSL(true); email.setHostName(XxlJobAdminConfig.getAdminConfig().getMailHost()); if (XxlJobAdminConfig.getAdminConfig().isMailSSL()) { email.setSslSmtpPort(XxlJobAdminConfig.getAdminConfig().getMailPort()); email.setSSLOnConnect(true); } else { email.setSmtpPort(Integer.valueOf(XxlJobAdminConfig.getAdminConfig().getMailPort())); } email.setAuthenticator(new DefaultAuthenticator(XxlJobAdminConfig.getAdminConfig().getMailUsername(), XxlJobAdminConfig.getAdminConfig().getMailPassword())); email.setCharset("UTF-8"); email.setFrom(XxlJobAdminConfig.getAdminConfig().getMailUsername(), XxlJobAdminConfig.getAdminConfig().getMailSendNick()); email.addTo(toAddress); email.setSubject(mailSubject); email.setMsg(mailBody); //email.attach(attachment); // add the attachment email.send(); // send the email return true; } catch (EmailException e) { logger.error(e.getMessage(), e); } return false; }