Java Code Examples for org.apache.commons.mail.SimpleEmail#setHostName()
The following examples show how to use
org.apache.commons.mail.SimpleEmail#setHostName() .
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: MailSenderDefaultImpl.java From minsx-framework with Apache License 2.0 | 7 votes |
public void finishInitial() { try { Integer sslPort = 465; simpleEmail = new SimpleEmail(); simpleEmail.setHostName(this.host); simpleEmail.setSmtpPort(this.port); simpleEmail.setAuthentication(this.username, this.password); simpleEmail.setFrom(this.from); simpleEmail.setCharset("UTF-8"); if (sslPort.equals(this.port)) { simpleEmail.setSSLOnConnect(true); } htmlEmail = new HtmlEmail(); htmlEmail.setHostName(this.host); htmlEmail.setSmtpPort(this.port); htmlEmail.setAuthentication(this.username, this.password); htmlEmail.setFrom(this.from); htmlEmail.setCharset("UTF-8"); if (sslPort.equals(this.port)) { htmlEmail.setSSLOnConnect(true); } } catch (EmailException e) { throw new MailSendException(String.format("Incorrect setting field of [from],cause: %s", e.getMessage()), e); } }
Example 2
Source File: MailUtil.java From shop with GNU General Public License v3.0 | 6 votes |
/** * 发送邮件给指定人,需要主题和内容 * @param user * @param title * @param content */ public static void sendMail(String user, String title, String content) { SimpleEmail email = new SimpleEmail(); email.setCharset("UTF8"); email.setHostName("smtp.163.com"); email.setAuthentication(USERNAME, PASSWORD); try { email.setFrom(USERNAME); email.addTo(user); email.setSubject(title); email.setMsg(content); email.send(); } catch (EmailException e) { e.printStackTrace(); } }
Example 3
Source File: SendEmail.java From sAINT with BSD 3-Clause "New" or "Revised" License | 6 votes |
public void sendSimpleEmail(String email_to, String subject, String msg) { SimpleEmail email = new SimpleEmail(); try { email.setDebug(debug); email.setHostName(smtp); email.addTo(email_to); email.setFrom(email_from); email.setAuthentication(email_from, email_password); email.setSubject(subject); email.setMsg(msg); email.setSSL(ssl); email.setTLS(tls); email.send(); } catch (EmailException e) { System.out.println(e.getMessage()); } }
Example 4
Source File: EmailManager.java From gameserver with Apache License 2.0 | 6 votes |
/** * Send a verification email to the user's email account if exist. * * @param user */ public void sendNormalEmail(String subject, String content, String[] addresses ) { if ( StringUtil.checkNotEmpty(subject) && StringUtil.checkNotEmpty(content) ) { try { String emailSmtp = GameDataManager.getInstance().getGameDataAsString(GameDataKey.EMAIL_SMTP, "mail.xinqihd.com"); SimpleEmail email = new SimpleEmail(); email.setHostName(emailSmtp); email.setAuthenticator(new DefaultAuthenticator(EMAIL_FROM, "xinqi@2012")); email.setFrom(EMAIL_FROM); email.setSubject(subject); email.setMsg(content); email.setCharset("GBK"); for ( String address : addresses) { if ( StringUtil.checkNotEmpty(address) ) { email.addTo(address); } } email.send(); } catch (EmailException e) { logger.debug("Failed to send normal email", e); } } }
Example 5
Source File: EmailVirtualSensor.java From gsn with GNU General Public License v3.0 | 5 votes |
public boolean initialize ( ) { TreeMap < String , String > params = getVirtualSensorConfiguration( ).getMainClassInitialParams( ); if(params.get(INITPARAM_SUBJECT) != null) subject = params.get(INITPARAM_SUBJECT); if(params.get(INITPARAM_RECEIVER) != null) receiverEmail = params.get(INITPARAM_RECEIVER); if(params.get(INITPARAM_SENDER) != null) senderEmail = params.get(INITPARAM_SENDER); else { logger.error( "The parameter *" + INITPARAM_SENDER + "* is missing from the virtual sensor processing class's initialization." ); logger.error( "Loading the virtual sensor failed" ); return false; } if(params.get(INITPARAM_SERVER) != null) mailServer = params.get(INITPARAM_SERVER); else { logger.error( "The parameter *" + INITPARAM_SERVER + "* is missing from the virtual sensor processing class's initialization." ); logger.error( "Loading the virtual sensor failed" ); return false; } try { email = new SimpleEmail(); email.setHostName(mailServer); email.setFrom(senderEmail); email.setSubject( subject ); } catch(Exception e) { logger.error( "Email initialization failed", e ); return false; } return true; }
Example 6
Source File: SendEmaiWithGmail.java From spring-boot with Apache License 2.0 | 4 votes |
/** * 用 commons 发送简单邮件 用 [email protected] (登录密码为 pass)发送邮件 * * @author jianghui * @param userName * gmail 用户名 test * @param password * gmail 密码 pass * @param subject * 邮件标题 * @param simpleEmailBody * 邮件内容 * @param from * 邮件显示的发信人.实际的发信地址为 gamil 邮箱地址 * @param to * 收件人邮件地址 * @param cc * 抄送人邮件地址,多个地址用分号";"隔开,如果没有,则为空字符串"" * @param bcc * 密送人邮件地址,多个地址用分号";"隔开,如果没有,则为空字符串"" * @throws EmailException */ public void sendsimpleEmail(String userName, String password, String subject, String simpleEmailBody, String from, String to, String cc, String bcc) throws EmailException { // 创建SimpleEmail对象 SimpleEmail email = new SimpleEmail(); // 显示调试信息用于IED中输出 email.setDebug(true); // 设置发送电子邮件的邮件服务器 email.setHostName("smtp.gmail.com"); // 邮件服务器是否使用ssl加密方式gmail就是,163就不是) email.setSSL(Boolean.TRUE); // 设置smtp端口号(需要查看邮件服务器的说明ssl加密之后端口号是不一样的) email.setSmtpPort(465); // 设置发送人的账号/密码 email.setAuthentication(userName, password); // 显示的发信人地址,实际地址为gmail的地址 email.setFrom(from); // 设置发件人的地址/称呼 // email.setFrom("[email protected]", "发送人"); // 收信人地址 email.addTo(to); // 设置收件人的账号/称呼) // email.addTo("[email protected]", "收件人"); // 多个抄送地址 StrTokenizer stokenCC = new StrTokenizer(cc.trim(), ";"); // 开始逐个抄送地址 for (int i = 0; i < stokenCC.getTokenArray().length; i++) { email.addCc((String) stokenCC.getTokenArray()[i]); } // 多个密送送地址 StrTokenizer stokenBCC = new StrTokenizer(bcc.trim(), ";"); // 开始逐个抄送地址 for (int i = 0; i < stokenBCC.getTokenArray().length; i++) { email.addBcc((String) stokenBCC.getTokenArray()[i]); } // Set the charset of the message. email.setCharset("UTF-8"); email.setSentDate(new Date()); // 设置标题,但是不能设置编码,commons 邮件的缺陷 email.setSubject(subject); // 设置邮件正文 email.setMsg(simpleEmailBody); // 就是send发送 email.send(); // 这个是我自己写的。 System.out.println("The SimpleEmail send sucessful!"); }