Dennis A. Boanini
Dennis A. Boanini

Reputation: 497

How send email from jhipster application

I've developed an application using jhipster. I've setted application-dev.yml file with this information

mail:
    host: smtp.gmail.com
    port: 587
    username: **********@gmail.com
    password: ****************
    protocol: smtp
    tls: true
    properties.mail.smtp:
            auth: true
            starttls.enable: true
            ssl.trust: smtp.gmail.com

and everything work correctly.If a new user registers, the activation mail correct arrive to user email address. My question is, I've write a page contact-me, but I don't understand how send button work, I've, in java backend this method

@Async
public void sendEmail(String to, String subject, String content, boolean isMultipart, boolean isHtml) {
    log.debug("Send e-mail[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 e-mail to User '{}'", to);
    } catch (Exception e) {
        log.warn("E-mail could not be sent to user '{}'", to, e);
    }
}

that I think is the method to use for send mail from contact me form. I need a controller of contact-me html page? This is my contact me html page http://pastebin.com/h8NniSj1

Upvotes: 4

Views: 5638

Answers (2)

jannis
jannis

Reputation: 5210

Extend your REST API with a "contact me" method (e.g. /api/contactmes) that you will call from your contact form. The endpoint could accept POST requests with the "contact me" form parameters:

{
    "subject": "...",
    "from": "...",
    "message": "..."
}

Then you have options:

  • it could internally use the MailService::sendEMail method to contact you (via email)
  • it could save the info in a DB for you to see it later through your admin panel (if you have one)
  • it could broadcast the message through multiple contact-channels (e.g. Slack, e-mail, FB, etc)
  • etc.

Upvotes: 0

Igor Veloso
Igor Veloso

Reputation: 487

As you are using JHipster, I suppose you have a controller and service on your Angular front-end.

So, I think you can create a Spring-MVC controller to receive your parameters (TO, Subject, etc..) and call this Mail Service (sendMail) you post in your question.

Please let me know if I've understand you question correctly.

Upvotes: 2

Related Questions