M. Bajdek
M. Bajdek

Reputation: 21

correct configuration my smtp settings in jhipster project

I have a few problems with configuration of my jhipster application. This is part of my configuration file:

mail:
    host: smtp.mail.yahoo.com
    port: 465
    username: My_smtp_login
    password: my_smtp_password
    protocol: smtp
    tls: true
    auth: true
    from: [email protected]
messages:
    cache-seconds: 1
thymeleaf:
    cache: false

and my logs:

2015-12-22 20:47:09.680 DEBUG 13428 --- [hero-Executor-2] com.sun.mail.smtp                        : useEhlo true, useAuth false
2015-12-22 20:47:09.680 DEBUG 13428 --- [hero-Executor-2] com.sun.mail.smtp                        : trying to connect to host "smtp.mail.yahoo.com", port 465, isSSL false
2015-12-22 20:48:09.832 DEBUG 13428 --- [hero-Executor-2] com.sun.mail.smtp                        : EOF: [EOF]
2015-12-22 20:48:09.833 DEBUG 13428 --- [hero-Executor-2] com.sun.mail.smtp                        : could not connect to host "smtp.mail.yahoo.com", port: 465, response: -1
2015-12-22 20:48:09.834  WARN 13428 --- [hero-Executor-2] pl.mailinghero.service.MailService       : E-mail could not be sent to user '[email protected]', exception is: Mail server connection failed; nested exception is javax.mail.MessagingException: Could not connect to SMTP host: smtp.mail.yahoo.com, port: 465, response: -1. Failed messages: javax.mail.MessagingException: Could not connect to SMTP host: smtp.mail.yahoo.com, port: 465, response: -1
2015-12-22 20:48:09.834 DEBUG 13428 --- [hero-Executor-2] p.mailinghero.aop.logging.LoggingAspect  : Exit: pl.mailinghero.service.MailService.sendActivationEmail() with result = null

It's not only yahoo problem, i checked with AOL, Gmail and Yandex , but there was the same problem with smtp. Where is the problem with smtp configuration?

--edit:

this is my new conf:

spring:
    profiles:
        active: dev
    devtools:
        restart:
            enabled: true
        livereload:
            enabled: false # we use Grunt + BrowserSync for livereload
    datasource:
        driver-class-name: com.mysql.jdbc.jdbc2.optional.MysqlDataSource
        url: jdbc:mysql://localhost:3306/DemoApp?useUnicode=true&characterEncoding=utf8
        name:
        username: root
        password: password123
    jpa:
        database-platform: org.hibernate.dialect.MySQLInnoDBDialect
        database: MYSQL
        show_sql: true
        properties:
            hibernate.cache.use_second_level_cache: true
            hibernate.cache.use_query_cache: false
            hibernate.generate_statistics: true
            hibernate.cache.region.factory_class: org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory
    data:
        elasticsearch:
            cluster-name:
            cluster-nodes:
            properties:
                path:
                  logs: target/elasticsearch/log
                  data: target/elasticsearch/data
    mail:
        host: smtp.mail.yahoo.com
        port: 587
        username: [email protected]
        password: password
        protocol: smtp
        tls: true
        properties.mail.smtp:
             auth: true
             starttls.enable: true
             ssl.trust: smtp.mail.yahoo.com
        from: [email protected]
    messages:
        cache-seconds: 1
    thymeleaf:
        cache: false

liquibase:
    contexts: dev

server:
    port: 8080

# ===================================================================
# JHipster specific properties
# ===================================================================

