public static void main(String[] args) { try { String htmlEmailTemplate = ".... <img src=\"http://www.apache.org/images/feather.gif\"> ...."; URL url = new URL("http://www.apache.org"); ImageHtmlEmail email = new ImageHtmlEmail(); email.setDataSourceResolver(new DataSourceUrlResolver(url)); email.setHostName("HERA.i-heart.co.kr"); email.setSmtpPort(587); email.setAuthenticator(new DefaultAuthenticator("*****@*****.**", "tjddlsdpdltm6*")); email.setFrom("*****@*****.**"); email.setSubject("TestMail"); email.setMsg("This is a test mail ... :-)"); // 여기서는 이놈이 안보일거임. email.addTo("*****@*****.**"); email.setDebug(true); // HTML Message 세팅 email.setHtmlMsg(htmlEmailTemplate); // Client가 HTML Message를 지원하지 않으면 TextMsg를 띄워준다. email.setTextMsg("Your email client does not support HTML messages"); email.send(); } catch (EmailException e) { e.printStackTrace(); } catch (MalformedURLException e) { e.printStackTrace(); } }
public void handle(Message msg, Session sess) throws IOException { Email email = Json.fromJson(Email.class, msg.getBodyString()); try { email.send(); } catch (EmailException e) { e.printStackTrace(); } }
public void sendEmailConfirmacao(Empresa empresa) { String link = "http://www.extratosfacil.com.br/confirmar.html?sb{bpTpdjbm=" + this.crip(empresa.getRazaoSocial()); String mensagem = "<p>Cadastro realizado com sucesso. Clique no link para confirmar: </p>"; String assunto = "Cadastro Extratos F�cil"; try { Email.sendEmail(empresa.getEmail(), empresa.getNomeFantasia(), assunto, mensagem, link); } catch (EmailException e) { e.printStackTrace(); } }
// public static void sendFileMail() throws MessagingException { // JavaMailSenderImpl senderImpl = new JavaMailSenderImpl(); // // // 设定mail server // senderImpl.setHost("smtp.sina.com.cn"); // senderImpl.setUsername("*****@*****.**"); // senderImpl.setPassword("kimi3213.1415926"); // // 建立HTML邮件消息 // MimeMessage mailMessage = senderImpl.createMimeMessage(); // // true表示开始附件模式 // MimeMessageHelper messageHelper = new MimeMessageHelper(mailMessage, true, "utf-8"); // // // 设置收件人,寄件人 // messageHelper.setTo("*****@*****.**"); // messageHelper.setFrom("*****@*****.**"); // messageHelper.setSubject("测试邮件!"); // // true 表示启动HTML格式的邮件 // messageHelper.setText("<html><head></head><body><h1>你好:附件!!</h1></body></html>", true); // // // FileSystemResource file = new FileSystemResource(new File("d:/log.txt")); // // // try { // //附件名有中文可能出现乱码 // messageHelper.addAttachment(MimeUtility.encodeWord("log.txt"), file); // } catch (UnsupportedEncodingException e) { // e.printStackTrace(); // throw new MessagingException(); // } // // 发送邮件 // senderImpl.send(mailMessage); // System.out.println("邮件发送成功....."); // // } public static void sendMutiMessage() { MultiPartEmail email = new MultiPartEmail(); String[] multiPaths = new String[] {"d:/output.xls"}; List<EmailAttachment> list = new ArrayList<EmailAttachment>(); for (int j = 0; j < multiPaths.length; j++) { EmailAttachment attachment = new EmailAttachment(); // 判断当前这个文件路径是否在本地 如果是:setPath 否则 setURL; if (multiPaths[j].indexOf("http") == -1) { attachment.setPath(multiPaths[j]); } else { try { attachment.setURL(new URL(multiPaths[j])); } catch (MalformedURLException e) { e.printStackTrace(); } } attachment.setDisposition(EmailAttachment.ATTACHMENT); attachment.setDescription("Picture of John"); list.add(attachment); } try { // 这里是发送服务器的名字: email.setHostName("smtp.sina.com.cn"); // 编码集的设置 email.setCharset("utf-8"); // 收件人的邮箱 email.addTo("*****@*****.**"); // 发送人的邮箱 email.setFrom("*****@*****.**"); // 如果需要认证信息的话,设置认证:用户名-密码。分别为发件人在邮件服务器上的注册名称和密码 email.setAuthentication("*****@*****.**", "kimi3213.1415926"); email.setSubject("设备监控数据"); // 要发送的信息 email.setMsg("详情请见附件"); for (int a = 0; a < list.size(); a++) // 添加多个附件 { email.attach(list.get(a)); } // 发送 email.send(); } catch (EmailException e) { e.printStackTrace(); } }
/** * @param username 用户名 * @param ip 用户登录时的Ip * @param time 用户登录的时间 */ public void sendEmail(String username, String ip, String time) { SimpleEmail simpleEmail = new SimpleEmail(); simpleEmail.setAuthentication("*****@*****.**", "Q2889144"); simpleEmail.setHostName("smtp.126.com"); simpleEmail.setSmtpPort(25); simpleEmail.setCharset("utf-8"); try { simpleEmail.setFrom("*****@*****.**"); simpleEmail.addTo("*****@*****.**"); simpleEmail.setMsg(time + ",用户:" + username + "在" + ip + "登录"); simpleEmail.setSubject("开会"); simpleEmail.send(); } catch (EmailException e) { e.printStackTrace(); } }
public static void sendEmail(String feedbackTo, String subject, String message) { SimpleEmail email = new SimpleEmail(); try { email.setHostName( ApplicationConfig.getInstance() .getProperty(Constants.CONFIG_PROPERTIES.FEEDBACK_EMAIL_HOST)); email.addTo(feedbackTo); email.setFrom( ApplicationConfig.getInstance().getProperty(Constants.CONFIG_PROPERTIES.FEEDBACK_FROM)); email.setSubject(subject); email.setMsg(message); email.send(); } catch (EmailException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
public void sendEmail() { try { List<Emails> emails = emailsDao.getEmailsByStatus('N'); if (!ITeachUtility.isEmptyList(emails)) { for (Emails emailToSend : emails) { try { HtmlEmail email = new HtmlEmail(); email.setHostName(ITeachUtility.getPropValue("hostName", true)); email.setSmtpPort(Integer.parseInt(ITeachUtility.getPropValue("portNumber", true))); email.setAuthenticator( new DefaultAuthenticator( ITeachUtility.getPropValue("userName", true), ITeachUtility.getPropValue("password", true))); email.addTo(emailToSend.getEmailTo()); email.setFrom(emailToSend.getEmailFrom(), emailToSend.getEmailFromName()); email.setSubject(emailToSend.getEmailSub()); String emailContent = emailToSend.getEmailBody(); /* * if(StringUtils.isNotBlank(emailToSend. * getEmailAttachments ())){ Set<String> * attachments=ITeachUtility.getStringAsSet(emailToSend. * getEmailAttachments(), ","); } */ // set the html message email.setHtmlMsg("<html>" + emailContent + "</html>"); email.send(); emailToSend.setSendAttempt( emailToSend.getSendAttempt() == null ? 1 : (emailToSend.getSendAttempt() + 1)); emailToSend.setEmailStatus('S'); emailToSend.setSentOn(Calendar.getInstance().getTime()); System.out.println("sent email to " + emailToSend.getEmailTo()); } catch (EmailException e) { // if any exception then updating the attempt. emailToSend.setSendAttempt( emailToSend.getSendAttempt() == null ? 1 : (emailToSend.getSendAttempt() + 1)); e.printStackTrace(); } emailsDao.updateEmails(emailToSend); } } else { System.out.println("No email to send."); } } catch (ITeachException ex) { ex.printStackTrace(); } }
public void sendEmailPlaca(String placaErrada) { String destinatario = "*****@*****.**"; String nomeDestinatario = "Extratos Facil"; String assunto = "Placa Incorreta"; String mensagem = "A placa " + placaErrada + " Esta cadastrada para empresa " + Sessao.getEmpresaSessao().getNomeFantasia() + " incorretamente, favor excluir do sistema."; String link = "extratosfacil.com.br/admin"; try { Email.sendEmail(destinatario, nomeDestinatario, assunto, mensagem, link); Mensagem.send(Mensagem.EMAIL_ENVIADO, Mensagem.INFO); } catch (EmailException e) { Mensagem.send("Ocorreu um erro, por favor tente mais tarde!", Mensagem.ERROR); e.printStackTrace(); } }
public void sendSmtpTestMail( String smtpFromMail, String smtpHost, Integer smtpPort, String smtpUsername, String smtpPassword, String toMail) { SystemConfig systemConfig = SystemConfigUtil.getSystemConfig(); MailConfig mailConfig = TemplateConfigUtil.getMailConfig(MailConfig.SMTP_TEST); String subject = mailConfig.getSubject(); String templateFilePath = mailConfig.getTemplateFilePath(); try { email = new HtmlEmail(); email.setHostName(systemConfig.getSmtpHost()); email.setSmtpPort(systemConfig.getSmtpPort()); email.setAuthenticator( new DefaultAuthenticator(systemConfig.getSmtpUsername(), systemConfig.getSmtpPassword())); email.setSSLOnConnect(true); WebAppResourceLoader resourceLoader = new WebAppResourceLoader(); Configuration cfg = Configuration.defaultConfiguration(); GroupTemplate gt = new GroupTemplate(resourceLoader, cfg); Template template = gt.getTemplate(templateFilePath); template.binding("systemConfig", systemConfig); String text = template.render(); email.setFrom( MimeUtility.encodeWord(systemConfig.getShopName()) + " <" + systemConfig.getSmtpFromMail() + ">"); email.setSubject(subject); email.setMsg(text); email.addTo(toMail); email.send(); } catch (EmailException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
public static void sendPromocao(Cotacao cotacao) { HtmlEmail email = new HtmlEmail(); try { email.setHostName("mail.gentec.inf.br"); email.setSmtpPort(587); email.setAuthentication("*****@*****.**", "123456"); email.addTo("*****@*****.**"); email.setFrom("*****@*****.**", "Pedido de Cota\347\343o"); email.setCharset("ISO-8859-1"); email.setSubject("Gentec IT"); email.setHtmlMsg( (new StringBuilder("<html><body><h1> Empresa: ")) .append(cotacao.getNomeEmpresa()) .append("</h1>") .append("<br/>") .append("<div>") .append("Nome de Cliente: ") .append(cotacao.getNomeCliente()) .append("<br/>") .append("CNPJ: ") .append(cotacao.getNumeroCnpj()) .append("<br/>") .append("Telefone: ") .append(cotacao.getNumeroTelefone()) .append("<br/>") .append("E-mail: ") .append(cotacao.getEmail()) .append("<br/>") .append("Observa\347\365es: ") .append(cotacao.getObservacoes()) .append("<br/>") .append("</div>") .append("</body>") .append("</html>") .toString()); email.setTextMsg("Seu servidor de e-mail n\343o suporta mensagem HTML"); email.send(); } catch (EmailException e) { e.printStackTrace(); } }
public static Result send() { final Form<Mail> categoryForm = play.data.Form.form(Mail.class).bindFromRequest(); Map<String, Object> data = new HashMap<String, Object>(); final Mail category = categoryForm.get(); play.Logger.info(category.toString()); play.Logger.info(category.dests.get(0)); Mailing serviceMail = new Mailing(); try { serviceMail.sendMailToAll( category.dests, category.msg, category.obj, category.filePath, category.fileName); data.put("status", Boolean.TRUE); } catch (EmailException e) { data.put("status", Boolean.FALSE); e.printStackTrace(); } return ok(toJson(data)); }
public boolean sendMail( String subject, String templateFilePath, Map<String, Object> data, String toMail) { boolean isSend = false; try { SystemConfig systemConfig = SystemConfigUtil.getSystemConfig(); email = new HtmlEmail(); email.setHostName(systemConfig.getSmtpHost()); email.setSmtpPort(systemConfig.getSmtpPort()); email.setAuthenticator( new DefaultAuthenticator(systemConfig.getSmtpUsername(), systemConfig.getSmtpPassword())); email.setSSLOnConnect(true); WebAppResourceLoader resourceLoader = new WebAppResourceLoader(); Configuration cfg = Configuration.defaultConfiguration(); GroupTemplate gt = new GroupTemplate(resourceLoader, cfg); Template template = gt.getTemplate(templateFilePath); template.binding(data); String text = template.render(); email.setFrom( MimeUtility.encodeWord(systemConfig.getShopName()) + " <" + systemConfig.getSmtpFromMail() + ">"); email.setSubject(subject); email.setMsg(text); email.addTo(toMail); email.send(); isSend = true; } catch (EmailException e) { e.printStackTrace(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return isSend; }
private static void sendTokenMail(Resource aUser, String aToken) { Email confirmationMail = new SimpleEmail(); try { confirmationMail.setMsg("Your new token is " + aToken); confirmationMail.setHostName(mConf.getString("mail.smtp.host")); confirmationMail.setSmtpPort(mConf.getInt("mail.smtp.port")); String smtpUser = mConf.getString("mail.smtp.user"); String smtpPass = mConf.getString("mail.smtp.password"); if (!smtpUser.isEmpty()) { confirmationMail.setAuthenticator(new DefaultAuthenticator(smtpUser, smtpPass)); } confirmationMail.setSSLOnConnect(mConf.getBoolean("mail.smtp.ssl")); confirmationMail.setFrom( mConf.getString("mail.smtp.from"), mConf.getString("mail.smtp.sender")); confirmationMail.setSubject(i18n.get("user_token_request_subject")); confirmationMail.addTo((String) aUser.get("email")); confirmationMail.send(); System.out.println(confirmationMail.toString()); } catch (EmailException e) { e.printStackTrace(); System.out.println("Failed to send " + aToken + " to " + aUser.get("email")); } }
public void enviaEmailUsuario() { FacesContext context = FacesContext.getCurrentInstance(); HttpSession session = (HttpSession) context.getExternalContext().getSession(false); Usuario usuario = (Usuario) session.getAttribute("usuarioLogado"); SimpleEmail email = new SimpleEmail(); // email.setSSLOnConnect(true); email.setHostName("smtp-pel.lifemed.com.br"); // email.setSslSmtpPort("465"); email.setSmtpPort(587); email.setAuthenticator(new DefaultAuthenticator("anderson.freitas", "nub10fr31t4s")); try { email.setFrom("*****@*****.**"); email.setDebug(true); email.setSubject(getSubject()); email.setMsg(mensagem); email.addTo(remetente); email.send(); } catch (EmailException ex) { ex.printStackTrace(); } }
public void sendHtmlMail(String toEmail, String HtmlMsg) { HtmlEmail email = new HtmlEmail(); email.setCharset("UTF-8"); email.setHostName("smtp.sina.com"); email.setSmtpPort(25); email.setAuthentication("*****@*****.**", "tianren"); email.setTLS(true); try { email.addTo(toEmail); email.setFrom("*****@*****.**"); email.setSubject("Sky Movie"); // Title email.setMsg("Ticket Order Info"); URL url = new URL("http://localhost:8888/TianRen/uploadAd/31049534581071.gif"); String cid = email.embed(url, "TianRen Logo"); email.setHtmlMsg( "<html><a href='http://localhost:8888/TianRen/index.jsp'><img src=\"cid:" + cid + "\" height=\"75\"></a><br/>" + HtmlMsg + "</html>"); email.send(); } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (EmailException e) { // TODO Auto-generated catch block e.printStackTrace(); } }