Java Code Examples for org.springframework.mail.javamail.JavaMailSenderImpl#setPassword()
The following examples show how to use
org.springframework.mail.javamail.JavaMailSenderImpl#setPassword() .
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: JavaMailSenderFactory.java From molgenis with GNU Lesser General Public License v3.0 | 6 votes |
@Override public JavaMailSenderImpl createMailSender(MailSettings mailSettings) { LOG.trace("createMailSender"); JavaMailSenderImpl mailSender = new JavaMailSenderImpl(); mailSender.setHost(mailSettings.getHost()); mailSender.setPort(mailSettings.getPort()); mailSender.setProtocol(mailSettings.getProtocol()); mailSender.setUsername(mailSettings.getUsername()); mailSender.setPassword(mailSettings.getPassword()); mailSender.setDefaultEncoding(mailSettings.getDefaultEncoding().name()); Properties properties = new Properties(defaultProperties); defaultProperties.setProperty(MAIL_SMTP_STARTTLS_ENABLE, mailSettings.isStartTlsEnabled()); defaultProperties.setProperty(MAIL_SMTP_QUITWAIT, mailSettings.isQuitWait()); defaultProperties.setProperty(MAIL_SMTP_AUTH, mailSettings.isAuthenticationRequired()); defaultProperties.setProperty(MAIL_SMTP_FROM_ADDRESS, mailSettings.getFromAddress()); properties.putAll(mailSettings.getJavaMailProperties()); LOG.debug("Mail properties: {}; defaults: {}", properties, defaultProperties); mailSender.setJavaMailProperties(properties); return mailSender; }
Example 2
Source File: EmailServiceImpl.java From cia with Apache License 2.0 | 6 votes |
/** * Gets the mail sender. * * @return the mail sender */ private JavaMailSender getMailSender() { final JavaMailSenderImpl javaMailSender = new JavaMailSenderImpl(); final ApplicationConfiguration smtpHostConfig = applicationConfigurationService.checkValueOrLoadDefault(EMAIL_CONFIGURATION_SMTP_HOST, SMTP_HOST, ConfigurationGroup.EXTERNAL_SERVICES, EmailServiceImpl.class.getSimpleName(), SMTP_HOST, RESPONSIBLE_FOR_SENDING_EMAIL, APPLICATION_EMAIL_SMTP_HOST, "localhost"); final ApplicationConfiguration smtpPort = applicationConfigurationService.checkValueOrLoadDefault(EMAIL_CONFIGURATION_SMTP_PORT, SMTP_PORT, ConfigurationGroup.EXTERNAL_SERVICES, EmailServiceImpl.class.getSimpleName(), SMTP_PORT, RESPONSIBLE_FOR_SENDING_EMAIL, APPLICATION_EMAIL_SMTP_PORT, DEFAULT_SMTP_PORT); final ApplicationConfiguration smtpUsername = applicationConfigurationService.checkValueOrLoadDefault(EMAIL_CONFIGURATION_SMTP_USERNAME, SMTP_USERNAME, ConfigurationGroup.EXTERNAL_SERVICES, EmailServiceImpl.class.getSimpleName(), SMTP_USERNAME, RESPONSIBLE_FOR_SENDING_EMAIL, APPLICATION_EMAIL_SMTP_USERNAME, "username"); final ApplicationConfiguration smtpPassword = applicationConfigurationService.checkValueOrLoadDefault(EMAIL_CONFIGURATION_SMTP_SECRET, SMTP_SECRET, ConfigurationGroup.EXTERNAL_SERVICES, EmailServiceImpl.class.getSimpleName(), SMTP_SECRET, RESPONSIBLE_FOR_SENDING_EMAIL, APPLICATION_EMAIL_SMTP_SECRET, "password"); final ApplicationConfiguration smtpAuth = applicationConfigurationService.checkValueOrLoadDefault(EMAIL_CONFIGURATION_SMTP_AUTH, SMTP_AUTH, ConfigurationGroup.EXTERNAL_SERVICES, EmailServiceImpl.class.getSimpleName(), SMTP_AUTH, RESPONSIBLE_FOR_SENDING_EMAIL, APPLICATION_EMAIL_SMTP_AUTH, "true"); final ApplicationConfiguration smtpStartTlsEnable = applicationConfigurationService.checkValueOrLoadDefault(EMAIL_CONFIGURATION_SMTP_STARTTLS_ENABLE, SMTP_STARTTLS_ENABLE, ConfigurationGroup.EXTERNAL_SERVICES, EmailServiceImpl.class.getSimpleName(), SMTP_STARTTLS_ENABLE, RESPONSIBLE_FOR_SENDING_EMAIL, APPLICATION_EMAIL_SMTP_STARTTLS_ENABLE, "true"); javaMailSender.setHost(smtpHostConfig.getPropertyValue()); javaMailSender.setPort(getSmtpPort(smtpPort)); javaMailSender.setUsername(smtpUsername.getPropertyValue()); javaMailSender.setPassword(smtpPassword.getPropertyValue()); final Properties javaMailProperties = new Properties(); javaMailProperties.setProperty(MAIL_SMTP_AUTH, smtpAuth.getPropertyValue()); javaMailProperties.setProperty(MAIL_SMTP_STARTTLS_ENABLE, smtpStartTlsEnable.getPropertyValue()); javaMailSender.setJavaMailProperties(javaMailProperties); return javaMailSender; }
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: 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 5
Source File: MailUtil.java From boubei-tss with Apache License 2.0 | 6 votes |
public static JavaMailSenderImpl getMailSender(String _ms) { // 读取邮件服务器配置 String[] configs = getEmailInfos(_ms); int port = EasyUtils.obj2Int( ParamConfig.getAttribute(PX.MAIL_SERVER_PORT +_ms , "25") ); JavaMailSenderImpl mailSender = new JavaMailSenderImpl(); mailSender.setHost( configs[0] ); mailSender.setPort( port ); if( configs.length == 5 ) { mailSender.setUsername( configs[3] ); mailSender.setPassword( InfoEncoder.simpleDecode(configs[4], 12) ); mailSender.getJavaMailProperties().put("mail.smtp.auth", true); } return mailSender; }
Example 6
Source File: EmailConfiguration.java From activiti6-boot2 with Apache License 2.0 | 6 votes |
@Bean public JavaMailSender javaMailSender() { JavaMailSenderImpl sender = new JavaMailSenderImpl(); boolean isEmailEnabled = env.getProperty("email.enabled", Boolean.class, false); if (isEmailEnabled) { sender.setHost(env.getRequiredProperty("email.host")); sender.setPort(env.getRequiredProperty("email.port", Integer.class)); } Boolean useCredentials = env.getProperty("email.useCredentials", Boolean.class); if (Boolean.TRUE.equals(useCredentials)) { sender.setUsername(env.getProperty("email.username")); sender.setPassword(env.getProperty("email.password")); } Boolean emailTLS = env.getProperty("email.tls", Boolean.class); if (emailTLS != null) { sender.getJavaMailProperties().setProperty("mail.smtp.starttls.enable", emailTLS.toString()); } return sender; }
Example 7
Source File: MailConfig.java From restfiddle with Apache License 2.0 | 6 votes |
@Bean public JavaMailSender javaMailSender() { JavaMailSenderImpl mailSender = new JavaMailSenderImpl(); Properties mailProperties = new Properties(); mailSender.setProtocol(env.getProperty("mail.protocol")); mailSender.setHost(env.getProperty("mail.host")); mailSender.setPort(Integer.parseInt(env.getProperty("mail.port"))); mailSender.setUsername(env.getProperty("mail.username")); mailSender.setPassword(env.getProperty("mail.password")); mailProperties.put("mail.smtp.auth", env.getProperty("mail.smtp.auth")); mailProperties.put("mail.smtp.starttls.enable", env.getProperty("mail.smtp.starttls.enable")); mailProperties.put("mail.smtp.debug", env.getProperty("mail.smtp.debug")); mailProperties.put("mail.smtp.socketFactory.port", "465"); mailProperties.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); mailProperties.put("mail.smtps.ssl.trust", env.getProperty("mail.smtps.ssl.trust")); mailProperties.put("mail.smtps.ssl.checkserveridentity", env.getProperty("mail.smtps.ssl.checkserveridentity")); mailSender.setJavaMailProperties(mailProperties); return mailSender; }
Example 8
Source File: MailSender.java From cola-cloud with MIT License | 5 votes |
public static void main(String[] args) { JavaMailSenderImpl js=new JavaMailSenderImpl(); js.setHost("smtp.qq.com"); js.setUsername("[email protected]"); js.setPassword("mygdzwlcjlxpbghc"); 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); MimeMessage message = null; try { message = js.createMimeMessage(); MimeMessageHelper helper = new MimeMessageHelper(message, true); // helper.setFrom(new InternetAddress(this.getFrom(), MimeUtility.encodeText(this.name,"UTF-8", "B"))); helper.setFrom("[email protected]"); helper.setTo("[email protected]"); helper.setSubject("测试"); helper.setText("测试内容"); //addAttachmentStatic(helper,params); } catch (Exception e) { e.printStackTrace(); } js.send(message); }
Example 9
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 10
Source File: MailConfig.java From phoenix.webui.framework with Apache License 2.0 | 5 votes |
@Bean(autowire = Autowire.BY_TYPE) public MailSender mailBean() { JavaMailSenderImpl mailSender = new JavaMailSenderImpl(); mailSender.setHost(mailHost); mailSender.setUsername(mailUserName); mailSender.setPassword(mailPassword); setUpMailPro(mailSender); return mailSender; }
Example 11
Source File: MailSenderCreator.java From spring-cloud-connectors with Apache License 2.0 | 5 votes |
@Override public JavaMailSender create(SmtpServiceInfo serviceInfo, ServiceConnectorConfig config) { JavaMailSenderImpl mailSender = new JavaMailSenderImpl(); mailSender.setHost(serviceInfo.getHost()); mailSender.setPort(serviceInfo.getPort()); mailSender.setUsername(serviceInfo.getUserName()); mailSender.setPassword(serviceInfo.getPassword()); return mailSender; }
Example 12
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 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 angularjs-springboot-bookstore with MIT License | 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 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 16
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 17
Source File: EmailAlert.java From redis-manager with Apache License 2.0 | 4 votes |
private JavaMailSender getJavaMailSender(AlertChannel alertChannel) { JavaMailSenderImpl mailSender = new JavaMailSenderImpl(); String smtpHost = alertChannel.getSmtpHost(); String[] hostAndPort = smtpHost.split(SignUtil.COLON); mailSender.setHost(hostAndPort[0]); if (hostAndPort.length > 1) { mailSender.setPort(Integer.parseInt(hostAndPort[0])); } mailSender.setUsername(alertChannel.getEmailUserName()); mailSender.setPassword(alertChannel.getEmailPassword()); Properties props = mailSender.getJavaMailProperties(); props.put("mail.transport.protocol", "smtp"); return mailSender; }
Example 18
Source File: NeteaseMailUtil.java From charging_pile_cloud with MIT License | 4 votes |
/** * 发送网页图片邮箱 * * @param to * @param title * @param text * @return */ private static boolean sendMailHtml(String to, String title, String text) { JavaMailSenderImpl senderImpl = new JavaMailSenderImpl(); //SimpleMailMessage mailMessage = new SimpleMailMessage(); //建立邮件消息,发送简单邮件和html邮件的区别 MimeMessage mailMessage = senderImpl.createMimeMessage(); Properties prop = new Properties(); System.out.println("sendMail...util..."); try { //注意这里的boolean,等于真的时候才能嵌套图片,在构建MimeMessageHelper时候,所给定的值是true表示启用, //multipart模式 MimeMessageHelper messageHelper = new MimeMessageHelper(mailMessage, true, "utf-8"); 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); senderImpl.setUsername(emailUsername); senderImpl.setPassword(authorizationPwd); //设定mail server senderImpl.setHost(emailHost); //senderImpl.setPort(587); // 设置收件人,寄件人 用数组发送多个邮件 // String[] array = new String[] {"[email protected]","[email protected]"}; // mailMessage.setTo(array); messageHelper.setTo(to); messageHelper.setFrom(sendEmail); messageHelper.setSubject(title); messageHelper.setText(messageHtml(text), true); 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; } }
Example 19
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; } }
Example 20
Source File: MailConfig.java From QuizZz with MIT License | 3 votes |
@Bean public JavaMailSender javaMailSender() { JavaMailSenderImpl mailSender = new JavaMailSenderImpl(); Properties mailProperties = new Properties(); mailProperties.put("mail.smtp.auth", auth); mailProperties.put("mail.smtp.starttls.enable", starttls); mailSender.setJavaMailProperties(mailProperties); mailSender.setHost(host); mailSender.setPort(port); mailSender.setProtocol(protocol); mailSender.setUsername(username); mailSender.setPassword(password); return mailSender; }