jhipster:
    datasource: # JHipster-specific configuration, in addition to the standard spring.datasource properties
        cachePrepStmts: true
        prepStmtCacheSize: 250
        prepStmtCacheSqlLimit: 2048
        useServerPrepStmts: true
    cache: # Hibernate 2nd level cache, used by CacheConfiguration
        timeToLiveSeconds: 3600
        ehcache:
            maxBytesLocalHeap: 16M
    mail: # specific JHipster mail property, for standard properties see MailProperties
        from: DemoApp@localhost
    metrics: # DropWizard Metrics configuration, used by MetricsConfiguration
        jmx.enabled: true
        spark:
            enabled: false
            host: localhost
            port: 9999
        graphite:
            enabled: false
            host: localhost
            port: 2003
            prefix: DemoApp

but problem still exist:

<html>
    <head>
        <title>DemoApp account activation</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    </head>
    <body>
        <p>Dear dkj</p>
        <p>Your DemoApp account has been created, please click on the URL below to activate it:</p>
        <p>
            <a href="http://localhost:8080/#/activate?key=95189449636004891182">dkj</a>
        </p>
        <p>
            <span>Regards,</span>
            <br />
            <em>DemoApp Team.</em>
        </p>
    </body>
</html>

2015-12-25 18:23:31.119 DEBUG 5677 --- [-app-Executor-1] com.sun.mail.smtp                        : useEhlo true, useAuth false
2015-12-25 18:23:31.119 DEBUG 5677 --- [-app-Executor-1] com.sun.mail.smtp                        : trying to connect to host "smtp.mail.yahoo.com", port 587, isSSL false
2015-12-25 18:23:31.581 DEBUG 5677 --- [-app-Executor-1] com.sun.mail.smtp                        : connected to host "smtp.mail.yahoo.com", port: 587

2015-12-25 18:23:31.740 DEBUG 5677 --- [-app-Executor-1] com.sun.mail.smtp                        : Found extension "PIPELINING", arg ""
2015-12-25 18:23:31.740 DEBUG 5677 --- [-app-Executor-1] com.sun.mail.smtp                        : Found extension "SIZE", arg "41697280"
2015-12-25 18:23:31.740 DEBUG 5677 --- [-app-Executor-1] com.sun.mail.smtp                        : Found extension "8", arg "BITMIME"
2015-12-25 18:23:31.740 DEBUG 5677 --- [-app-Executor-1] com.sun.mail.smtp                        : Found extension "STARTTLS", arg ""
2015-12-25 18:23:32.436 DEBUG 5677 --- [-app-Executor-1] com.sun.mail.smtp                        : Found extension "PIPELINING", arg ""
2015-12-25 18:23:32.436 DEBUG 5677 --- [-app-Executor-1] com.sun.mail.smtp                        : Found extension "SIZE", arg "41697280"
2015-12-25 18:23:32.436 DEBUG 5677 --- [-app-Executor-1] com.sun.mail.smtp                        : Found extension "8", arg "BITMIME"
2015-12-25 18:23:32.436 DEBUG 5677 --- [-app-Executor-1] com.sun.mail.smtp                        : Found extension "AUTH", arg "PLAIN LOGIN XOAUTH2 XYMCOOKIE"
2015-12-25 18:23:32.436 DEBUG 5677 --- [-app-Executor-1] com.sun.mail.smtp                        : Attempt to authenticate using mechanisms: LOGIN PLAIN DIGEST-MD5 NTLM 
2015-12-25 18:23:33.470 DEBUG 5677 --- [-app-Executor-1] com.sun.mail.smtp                        : use8bit false
2015-12-25 18:23:33.703 DEBUG 5677 --- [-app-Executor-1] com.sun.mail.smtp                        : got response code 501, with response: 501 Syntax error in arguments

2015-12-25 18:23:33.945 DEBUG 5677 --- [-app-Executor-1] com.sun.mail.smtp                        : MessagingException while sending

