Java Code Examples for org.springframework.mail.javamail.JavaMailSenderImpl#setJavaMailProperties()
The following examples show how to use
org.springframework.mail.javamail.JavaMailSenderImpl#setJavaMailProperties() .
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: MailAutoConfiguration.java From cola-cloud with MIT License | 7 votes |
@Bean @ConditionalOnBean(JavaMailSender.class) public MailSender adiMailSender1(JavaMailSender sender, FreeMarkerConfigurer freeMarkerConfigurer) { if (mailProperties.getPreferIPv4Stack()) { System.setProperty("java.net.preferIPv4Stack", "true"); } JavaMailSenderImpl js= (JavaMailSenderImpl) sender; Properties props = new Properties(); props.put("mail.smtp.auth", true); props.put("mail.smtp.ssl.enable", true); props.put("mail.smtp.socketFactory.class","javax.net.ssl.SSLSocketFactory"); props.put("mail.smtp.timeout", 25000); js.setJavaMailProperties(props); MailSender mailSender = new MailSender(); mailSender.setJavaMailSender(js); mailSender.setFreeMarkerConfigurer(freeMarkerConfigurer); mailSender.setName(mailProperties.getName()); mailSender.setFrom(mailProperties.getFrom()); return mailSender; }
Example 2
Source File: SmtpMailer.java From alf.io with GNU General Public License v3.0 | 6 votes |
private static JavaMailSender toMailSender(Map<ConfigurationKeys, ConfigurationManager.MaybeConfiguration> conf) { JavaMailSenderImpl r = new CustomJavaMailSenderImpl(); r.setDefaultEncoding("UTF-8"); r.setHost(conf.get(SMTP_HOST).getRequiredValue()); r.setPort(Integer.parseInt(conf.get(SMTP_PORT).getRequiredValue())); r.setProtocol(conf.get(SMTP_PROTOCOL).getRequiredValue()); r.setUsername(conf.get(SMTP_USERNAME).getValueOrDefault(null)); r.setPassword(conf.get(SMTP_PASSWORD).getValueOrDefault(null)); String properties = conf.get(SMTP_PROPERTIES).getValueOrDefault(null); if (properties != null) { try { Properties prop = PropertiesLoaderUtils.loadProperties(new EncodedResource(new ByteArrayResource( properties.getBytes(StandardCharsets.UTF_8)), "UTF-8")); r.setJavaMailProperties(prop); } catch (IOException e) { log.warn("error while setting the mail sender properties", e); } } return r; }
Example 3
Source File: MailAlarmService.java From yugong with GNU General Public License v2.0 | 6 votes |
@Override public void start() { super.start(); JavaMailSenderImpl mailSender = new JavaMailSenderImpl(); mailSender.setUsername(emailUsername); mailSender.setPassword(emailPassword); mailSender.setHost(emailHost); mailSender.setDefaultEncoding("UTF-8"); Properties pros = new Properties(); pros.put("mail.smtp.auth", true); pros.put("mail.smtp.timeout", 25000); pros.put("mail.smtp.port", stmpPort); pros.put("mail.smtp.socketFactory.port", stmpPort); pros.put("mail.smtp.socketFactory.fallback", false); if (sslSupport) { pros.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); } mailSender.setJavaMailProperties(pros); this.mailSender = mailSender; }
Example 4
Source File: MailManager.java From BlogSystem with Apache License 2.0 | 6 votes |
public MailManager() { mailSender = new JavaMailSenderImpl(); //指定用来发送Email的邮件服务器主机名 mailSender.setHost("smtp.qq.com"); //默认端口,标准的SMTP端口 mailSender.setPort(465); Properties properties = new Properties(); properties.setProperty("mail.host", "smtp.qq.com"); properties.setProperty("mail.transport.protocol", "smtp"); properties.setProperty("mail.smtp.auth", "true"); properties.setProperty("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); properties.setProperty("mail.smtp.port", "465"); properties.setProperty("mail.smtp.socketFactory.port", "465"); mailSender.setJavaMailProperties(properties); }
Example 5
Source File: MailService.java From cloud-portal with MIT License | 6 votes |
@PostConstruct public void init() { // create new java mail sender mailSender = new JavaMailSenderImpl(); // set mail sender configuration mailSender.setHost(host); mailSender.setPort(port); mailSender.setProtocol(protocol); mailSender.setUsername(username); mailSender.setPassword(password); // set mail encoding mailSender.setDefaultEncoding(StandardCharsets.UTF_8.name()); // create java mail properties Properties mailProperties = new Properties(); mailProperties.put("mail.smtp.auth", auth); mailProperties.put("mail.smtp.starttls.enable", starttls); mailProperties.put("mail.smtp.timeout", timeout); mailProperties.put("mail.smtp.connectiontimeout", timeout); // set java mail properties mailSender.setJavaMailProperties(mailProperties); }
Example 6
Source File: MailServerInfo.java From lemon with Apache License 2.0 | 6 votes |
public void updateJavaMailSender() { javaMailSender = new JavaMailSenderImpl(); javaMailSender.setHost(host); javaMailSender.setPort(port); if (smtpAuth) { javaMailSender.setUsername(username); javaMailSender.setPassword(password); } javaMailSender.setDefaultEncoding("UTF-8"); javaMailSender.setJavaMailProperties(this.getProperties()); logger.debug("host : {}", host); logger.debug("port : {}", port); logger.debug("username : {}", username); logger.debug("password : {}", password); logger.debug("getProperties : {}", getProperties()); }
Example 7
Source File: EmailExchanger.java From open-cloud with MIT License | 6 votes |
private JavaMailSenderImpl buildMailSender(EmailConfig config) { if (config == null) { throw new RuntimeException("缺少默认邮件服务器配置"); } JavaMailSenderImpl sender = new JavaMailSenderImpl(); sender.setHost(config.getSmtpHost()); sender.setUsername(config.getSmtpUsername()); sender.setPassword(config.getSmtpPassword()); sender.setDefaultEncoding("UTF-8"); Properties props = new Properties(); props.setProperty("mail.smtp.auth", "true"); props.setProperty("mail.smtp.starttls.enable", "true"); props.setProperty("mail.smtp.starttls.required", "true"); sender.setJavaMailProperties(props); return sender; }
Example 8
Source File: SendEmailService.java From sitemonitoring-production with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void applyFixes(JavaMailSenderImpl javaMailSender) throws GeneralSecurityException { Properties props = new Properties(); fixAuth(javaMailSender, props); fixSSL(props); if (props.size() > 0) { javaMailSender.setJavaMailProperties(props); } }
Example 9
Source File: MailSenderFactory.java From halo with GNU General Public License v3.0 | 5 votes |
private void setProperties(@NonNull JavaMailSenderImpl mailSender, @NonNull MailProperties mailProperties) { mailSender.setHost(mailProperties.getHost()); mailSender.setPort(mailProperties.getPort()); mailSender.setUsername(mailProperties.getUsername()); mailSender.setPassword(mailProperties.getPassword()); mailSender.setProtocol(mailProperties.getProtocol()); mailSender.setDefaultEncoding(mailProperties.getDefaultEncoding().name()); if (!CollectionUtils.isEmpty(mailProperties.getProperties())) { Properties properties = new Properties(); properties.putAll(mailProperties.getProperties()); mailSender.setJavaMailProperties(properties); } }
Example 10
Source File: EmailConfiguration.java From gravitee-management-rest-api with Apache License 2.0 | 5 votes |
@Bean public JavaMailSenderImpl mailSender() { final JavaMailSenderImpl javaMailSender = new JavaMailSenderImpl(); javaMailSender.setHost(host); if (StringUtils.isNumeric(port)) { javaMailSender.setPort(Integer.valueOf(this.port)); } javaMailSender.setUsername(username); javaMailSender.setPassword(password); javaMailSender.setProtocol(protocol); javaMailSender.setJavaMailProperties(loadProperties()); return javaMailSender; }
Example 11
Source File: SendEmailService.java From sitemonitoring-production with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void applyFixes(JavaMailSenderImpl javaMailSender) throws GeneralSecurityException { Properties props = new Properties(); fixAuth(javaMailSender, props); fixSSL(props); if (props.size() > 0) { javaMailSender.setJavaMailProperties(props); } }
Example 12
Source File: MailPlugin.java From iotplatform with Apache License 2.0 | 5 votes |
private void initMailSender(MailPluginConfiguration configuration) { JavaMailSenderImpl mail = new JavaMailSenderImpl(); mail.setHost(configuration.getHost()); mail.setPort(configuration.getPort()); mail.setUsername(configuration.getUsername()); mail.setPassword(configuration.getPassword()); if (configuration.getOtherProperties() != null) { Properties mailProperties = new Properties(); configuration.getOtherProperties().forEach(p -> mailProperties.put(p.getKey(), p.getValue())); mail.setJavaMailProperties(mailProperties); } mailSender = mail; }
Example 13
Source File: DefaultMailService.java From iotplatform with Apache License 2.0 | 5 votes |
private JavaMailSenderImpl createMailSender(JsonNode jsonConfig) { JavaMailSenderImpl mailSender = new JavaMailSenderImpl(); mailSender.setHost(jsonConfig.get("smtpHost").asText()); mailSender.setPort(parsePort(jsonConfig.get("smtpPort").asText())); mailSender.setUsername(jsonConfig.get("username").asText()); mailSender.setPassword(jsonConfig.get("password").asText()); mailSender.setJavaMailProperties(createJavaMailProperties(jsonConfig)); return mailSender; }
Example 14
Source File: MailConfiguration.java From ServiceCutter with Apache License 2.0 | 5 votes |
@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; }
Example 15
Source File: EmailConfiguration.java From graviteeio-access-management with Apache License 2.0 | 5 votes |
@Bean public JavaMailSender mailSender() { final JavaMailSenderImpl javaMailSender = new JavaMailSenderImpl(); javaMailSender.setHost(host); try { javaMailSender.setPort(Integer.valueOf(this.port)); } catch (Exception e) { } javaMailSender.setUsername(username); javaMailSender.setPassword(password); javaMailSender.setProtocol(protocol); javaMailSender.setJavaMailProperties(loadProperties()); return javaMailSender; }
Example 16
Source File: EmailConfiguration.java From graviteeio-access-management with Apache License 2.0 | 5 votes |
@Bean public JavaMailSender mailSender() { final JavaMailSenderImpl javaMailSender = new JavaMailSenderImpl(); javaMailSender.setHost(host); try { javaMailSender.setPort(Integer.valueOf(this.port)); } catch (Exception e) { } javaMailSender.setUsername(username); javaMailSender.setPassword(password); javaMailSender.setProtocol(protocol); javaMailSender.setJavaMailProperties(loadProperties()); return javaMailSender; }
Example 17
Source File: CoreMailConfiguration.java From abixen-platform with GNU Lesser General Public License v2.1 | 5 votes |
@Bean public JavaMailSender javaMailService() { log.debug("javaMailService()"); JavaMailSenderImpl javaMailSender = new JavaMailSenderImpl(); javaMailSender.setHost(platformMailConfigurationProperties.getHost()); javaMailSender.setPort(platformMailConfigurationProperties.getPort()); javaMailSender.setUsername(platformMailConfigurationProperties.getUser().getUsername()); javaMailSender.setPassword(platformMailConfigurationProperties.getUser().getPassword()); javaMailSender.setJavaMailProperties(getMailProperties()); return javaMailSender; }
Example 18
Source File: JavaMailSenderBuilderImpl.java From yes-cart with Apache License 2.0 | 5 votes |
JavaMailSender configureMailSender(final String shopCode, final String host, final String port, final String user, final String pass, final String smtpauth, final String starttls) { if (host == null || port == null) { LOG.error(Markers.alert(), "Custom mail sender is missconfigured for {}, host or port missing", shopCode); return null; } if (Boolean.valueOf(smtpauth) && user == null || pass == null) { LOG.error(Markers.alert(), "Custom mail sender is missconfigured for {}, user or pass missing for SMTP-AUTH", shopCode); return null; } JavaMailSenderImpl shopMailSender = new JavaMailSenderImpl(); shopMailSender.setHost(host); try { shopMailSender.setPort(Integer.valueOf(port)); } catch (NumberFormatException nfe) { LOG.error(Markers.alert(), "Custom mail sender is missconfigured for {}, invalid port", shopCode); return null; } shopMailSender.setUsername(user); shopMailSender.setPassword(pass); final Properties properties = new Properties(); properties.put("mail.smtp.auth", smtpauth); properties.put("mail.smtp.starttls.enable", starttls); properties.put("mail.smtp.connectiontimeout", this.connectionTimeout); properties.put("mail.smtp.timeout", this.connectionTimeout); shopMailSender.setJavaMailProperties(properties); LOG.info("Detected custom mail sender {}:{} for shop {}", host, port, shopCode); return shopMailSender; }
Example 19
Source File: MailServiceImpl.java From nimrod with MIT License | 4 votes |
@Override public void initialize() { String host = (String) dictionaryService.get("MAIL", "HOST"); String protocol = (String) dictionaryService.get("MAIL", "PROTOCOL"); String port = (String) dictionaryService.get("MAIL", "PORT"); String username = (String) dictionaryService.get("MAIL", "USERNAME"); String password = (String) dictionaryService.get("MAIL", "PASSWORD"); String defaultEncoding = (String) dictionaryService.get("MAIL", "DEFAULT_ENCODING"); String smtpAuth = (String) dictionaryService.get("MAIL", "SMTP_AUTH"); String startTlsEnable = (String) dictionaryService.get("MAIL", "STARTTLS_ENABLE"); String startTlsRequired = (String) dictionaryService.get("MAIL", "STARTTLS_REQUIRED"); javaMailSender = new JavaMailSenderImpl(); if (host != null) { javaMailSender.setHost(host); } if (protocol != null) { javaMailSender.setProtocol(protocol); } if (port != null) { javaMailSender.setPort(Integer.parseInt(port)); } if (username != null) { javaMailSender.setUsername(username); } if (password != null) { javaMailSender.setPassword(password); } if (password != null) { javaMailSender.setPassword(password); } if (defaultEncoding != null) { javaMailSender.setDefaultEncoding(defaultEncoding); } Properties properties = new Properties(); if (smtpAuth != null) { properties.setProperty("mail.smtp.auth", smtpAuth); } if (startTlsEnable != null) { properties.setProperty("mail.starttls.enable", startTlsEnable); } if (startTlsRequired != null) { properties.setProperty("mail.starttls.required", startTlsRequired); } javaMailSender.setJavaMailProperties(properties); }
Example 20
Source File: NeteaseMailUtil.java From charging_pile_cloud with MIT License | 4 votes |
/** * @param to 目的邮箱 * @param title 标题 * @param text 内容 * @return */ private static boolean sendMailText(String to, String title, String text) { JavaMailSenderImpl senderImpl = new JavaMailSenderImpl(); SimpleMailMessage mailMessage = new SimpleMailMessage(); Properties prop = new Properties(); System.out.println("sendMail...util..."); try { //设定mail server senderImpl.setHost(emailHost); //senderImpl.setPort(587); // 设置收件人,寄件人 用数组发送多个邮件 // String[] array = new String[] {"[email protected]","[email protected]"}; // mailMessage.setTo(array); mailMessage.setTo(to); mailMessage.setFrom(sendEmail); mailMessage.setSubject(title); mailMessage.setText(text); senderImpl.setUsername(emailUsername); senderImpl.setPassword(authorizationPwd); 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("mail.smtp.socketFactory.port", "465"); // 设置传输协议 prop.setProperty("mail.transport.protocol", "smtp"); prop.put("mail.smtp.auth", isAuth); prop.put("mail.smtp.timeout", linkTimeout); senderImpl.setJavaMailProperties(prop); System.out.println("发送信息:" + text); MimeMessage msg = senderImpl.createMimeMessage(); msg.addRecipients(MimeMessage.RecipientType.CC, InternetAddress.parse(sendEmail)); //发送邮件 senderImpl.send(mailMessage); System.out.println("发送邮件成功"); return true; } catch (Exception e) { e.printStackTrace(); System.out.println("发送邮件失败"); return false; } }