我的jhipster应用程序配置存在一些问题。这是我的配置文件的一部分:
mail:
host: smtp.mail.yahoo.com
port: 465
username: My_smtp_login
password: my_smtp_password
protocol: smtp
tls: true
auth: true
from: mymail@yahoo.pl
messages:
cache-seconds: 1
thymeleaf:
cache: false
和我的日志:
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 'xxxx@yandex.com', 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
这不仅是雅虎问题,我还是使用AOL,Gmail和Yandex查看过,但是smtp存在同样的问题。 smtp配置的问题在哪里?
- 编辑:
这是我的新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: login@yahoo.com
password: password
protocol: smtp
tls: true
properties.mail.smtp:
auth: true
starttls.enable: true
ssl.trust: smtp.mail.yahoo.com
from: login@yahoo.com
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
但问题仍然存在:
<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 'login@gmail.com', 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
我找到了删除
的信息来自:mymail@yahoo.pl 应该有所帮助,但它在我的案例中没有用
答案 0 :(得分:1)
我遇到了和你一样的错误。我的解决方案是将from: mymail@yahoo.pl
(必须与雅虎邮件用户名一样)放到以下部分:
jhipster:
mail:
from: mymail@yahoo.pl
也可以在application-prod.yml或application-dev.yml文件中找到,但下面有几行:
spring:
mail:
部分。 所以我的整个解决方案如下(使用您的示例凭据):
spring:
...
mail:
host: smtp.mail.yahoo.com
port: 587
username: mymail@yahoo.pl
password: my_smtp_password
protocol: smtp
tls: true
properties.mail.smtp:
auth: true
starttls.enable: true
ssl.trust: smtp.mail.yahoo.com
和
jhipster:
...
mail:
from: mymail@yahoo.pl
答案 1 :(得分:0)
您是否已检查过可以使用telnet从外部JHipster连接到此SMTP服务器?也许你被防火墙阻挡了。
另外,您应该为spring.mail.properties.mail.smtp
设置其他属性,如下所示。
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: mymail@yahoo.pl
答案 2 :(得分:0)
我发现的大多数示例都使用了来自https://jhipster.github.io/tips/011_tip_configuring_email_in_jhipster.html
的clasic配置我遇到了与尝试使用Exchange Server进行连接时相同的错误。 修复程序是将SMTP属性添加到spring:mail,以便在Session
中加载这些属性所以我在配置文件application-dev.yml中添加了我需要的SMTP属性 (见: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: yourproject@something.com
为了检查Session,我在MailService类中添加了一些调试日志。
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());
}
}
结果,所有属性都被加载到会话中
your.pack.service.MailService : Sending activation e-mail to 'thenewuser@server.com'
your.pack.service.MailService : Send e-mail[multipart 'false' and html 'true'] to 'thenewuser@server.com' 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
至少对我而言,它正在发挥作用!