com.sun.mail.smtp.SMTPSendFailedException: 501 Syntax error in arguments

    at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:2203) ~[javax.mail-1.5.4.jar:1.5.4]
    at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:1694) ~[javax.mail-1.5.4.jar:1.5.4]
    at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1194) ~[javax.mail-1.5.4.jar:1.5.4]
    at org.springframework.mail.javamail.JavaMailSenderImpl.doSend(JavaMailSenderImpl.java:448) [spring-context-support-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:345) [spring-context-support-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:340) [spring-context-support-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at net.demo.service.MailService.sendEmail(MailService.java:65) [classes/:na]
    at net.demo.service.MailService.sendActivationEmail(MailService.java:81) [classes/:na]
    at net.demo.service.MailService$$FastClassBySpringCGLIB$$bf501f3f.invoke(<generated>) [classes/:na]
    at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204) [spring-core-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:718) [spring-aop-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) [spring-aop-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:85) [spring-aop-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at net.demo.aop.logging.LoggingAspect.logAround(LoggingAspect.java:51) [classes/:na]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_65]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_65]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_65]
    at java.lang.reflect.Method.invoke(Method.java:497) ~[na:1.8.0_65]
    at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:621) [spring-aop-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:610) [spring-aop-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:68) [spring-aop-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) [spring-aop-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.aop.aspectj.AspectJAfterThrowingAdvice.invoke(AspectJAfterThrowingAdvice.java:58) [spring-aop-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) [spring-aop-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92) [spring-aop-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) [spring-aop-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.aop.interceptor.AsyncExecutionInterceptor$1.call(AsyncExecutionInterceptor.java:108) [spring-aop-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_65]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_65]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_65]
    at java.lang.Thread.run(Thread.java:745) [na:1.8.0_65]
Caused by: com.sun.mail.smtp.SMTPSenderFailedException: 501 Syntax error in arguments

    at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:1703) ~[javax.mail-1.5.4.jar:1.5.4]
    ... 29 common frames omitted

2015-12-25 18:23:34.189  WARN 5677 --- [-app-Executor-1] net.demo.service.MailService             : E-mail could not be sent to user '[email protected]', exception is: Failed messages: com.sun.mail.smtp.SMTPSendFailedException: 501 Syntax error in arguments
;
  nested exception is:
    com.sun.mail.smtp.SMTPSenderFailedException: 501 Syntax error in arguments

2015-12-25 18:23:34.189 DEBUG 5677 --- [-app-Executor-1] net.demo.aop.logging.LoggingAspect       : Exit: net.demo.service.MailService.sendActivationEmail() with result = null

I found information, that remove

from: [email protected] should help, but it didn't work in my case

Upvotes: 2

Views: 3621

Answers (3)

NNSOFT
NNSOFT

Reputation: 1

Most examples I found use the clasic configurations from: https://jhipster.github.io/tips/011_tip_configuring_email_in_jhipster.html

I had the same error like you trying to connect using Exchange Server. The fix was add the SMTP properties to spring:mail, in order to get those properties loaded in the Session

So I added the SMTP properties that I needed in the profile application-dev.yml (See: https://javamail.java.net/nonav/docs/api/com/sun/mail/smtp/package-summary.html)

spring:
    mail:
        host: 10.10.10.10
        port: 25
        username: 
        password: 
        properties.mail.smtp:
            host: 10.10.10.10
            port: 25
            auth: false
            starttls.enable: false
            connectiontimeout: 180000
            timeout: 180000

jhipster:
    mail: 
        from: [email protected]

In order to check the Session, I have added some debug logs in the MailService class.

Class: your.pack.service.MailService.java

@Inject
private MailProperties mailProperties;

@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);

        // --- Debug Code
        log.debug("----- spring: mail: -----");
        log.debug("spring mail: host={}", mailProperties.getHost());
        log.debug("spring mail: port={}", mailProperties.getPort());
        log.debug("spring mail: username={}", mailProperties.getUsername());
        log.debug("spring mail: password={}", mailProperties.getPassword());
        log.debug("spring mail: protocol={}", mailProperties.getProtocol());

        log.debug("----- spring: mail: properties.mail.smtp -----");
        for (Entry<String, String> entry : mailProperties.getProperties().entrySet()) {
            log.debug("properties.mail.smtp: {}={}", entry.getKey(), entry.getValue());
        }

        log.debug("----- session object -----");
        for (Entry<Object, Object> entry : message.getMimeMessage().getSession().getProperties().entrySet()) {
            log.debug("session: {}={}", entry.getKey(), entry.getValue());
        }
        // --- Debug Code

        javaMailSender.send(mimeMessage);
        log.debug("Sent e-mail to User '{}'", to);
    } catch (Exception e) {
        log.warn("E-mail could not be sent to user '{}', exception is: {}", to, e.getMessage());
    }
}

