本文整理汇总了Java中org.springframework.mail.javamail.JavaMailSender类的典型用法代码示例。如果您正苦于以下问题:Java JavaMailSender类的具体用法?Java JavaMailSender怎么用?Java JavaMailSender使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JavaMailSender类属于org.springframework.mail.javamail包,在下文中一共展示了JavaMailSender类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: javaMailService
import org.springframework.mail.javamail.JavaMailSender; //导入依赖的package包/类
@Bean
public JavaMailSender javaMailService() {
JavaMailSenderImpl javaMailSender = new JavaMailSenderImpl();
if (this.auth) {
javaMailSender.setUsername(this.username);
javaMailSender.setPassword(this.password);
}
Properties properties = new Properties();
properties.setProperty("mail.transport.protocol", this.protocol);
properties.setProperty("mail.smtp.auth", Boolean.toString(this.auth));
properties.setProperty("mail.smtp.starttls.enable", Boolean.toString(this.starttls));
properties.setProperty("mail.debug", Boolean.toString(this.debug));
properties.setProperty("mail.smtp.host", this.host);
properties.setProperty("mail.smtp.port", Integer.toString(this.port));
properties.setProperty("mail.smtp.ssl.trust", this.trust);
javaMailSender.setJavaMailProperties(properties);
return javaMailSender;
}
示例2: getMailSender
import org.springframework.mail.javamail.JavaMailSender; //导入依赖的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;
}
示例3: sendPasswordResetMail
import org.springframework.mail.javamail.JavaMailSender; //导入依赖的package包/类
@Async
public void sendPasswordResetMail(String target,String reseturl,JavaMailSender javaMailSender) throws InterruptedException {
try {
MimeMessage mimeMsg = javaMailSender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(mimeMsg, false, "utf-8");
String content = (String) PropertyPlaceholder.getProperty("mail.template");
content = content.replace("{reseturl}", reseturl);
helper.setText(content, true);
helper.setTo(new String[]{target});
String title = (String) PropertyPlaceholder.getProperty("mail.title");
helper.setSubject(title);
String authormail = (String) PropertyPlaceholder.getProperty("mail.sendfrom");
String authorname = (String) PropertyPlaceholder.getProperty("mail.sendname");
helper.setFrom(authormail,authorname);
javaMailSender.send(mimeMsg);
log.info("Password Reset Mail has been send to "+target);
} catch(Exception e) {
e.printStackTrace();
}
}
示例4: mailSender
import org.springframework.mail.javamail.JavaMailSender; //导入依赖的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;
}
示例5: build
import org.springframework.mail.javamail.JavaMailSender; //导入依赖的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;
}
示例6: javaMailSender
import org.springframework.mail.javamail.JavaMailSender; //导入依赖的package包/类
@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;
}
示例7: createHtmlEmail
import org.springframework.mail.javamail.JavaMailSender; //导入依赖的package包/类
private static void createHtmlEmail(int i){
try {
JavaMailSender sender = getEmailSender();
MimeMessage message = sender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(message);
helper.setTo("[email protected]");
helper.setFrom("[email protected]");
helper.setSubject("Test-Mail " + i);
helper.setText("<html><head></head><body>This is the test mail number " + i + "</body>", true);
sender.send(message);
} catch (MessagingException e){
throw new RuntimeException("Failed to create mail", e);
}
}
示例8: javaMailSender
import org.springframework.mail.javamail.JavaMailSender; //导入依赖的package包/类
@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);
mailProperties.put("mail.smtp.starttls.required", startlls_required);
mailProperties.put("mail.smtp.socketFactory.port", socketPort);
mailProperties.put("mail.smtp.debug", debug);
mailProperties.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
mailProperties.put("mail.smtp.socketFactory.fallback", fallback);
mailSender.setJavaMailProperties(mailProperties);
mailSender.setHost(host);
mailSender.setPort(port);
mailSender.setProtocol(protocol);
mailSender.setUsername(username);
mailSender.setPassword(password);
return mailSender;
}
示例9: mailTo
import org.springframework.mail.javamail.JavaMailSender; //导入依赖的package包/类
@Async
public void mailTo(String[] targetuser,String title,String content,JavaMailSender javaMailSender) {//邮件功能
try {
MimeMessage mimeMsg = javaMailSender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(mimeMsg, false, "utf-8");
helper.setText(content, true);
helper.setBcc(targetuser);
helper.setSubject(title);
String authormail = (String) PropertyPlaceholder.getProperty("mail.sendfrom");
String authorname = (String) PropertyPlaceholder.getProperty("mail.sendname");
helper.setFrom(authormail,authorname);
javaMailSender.send(mimeMsg);
log.info("Mail send to "+Arrays.toString(targetuser));
} catch(Exception e) {
e.printStackTrace();
}
}
示例10: javaMailSender
import org.springframework.mail.javamail.JavaMailSender; //导入依赖的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;
}
示例11: CaptchaService
import org.springframework.mail.javamail.JavaMailSender; //导入依赖的package包/类
@Autowired
public CaptchaService(UserInfoValidator userInfoValidator, LsPushProperties lsPushProperties,
JavaMailSender mailSender, TemplateEngine templateEngine, ObjectMapper objectMapper,
UserRepository userRepo) {
mUserInfoValidator = userInfoValidator;
serverName = lsPushProperties.getServerName();
serverUrl = lsPushProperties.getServerUrl();
serverEmail = lsPushProperties.getServerEmail();
mMailSender = mailSender;
mTemplateEngine = templateEngine;
mObjectMapper = objectMapper;
mUserRepo = userRepo;
mAuthCodeMap = CacheBuilder.newBuilder()
.initialCapacity(100)
.maximumSize(500)
.expireAfterWrite(30, TimeUnit.MINUTES)
.build();
mStringFunnel = (Funnel<String>) (from, into) -> into.putString(from, StandardCharsets.UTF_8);
resetBloomFilter();
}
示例12: getMailSender
import org.springframework.mail.javamail.JavaMailSender; //导入依赖的package包/类
public JavaMailSender getMailSender() {
if (mailSender == null) {
final JavaMailSenderImpl impl = new JavaMailSenderImpl();
impl.setHost(smtpServer);
impl.setPort(smtpPort);
final Properties properties = new Properties();
if (StringUtils.isNotEmpty(smtpUsername)) {
// Use authentication
properties.setProperty("mail.smtp.auth", "true");
impl.setUsername(smtpUsername);
impl.setPassword(smtpPassword);
}
if (smtpUseTLS) {
properties.setProperty("mail.smtp.starttls.enable", "true");
}
impl.setJavaMailProperties(properties);
mailSender = impl;
}
return mailSender;
}
示例13: sendMail
import org.springframework.mail.javamail.JavaMailSender; //导入依赖的package包/类
private Consumer<UserEntity> sendMail(JavaMailSender mailSender, final MessageEntity messageEntity) {
return foundUser -> {
if (ofNullable(foundUser.getEmail()).isPresent()) {
MimeMessagePreparator preparator = mimeMessage -> {
MimeMessageHelper message = new MimeMessageHelper(mimeMessage, true, "UTF-8");
message.setFrom("[email protected]");
message.setSubject("New message from @" + messageEntity.getFrom());
message.setTo(foundUser.getEmail());
String textContent = new MailTemplates()
.create("message")
.data("text", messageEntity.getText())
.getText();
String htmlContent = new MailTemplates()
.create("message.html")
.data("text", htmlContent(messageEntity))
.getText();
message.setText(textContent, htmlContent);
};
mailSender.send(preparator);
}
};
}
示例14: EmailService
import org.springframework.mail.javamail.JavaMailSender; //导入依赖的package包/类
public EmailService(JavaMailSender mailSender, String supportEmail, String personalName)
throws UnsupportedEncodingException {
if(mailSender==null) {
throw new IllegalArgumentException("EmailService constructor contains a null JavaMailSender argument");
}
if(supportEmail==null) {
throw new IllegalArgumentException("EmailService constructor contains a null String argument");
}
Address[] temp = null;
try {
temp = new Address[] {new InternetAddress(supportEmail, personalName)};
} catch (IllegalArgumentException e) {
LOGGER.error(e);
}
this.senderAddresses = temp;
this.mailSender = mailSender;
}
示例15: tryLookup
import org.springframework.mail.javamail.JavaMailSender; //导入依赖的package包/类
/**
* Try to perform the lookup of the email service. This is called during
* configuration so that any failure happens at a useful, predictable time.
*/
@PostConstruct
public void tryLookup() {
if (!isAvailable()) {
log.warn("no mail support; disabling email dispatch");
sender = null;
return;
}
try {
if (sender instanceof JavaMailSender)
((JavaMailSender) sender).createMimeMessage();
} catch (Throwable t) {
log.warn("sender having problems constructing messages; "
+ "disabling...", t);
sender = null;
}
}