In my java application I have a module that allows to send mails


        host: smtp.gmail.com
        port: 587
        username: xxxxxx@gmail.com  #Replace this field with your Gmail username.
        password: xxxxxxx           #Replace this field with your Gmail password.
        protocol: smtp
        tls: true
            auth: true
            starttls.enable: true
            ssl.trust: smtp.gmail.com


    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, StandardCharsets.UTF_8.name());
            message.setText(content, isHtml);
            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());

When I use my application locally (Windows 10) I receive my emails. But when I deploy my application on my server Centos 7 I do not receive any mail and I have no error in my logs.

So I wonder if it is necessary to install a postfix or others on my server Centos 7 to relay the mail?

I opened port 587 25 on my Centos 7 firewall

  • Can your CentOS machine resolve smtp.gmail.com? Can it get to port 587/tcp on the server(s) defined by that name? – roaima Mar 28 at 15:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.