The result, all properties were loaded into the session

your.pack.service.MailService    : Sending activation e-mail to '[email protected]'
your.pack.service.MailService    : Send e-mail[multipart 'false' and html 'true'] to '[email protected]' with subject 'YourProject account activation' and content=<!DOCTYPE html>
...
...
your.pack.service.MailService    : ----- spring: mail: -----
your.pack.service.MailService    : spring mail: host=10.10.10.10
your.pack.service.MailService    : spring mail: port=25
your.pack.service.MailService    : spring mail: username=
your.pack.service.MailService    : spring mail: password=
your.pack.service.MailService    : spring mail: protocol=smtp
...
your.pack.service.MailService    : ----- spring: mail: properties.mail.smtp -----
your.pack.service.MailService    : properties.mail.smtp: mail.smtp.port=25
your.pack.service.MailService    : properties.mail.smtp: mail.smtp.auth=false
your.pack.service.MailService    : properties.mail.smtp: mail.smtp.starttls.enable=false
your.pack.service.MailService    : properties.mail.smtp: mail.smtp.timeout=180000
your.pack.service.MailService    : properties.mail.smtp: mail.smtp.host=10.10.10.10
your.pack.service.MailService    : properties.mail.smtp: mail.smtp.connectiontimeout=180000
...
your.pack.service.MailService    : ----- session object -----
your.pack.service.MailService    : session: mail.smtp.starttls.enable=false
your.pack.service.MailService    : session: mail.smtp.port=25
your.pack.service.MailService    : session: mail.smtp.host=10.10.10.10
your.pack.service.MailService    : session: mail.smtp.auth=false
your.pack.service.MailService    : session: mail.smtp.timeout=180000
your.pack.service.MailService    : session: mail.smtp.connectiontimeout=180000

At least for me, it's working!

Upvotes: 0

Tobias Mini
Tobias Mini

Reputation: 380

I had the same error like you. The solution for me was to put the from: [email protected] (which has to be the same like the yahoo mail username) to the section:

jhipster: mail: from: [email protected]

which also can be found in the application-prod.yml or application-dev.yml files but several lines below the:

spring:
       mail:

section. So the whole solution for me looks as follows (using your example credentials):

spring:
        ...
          mail:
               host: smtp.mail.yahoo.com
               port: 587
               username: [email protected]
               password: my_smtp_password
               protocol: smtp
               tls: true
          properties.mail.smtp:
               auth: true
               starttls.enable: true
               ssl.trust: smtp.mail.yahoo.com

and:

jhipster:
         ...
         mail: 
              from: [email protected]

Upvotes: 1

Ga&#235;l Marziou
Ga&#235;l Marziou

Reputation: 16294

Have you checked that you can connect to this SMTP server from outside JHipster, using telnet for instance? Maybe you're blocked by a firewall.

Also you should set spring.mail.properties.mail.smtp for additional properties like below.

spring:
    mail:
        host: smtp.mail.yahoo.com
        port: 587
        username: My_smtp_login
        password: my_smtp_password
        protocol: smtp
        tls: true
        properties.mail.smtp:
             auth: true
             starttls.enable: true
             ssl.trust: smtp.mail.yahoo.com
        from: [email protected]

Upvotes: 0

Related Questions