@Bean public JavaMailSenderImpl javaMailSender(JHipsterProperties jHipsterProperties) { log.debug("Configuring mail server"); String host = jHipsterProperties.getMail().getHost(); int port = jHipsterProperties.getMail().getPort(); String user = jHipsterProperties.getMail().getUsername(); String password = jHipsterProperties.getMail().getPassword(); String protocol = jHipsterProperties.getMail().getProtocol(); Boolean tls = jHipsterProperties.getMail().isTls(); Boolean auth = jHipsterProperties.getMail().isAuth(); JavaMailSenderImpl sender = new JavaMailSenderImpl(); if (host != null && !host.isEmpty()) { sender.setHost(host); } else { log.warn("Warning! Your SMTP server is not configured. We will try to use one on localhost."); log.debug("Did you configure your SMTP settings in your application.yml?"); sender.setHost(DEFAULT_HOST); } sender.setPort(port); sender.setUsername(user); sender.setPassword(password); Properties sendProperties = new Properties(); sendProperties.setProperty(PROP_SMTP_AUTH, auth.toString()); sendProperties.setProperty(PROP_STARTTLS, tls.toString()); sendProperties.setProperty(PROP_TRANSPORT_PROTO, protocol); sender.setJavaMailProperties(sendProperties); return sender; }
public void postMail( String[] recipients, String subject, String message, String from, String[] cc) throws MessagingException { sender.setUsername((String) properties.getProperty("mail.user")); sender.setPassword((String) properties.getProperty("mail.password")); sender.setHost((String) properties.getProperty("mail.smtp.host")); String portString = (String) properties.getProperty("mail.smtp.port"); sender.setPort(Integer.valueOf(portString)); sender.setProtocol((String) properties.getProperty("mail.transport.protocol")); sender.setJavaMailProperties(properties); MimeMessage mimeMessage = sender.createMimeMessage(); MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, false, "UTF-8"); helper.setFrom(from); helper.setText(message); helper.setSubject(subject); if (cc != null) { helper.setCc(cc); } for (String receiver : recipients) { if (receiver != null) { helper.setTo(receiver); sender.send(mimeMessage); } } }
private static void sendMail(String str, String sendTo, String subject) { if (javaMail == null) { try { javaMail = new JavaMailSenderImpl(); javaMail.setUsername(MAIL_USERNAME); javaMail.setPassword(MAIL_PASSWORD); Properties prop = new Properties(); prop.setProperty("mail.smtp.auth", "true"); prop.setProperty("mail.debug", "true"); prop.setProperty("mail.smtp.socketFactory.port", "465"); prop.setProperty("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); prop.setProperty("mail.smtp.socketFactory.fallback", "false"); prop.setProperty("mail.smtp.port", "465"); prop.setProperty("host", MAIL_SMTP); javaMail.setJavaMailProperties(prop); javaMail.setProtocol("smtp"); } catch (Exception ex) { ex.printStackTrace(); } } // 初始化邮件信息 SimpleMailMessage message = new SimpleMailMessage(); message.setFrom(MAIL_USERNAME + "@" + MAIL_HOST); message.setTo(sendTo); message.setSubject(subject); message.setText(str); javaMail.send(message); }
/** @param args */ public static void main(String[] args) throws Exception { JavaMailSenderImpl senderImpl = new JavaMailSenderImpl(); // 设定mail server senderImpl.setHost("smtp.163.com"); // 建立邮件消息,发送简单邮件和html邮件的区别 MimeMessage mailMessage = senderImpl.createMimeMessage(); MimeMessageHelper messageHelper = new MimeMessageHelper(mailMessage); // 设置收件人,寄件人 messageHelper.setTo("*@qq.com"); messageHelper.setFrom("*@163.com"); messageHelper.setSubject("spring测试HTML邮件!"); // true 表示启动HTML格式的邮件 messageHelper.setText( "<html><head></head><body><h1>hello!!spring html Mail</h1></body></html>", true); senderImpl.setUsername("*"); // 根据自己的情况,设置username senderImpl.setPassword("*"); // 根据自己的情况, 设置password Properties prop = new Properties(); prop.put("mail.smtp.auth", "true"); // 将这个参数设为true,让服务器进行认证,认证用户名和密码是否正确 prop.put("mail.smtp.timeout", "25000"); senderImpl.setJavaMailProperties(prop); // 发送邮件 senderImpl.send(mailMessage); System.out.println("邮件发送成功.."); }
@Bean public JavaMailSenderImpl javaMailSender() { log.debug("Configuring mail server"); String host = propertyResolver.getProperty(PROP_HOST, DEFAULT_PROP_HOST); int port = propertyResolver.getProperty(PROP_PORT, Integer.class, 0); String user = propertyResolver.getProperty(PROP_USER); String password = propertyResolver.getProperty(PROP_PASSWORD); String protocol = propertyResolver.getProperty(PROP_PROTO); Boolean tls = propertyResolver.getProperty(PROP_TLS, Boolean.class, false); Boolean auth = propertyResolver.getProperty(PROP_AUTH, Boolean.class, false); JavaMailSenderImpl sender = new JavaMailSenderImpl(); if (host != null && !host.isEmpty()) { sender.setHost(host); } else { log.warn("Warning! Your SMTP server is not configured. We will try to use one on localhost."); log.debug("Did you configure your SMTP settings in your application.yml?"); sender.setHost(DEFAULT_HOST); } sender.setPort(port); sender.setUsername(user); sender.setPassword(password); Properties sendProperties = new Properties(); sendProperties.setProperty(PROP_SMTP_AUTH, auth.toString()); sendProperties.setProperty(PROP_STARTTLS, tls.toString()); sendProperties.setProperty(PROP_TRANSPORT_PROTO, protocol); sender.setJavaMailProperties(sendProperties); return sender; }
@Bean public MailSender mailSender() { JavaMailSenderImpl ms = new JavaMailSenderImpl(); ms.setJavaMailProperties((Properties) projectSettings().getMailerSettings().get("properties")); ms.setUsername((String) projectSettings().getMailerSettings().get("username")); ms.setPassword((String) projectSettings().getMailerSettings().get("password")); return ms; }
@Bean public JavaMailSender javaMailService() { JavaMailSenderImpl javaMailSender = new JavaMailSenderImpl(); javaMailSender.setHost(env.getRequiredProperty(PROPERTY_HOST)); javaMailSender.setPort(parsePortProperty(env.getRequiredProperty(PROPERTY_PORT))); javaMailSender.setUsername(env.getRequiredProperty(PROPERTY_USERNAME)); javaMailSender.setPassword(env.getRequiredProperty(PROPERTY_PASSWORD)); javaMailSender.setJavaMailProperties(getMailProperties()); javaMailSender.setDefaultEncoding(WebMvcConfiguration.DEFAULT_CHAR_ENCODING); return javaMailSender; }
@Bean public JavaMailSender mailSender() { JavaMailSenderImpl mailSender = new JavaMailSenderImpl(); mailSender.setHost("localhost"); mailSender.setPort(25); Properties javaMailProperties = new Properties(); javaMailProperties.put("mail.transport.protocol", "smtp"); mailSender.setJavaMailProperties(javaMailProperties); return mailSender; }
public static void init() { mailSenderImpl.setHost(PropertyUtils.getProperty("imti.mail.host")); mailSenderImpl.setUsername(PropertyUtils.getProperty("imti.mail.username")); mailSenderImpl.setPassword(PropertyUtils.getProperty("imti.mail.password")); Properties prop = new Properties(); prop.setProperty("mail.smtp.auth", PropertyUtils.getProperty("imti.mail.smtp.auth")); prop.setProperty("mail.smtp.timeout", PropertyUtils.getProperty("imti.mail.smtp.timeout")); mailSenderImpl.setJavaMailProperties(prop); }
private JavaMailSender getRandomBusinessMailSender() { Random random = new Random(); int r = random.nextInt(Constants.MAIL_BUSINESS_SETTINGS.length - 1); JavaMailSenderImpl mailSender = new JavaMailSenderImpl(); mailSender.setHost(Constants.MAIL_BUSINESS_SETTINGS[r][0]); mailSender.setUsername(Constants.MAIL_BUSINESS_SETTINGS[r][2]); mailSender.setPassword(Constants.MAIL_BUSINESS_SETTINGS[r][3]); Properties smtpAuthProperties = new Properties(); smtpAuthProperties.setProperty("mail.smtp.auth", "true"); mailSender.setJavaMailProperties(smtpAuthProperties); return mailSender; }
@PostConstruct public void init() throws IOException { mailSender.setHost(mailHost); mailSender.setPort(mailPort); mailSender.setProtocol(mailProtocol); mailSender.setPassword(mailPwd); mailSender.setUsername(mailUser); Properties props = new Properties(); props.load(mailProps.getInputStream()); mailSender.setJavaMailProperties(props); }
@Bean public JavaMailSenderImpl javaMailSenderImpl() { JavaMailSenderImpl mailSenderImpl = new JavaMailSenderImpl(); mailSenderImpl.setHost(env.getProperty("smtp.host")); mailSenderImpl.setPort(env.getProperty("smtp.port", Integer.class)); mailSenderImpl.setProtocol(env.getProperty("smtp.protocol")); mailSenderImpl.setUsername(env.getProperty("smtp.username")); mailSenderImpl.setPassword(env.getProperty("smtp.password")); Properties javaMailProps = new Properties(); javaMailProps.put("mail.smtp.auth", true); javaMailProps.put("mail.smtp.starttls.enable", true); mailSenderImpl.setJavaMailProperties(javaMailProps); return mailSenderImpl; }
@Bean public MailSender mailSender() { JavaMailSenderImpl javaMailSenderImpl = new JavaMailSenderImpl(); javaMailSenderImpl.setHost("smtp.ig.com.br"); javaMailSenderImpl.setPassword("leonardo941231cordeiro"); javaMailSenderImpl.setPort(587); javaMailSenderImpl.setUsername("*****@*****.**"); Properties mailProperties = new Properties(); mailProperties.put("mail.smtp.auth", true); mailProperties.put("mail.smtp.starttls.enable", true); javaMailSenderImpl.setJavaMailProperties(mailProperties); return javaMailSenderImpl; }
private void applyProperties(JavaMailSenderImpl sender) { sender.setHost(this.properties.getHost()); if (this.properties.getPort() != null) { sender.setPort(this.properties.getPort()); } sender.setUsername(this.properties.getUsername()); sender.setPassword(this.properties.getPassword()); sender.setProtocol(this.properties.getProtocol()); if (this.properties.getDefaultEncoding() != null) { sender.setDefaultEncoding(this.properties.getDefaultEncoding().name()); } if (!this.properties.getProperties().isEmpty()) { sender.setJavaMailProperties(asProperties(this.properties.getProperties())); } }
@Bean public JavaMailSenderImpl javaMailSenderImpl() { JavaMailSenderImpl javaMailSender = new JavaMailSenderImpl(); javaMailSender.setProtocol(env.getRequiredProperty("email.protocol")); javaMailSender.setHost(env.getRequiredProperty("email.host")); javaMailSender.setPort(Integer.parseInt(env.getRequiredProperty("email.port"))); javaMailSender.setUsername(env.getRequiredProperty("email.username")); javaMailSender.setPassword(env.getRequiredProperty("email.password")); Properties properties = new Properties(); properties.putAll(emailProperties()); javaMailSender.setJavaMailProperties(properties); return javaMailSender; }
private void organMailContent() { mailSender.setHost(ConfigManager.getInstance().getString("mail.host")); mailSender.setPort(ConfigManager.getInstance().getInt("mail.port", 25)); mailSender.setUsername(ConfigManager.getInstance().getString("mail.username")); mailSender.setPassword(ConfigManager.getInstance().getString("mail.password")); mailSender.setDefaultEncoding("utf-8"); log.info( "HOST>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>mailSender.getHost()=" + mailSender.getHost() + ",mailSender.getPort()=" + mailSender.getPort()); Properties props = new Properties(); props.setProperty("mail.smtp.auth", "true"); props.setProperty("mail.smtp.timeout", "0"); mailSender.setJavaMailProperties(props); this.setMailSender(mailSender); }
@Bean public MailSender mailSender() { JavaMailSenderImpl javaMailSenderImpl = new JavaMailSenderImpl(); /*javaMailSenderImpl.setHost("smtp.gmail.com");*/ javaMailSenderImpl.setHost("mail.loccoagencia.com.br"); javaMailSenderImpl.setPassword("Locco1234"); /*javaMailSenderImpl.setPort(587);*/ javaMailSenderImpl.setPort(26); javaMailSenderImpl.setUsername("*****@*****.**"); Properties mailProperties = new Properties(); mailProperties.put("mail.smtp.auth", true); mailProperties.put("mail.smtp.starttls.enable", true); javaMailSenderImpl.setJavaMailProperties(mailProperties); return javaMailSenderImpl; }
public void updateJavaMailSender() { javaMailSender = new JavaMailSenderImpl(); javaMailSender.setHost(host); if (smtpAuth) { javaMailSender.setUsername(username); javaMailSender.setPassword(password); } javaMailSender.setDefaultEncoding("UTF-8"); javaMailSender.setJavaMailProperties(this.getProperties()); logger.info("host : {}", host); logger.info("username : {}", username); logger.info("password : {}", password); logger.info("getProperties : {}", getProperties()); }
private void sendEmail(Task.Status exitStatus, File logFile) throws IOException, MessagingException, TemplateException { String smtpServer = RepoxContextUtil.getRepoxManager().getConfiguration().getSmtpServer(); if (smtpServer == null || smtpServer.isEmpty()) { return; } String fromEmail = RepoxContextUtil.getRepoxManager().getConfiguration().getDefaultEmail(); String recipientsEmail = RepoxContextUtil.getRepoxManager().getConfiguration().getAdministratorEmail(); String adminMailPass = RepoxContextUtil.getRepoxManager().getConfiguration().getMailPassword(); String subject = "REPOX Data Source ingesting finished. Exit status: " + exitStatus.toString(); EmailSender emailSender = new EmailSender(); String pathIngestFile = URLDecoder.decode( Thread.currentThread().getContextClassLoader().getResource("ingest.html.ftl").getFile(), "ISO-8859-1"); emailSender.setTemplate( pathIngestFile.substring(0, pathIngestFile.lastIndexOf("/")) + "/ingest"); HashMap map = new HashMap<String, String>(); map.put("exitStatus", exitStatus.toString()); map.put("id", id); JavaMailSenderImpl mail = new JavaMailSenderImpl(); // mail.setUsername(fromEmail); mail.setUsername(recipientsEmail); mail.setPassword(adminMailPass); mail.setPort(25); Properties props = System.getProperties(); props.put("mail.smtp.host", smtpServer); props.put("mail.smtp.starttls.enable", "true"); props.put("mail.smtp.auth", "true"); mail.setJavaMailProperties(props); emailSender.setMailSender(mail); emailSender.sendEmail(recipientsEmail, fromEmail, subject, map, logFile.getAbsolutePath()); }
@Bean public JavaMailSender mailSender() { JavaMailSender mailSender = null; if (isMailSendingConfigured()) { mailSender = new JavaMailSenderImpl(); ((JavaMailSenderImpl) mailSender).setHost(host); ((JavaMailSenderImpl) mailSender).setPort(port); if (!StringUtils.isEmpty(userName)) { ((JavaMailSenderImpl) mailSender).setUsername(userName); } if (!StringUtils.isEmpty(password)) { ((JavaMailSenderImpl) mailSender).setPassword(password); } ((JavaMailSenderImpl) mailSender).setJavaMailProperties(getJavaMailProperties()); } else { mailSender = new DummyEmailSender(); } return mailSender; }
public static void main(String[] args) throws Exception { String smtpServer = RepoxContextUtil.getRepoxManager().getConfiguration().getSmtpServer(); if (smtpServer == null || smtpServer.isEmpty()) { return; } String fromEmail = RepoxContextUtil.getRepoxManager().getConfiguration().getDefaultEmail(); String recipientsEmail = RepoxContextUtil.getRepoxManager().getConfiguration().getAdministratorEmail(); String adminMailPass = RepoxContextUtil.getRepoxManager().getConfiguration().getMailPassword(); String subject = "REPOX Data Source ingesting finished. Exit status: "; EmailSender emailSender = new EmailSender(); String pathIngestFile = URLDecoder.decode( Thread.currentThread().getContextClassLoader().getResource("ingest.html.ftl").getFile(), "ISO-8859-1"); emailSender.setTemplate( pathIngestFile.substring(0, pathIngestFile.lastIndexOf("/")) + "/ingest"); HashMap map = new HashMap<String, String>(); map.put("exitStatus", "OK"); map.put("id", "1111"); JavaMailSenderImpl mail = new JavaMailSenderImpl(); mail.setUsername(recipientsEmail); mail.setPassword(adminMailPass); mail.setPort(25); Properties props = System.getProperties(); props.put("mail.smtp.host", smtpServer); props.put("mail.smtp.starttls.enable", "true"); props.put("mail.smtp.auth", "false"); mail.setJavaMailProperties(props); emailSender.setMailSender(mail); emailSender.sendEmail( recipientsEmail, fromEmail, subject, map, "C:\\Users\\GPedrosa\\Desktop\\indexSec.txt"); }
@Bean public JavaMailSender javaMailSender() { JavaMailSenderImpl javaMailSender = new JavaMailSenderImpl(); javaMailSender.setHost(host); javaMailSender.setPort(Integer.parseInt(port)); javaMailSender.setUsername(username); javaMailSender.setPassword(password); Properties properties = new Properties(); properties.put("mail.smtp.auth", "true"); properties.put("mail.smtp.starttls.enable", "true"); properties.put("mail.smtp.ssl.trust", "smtp.gmail.com"); MailSSLSocketFactory sf = null; try { sf = new MailSSLSocketFactory(); sf.setTrustAllHosts(true); properties.put("mail.smtp.ssl.socketFactory", sf); } catch (GeneralSecurityException e) { e.printStackTrace(); } javaMailSender.setJavaMailProperties(properties); return javaMailSender; }