Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring 添加或不添加邮件模板在jhipster中发送邮件_Spring_Spring Boot_Smtp_Thymeleaf_Jhipster - Fatal编程技术网

Spring 添加或不添加邮件模板在jhipster中发送邮件

Spring 添加或不添加邮件模板在jhipster中发送邮件,spring,spring-boot,smtp,thymeleaf,jhipster,Spring,Spring Boot,Smtp,Thymeleaf,Jhipster,我需要在…/build/resources/main/mails/abc.html中添加一个邮件模板(abc.html),如default activationEmail.html、CreationEmail.html、passwordResetEmail.html。当我手动创建abc.html并运行gradlew执行应用程序后,新创建的abc.html文件将被删除。那么我怎样才能创造它呢?我需要在其他地方注册该文件吗? 在jhipster中创建实体时,是否有任何特定的命令来创建html文件。我

我需要在…/build/resources/main/mails/abc.html中添加一个邮件模板(abc.html),如default activationEmail.html、CreationEmail.html、passwordResetEmail.html。当我手动创建abc.html并运行gradlew执行应用程序后,新创建的abc.html文件将被删除。那么我怎样才能创造它呢?我需要在其他地方注册该文件吗? 在jhipster中创建实体时,是否有任何特定的命令来创建html文件。我的最终目标是发送邮件。但是如果不创建模板,我就不知道如何在MailService.java中传递sendMail方法中content变量的值。为内容分配null也不起作用。那么,是否有任何内置方法可以不使用模板发送邮件

@Async
public void sendEmail(String to, String subject, String content, boolean isMultipart, boolean isHtml) {
    log.debug("Send email[multipart '{}' and html '{}'] to '{}' with subject '{}' and content={}",
        isMultipart, isHtml, to, subject, content);

    // Prepare message using a Spring helper
    MimeMessage mimeMessage = javaMailSender.createMimeMessage();
    try {
        MimeMessageHelper message = new MimeMessageHelper(mimeMessage, isMultipart, CharEncoding.UTF_8);
        message.setTo(to);
        message.setFrom(jHipsterProperties.getMail().getFrom());
        message.setSubject(subject);
        message.setText(content, isHtml);
        javaMailSender.send(mimeMessage);
        log.debug("Sent email to User '{}'", to);
    } catch (Exception e) {
        if (log.isDebugEnabled()) {
            log.warn("Email could not be sent to user '{}'", to, e);
        } else {
            log.warn("Email could not be sent to user '{}': {}", to, e.getMessage());
        }
    }
}

@Async
public void sendSportMail(String email,String message) {
    log.debug("Sending sports email to '{}'", email," message");
    Locale locale = Locale.forLanguageTag("en");
    String subject = messageSource.getMessage("email.reset.title", null, locale);
    Context context = new Context(locale);
    context.setVariable(BASE_URL, jHipsterProperties.getMail().getBaseUrl());
    String content = templateEngine.process("creationEmail", context);
    sendEmail(email, subject, content, false, true);
}

在sendSportMail方法中没有“creationEmail”,我需要传递一个值(“abc”)。或者,如果有任何方法发送邮件而不创建更好的模板。因为实际上我不需要邮件模板。我可以在sendSportMail方法中检索电子邮件和消息参数的值。所以我只需要发送邮件,邮件主体是消息,收件人的邮件是电子邮件。gmail的配置做得很好,对于密码重置、创建用户等内置功能来说效果很好。

不要在build/folder中创建任何内容,因为gradle使用它来编译和打包您的项目。它类似于maven的target/folder

在src/main/resources/mails/中创建html模板