本文整理匯總了Java中org.springframework.mail.javamail.JavaMailSenderImpl.setDefaultEncoding方法的典型用法代碼示例。如果您正苦於以下問題:Java JavaMailSenderImpl.setDefaultEncoding方法的具體用法?Java JavaMailSenderImpl.setDefaultEncoding怎麽用?Java JavaMailSenderImpl.setDefaultEncoding使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.springframework.mail.javamail.JavaMailSenderImpl
的用法示例。
在下文中一共展示了JavaMailSenderImpl.setDefaultEncoding方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getMailSender
import org.springframework.mail.javamail.JavaMailSenderImpl; //導入方法依賴的package包/類
/**
* Return the {@link JavaMailSender} built from the given node.
*
* @param node
* The node holding the SMTP configuration.
* @return the {@link JavaMailSender} built from the given node.
*/
@CacheResult(cacheName = "plugin-data")
public JavaMailSender getMailSender(@CacheKey final String node) {
final JavaMailSenderImpl mail = new JavaMailSenderImpl();
final Map<String, String> parameters = pvResource.getNodeParameters(node);
mail.setUsername(parameters.get(PARAMETER_USER));
mail.setPassword(parameters.get(PARAMETER_PASSWORD));
mail.setHost(parameters.get(PARAMETER_HOST));
mail.setPort(Optional.ofNullable(parameters.get(PARAMETER_PORT)).map(Integer::valueOf).orElse(125));
mail.setDefaultEncoding("UTF-8");
final Properties properties = new Properties();
properties.put("mail.smtp.auth", Boolean.TRUE);
properties.put("mail.smtp.starttls.enable", Boolean.TRUE);
properties.put("mail.smtp.quitwait", Boolean.FALSE);
properties.put("mail.smtp.socketFactory.fallback", Boolean.FALSE);
mail.setJavaMailProperties(properties);
return mail;
}
示例2: updateJavaMailSender
import org.springframework.mail.javamail.JavaMailSenderImpl; //導入方法依賴的package包/類
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());
}
示例3: mailSender
import org.springframework.mail.javamail.JavaMailSenderImpl; //導入方法依賴的package包/類
@Bean
public JavaMailSender mailSender() {
JavaMailSenderImpl sender = new JavaMailSenderImpl();
sender.setHost(this.properties.getHost());
sender.setPort(this.properties.getPort());
sender.setUsername(this.properties.getUsername());
sender.setPassword(this.properties.getPassword());
sender.setProtocol(this.properties.getProtocol());
sender.setDefaultEncoding(this.properties.getDefaultEncoding().name());
// extra properties
if (!this.properties.getProperties().isEmpty()) {
Properties mailProperties = new Properties();
mailProperties.putAll(this.properties.getProperties());
sender.setJavaMailProperties(mailProperties);
}
return sender;
}
示例4: build
import org.springframework.mail.javamail.JavaMailSenderImpl; //導入方法依賴的package包/類
private static JavaMailSender build(MailConfigSource config) {
JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
mailSender.setDefaultEncoding(StandardCharsets.UTF_8.name());
mailSender.setHost(config.mailServer().getHost());
mailSender.setPort(config.mailServer().getPort());
JProps mailProps = new JProps(mailSender.getJavaMailProperties());
configureTransport(config, mailProps);
config.username().ifPresent(
u -> configureAuthentication(config, u, mailSender, mailProps));
if (MailProtocol.smtps.equals(config.protocol())) {
configureTls(config, mailProps);
}
return mailSender;
}
示例5: emailMessageSenderService
import org.springframework.mail.javamail.JavaMailSenderImpl; //導入方法依賴的package包/類
@Bean
public EmailMessageSenderService emailMessageSenderService() {
JavaMailSenderImpl javaMailSenderImpl = new JavaMailSenderImpl();
javaMailSenderImpl.setDefaultEncoding(mailDefaultEncoding);
javaMailSenderImpl.setHost(mailHost);
javaMailSenderImpl.setPort(mailPort);
javaMailSenderImpl.setUsername(mailUsername);
javaMailSenderImpl.setPassword(mailPassword);
Properties javaMailProperties = new Properties();
javaMailProperties.put("mail.debug", StringUtils.defaultString(mailDebug));
javaMailProperties.put("mail.smtp.starttls.enable", StringUtils.defaultString(startTls));
javaMailProperties.put("mail.smtp.auth", StringUtils.defaultString(mailSmtpAuth));
javaMailProperties.put("mail.smtp.socketFactory.class", StringUtils.defaultString(mailSmtpSocketFactoryClass));
javaMailProperties.put("mail.smtp.socketFactory.fallback", StringUtils.defaultString(mailSmtpSocketFactoryFallback));
javaMailProperties.put("mail.smtp.ssl", StringUtils.defaultString(mailSmtpSsl));
javaMailSenderImpl.setJavaMailProperties(javaMailProperties);
return new EmailMessageSenderService(javaMailSenderImpl);
}
示例6: start
import org.springframework.mail.javamail.JavaMailSenderImpl; //導入方法依賴的package包/類
@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;
}
示例7: javaMailSender
import org.springframework.mail.javamail.JavaMailSenderImpl; //導入方法依賴的package包/類
@Bean
public JavaMailSender javaMailSender() {
JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
mailSender.setHost(config.getSmtpHost());
mailSender.setPort(config.getSmtpPort());
mailSender.setProtocol(config.getSmtpProtocol());
mailSender.setUsername(config.getSmtpUsername());
mailSender.setPassword(config.getSmtpPassword());
mailSender.setDefaultEncoding("UTF-8");
if ("smtps".equalsIgnoreCase(config.getSmtpProtocol())) {
Properties mailProperties = new Properties();
mailProperties.setProperty("mail.smtps.auth", "true");
mailProperties.setProperty("mail.smtp.ssl.enable", "true");
mailProperties.setProperty("mail.transport.protocol", "smtps");
mailProperties.setProperty("mail.debug", "true");
mailProperties.setProperty("mail.mime.charset", "utf8");
mailSender.setJavaMailProperties(mailProperties);
}
return mailSender;
}
示例8: applyProperties
import org.springframework.mail.javamail.JavaMailSenderImpl; //導入方法依賴的package包/類
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()));
}
}
示例9: init
import org.springframework.mail.javamail.JavaMailSenderImpl; //導入方法依賴的package包/類
public void init() {
// 如果加載完畢直接返回
if (inited) {
return;
}
String host = appContext.getConfig().get(SiteConfig.SITE_MAIL_HS);
String username = appContext.getConfig().get(SiteConfig.SITE_MAIL_UN);
String password = appContext.getConfig().get(SiteConfig.SITE_MAIL_PW);
if (StringUtils.isEmpty(host) || StringUtils.isEmpty(username) || StringUtils.isEmpty(password)) {
throw new MtonsException(" 係統配置中的 mail.* 相關配置不完整, 不能正常使用郵件服務!");
}
sender = new JavaMailSenderImpl();
sender.setHost(host);
sender.setDefaultEncoding("UTF-8");
sender.setUsername(username);
sender.setPassword(password);
Properties props = new Properties();
props.setProperty("mail.smtp.auth", "true");
props.setProperty("mail.smtp.timeout", "25000");
sender.setJavaMailProperties(props);
// 標記加載完畢
inited = true;
}
示例10: send
import org.springframework.mail.javamail.JavaMailSenderImpl; //導入方法依賴的package包/類
/**
*
*/
@Override
public boolean send(String from, String to, String subject, String text) {
boolean result = false;
ResourceBundle rb = ResourceBundleUtils.getConfigBundle();
String smtpServer = rb.getString("email.server.smtp");
JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
mailSender.setHost(smtpServer);
mailSender.setDefaultEncoding("UTF-8");
SimpleMailMessage msg = new SimpleMailMessage();
msg.setFrom(from);
msg.setTo(to);
msg.setSubject(subject);
msg.setText(text);
try {
mailSender.send(msg);
result = true;
log.info("Odeslan email. From: " + from + ", to: " + to + ", subject: " + subject + ".");
} catch (MailException exc) {
log.error(exc.getMessage(), exc);
result = false;
log.info("NEodeslan email. From: " + from + ", to: " + to + ", subject: " + subject + ".");
}
return result;
}
示例11: initMailSender
import org.springframework.mail.javamail.JavaMailSenderImpl; //導入方法依賴的package包/類
private void initMailSender(){
mailSender = new JavaMailSenderImpl();
mailSender.setHost(properties.getProperty("server"));
mailSender.setPort(Integer.parseInt(properties.getProperty("port")));
mailSender.setDefaultEncoding("UTF-8");
}