本文整理匯總了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;
}
}