Java jhipster项目中正确配置我的smtp设置
我的jhipster应用程序的配置有一些问题。这是我的配置文件的一部分:Java jhipster项目中正确配置我的smtp设置,java,spring,email,jakarta-mail,jhipster,Java,Spring,Email,Jakarta Mail,Jhipster,我的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
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配置的问题在哪里
--编辑:
这是我的新配置:
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
DemoApp帐户激活
亲爱的dkj
您的DemoApp帐户已创建,请单击下面的URL将其激活:
当做
DemoApp团队。
2015-12-25 18:23:31.119调试5677---[-app-Executor-1]com.sun.mail.smtp:useEhlo true,useAuth false
2015-12-25 18:23:31.119调试5677---[-app-Executor-1]com.sun.mail.smtp:尝试连接到主机“smtp.mail.yahoo.com”,端口587,isSSL false
2015-12-25 18:23:31.581调试5677---[-app-Executor-1]com.sun.mail.smtp:已连接到主机“smtp.mail.yahoo.com”,端口:587
2015-12-25 18:23:31.740调试5677---[-app-Executor-1]com.sun.mail.smtp:找到扩展名“pipeline”,arg“”
2015-12-25 18:23:31.740调试5677---[-app-Executor-1]com.sun.mail.smtp:找到扩展名“SIZE”,arg“41697280”
2015-12-25 18:23:31.740调试5677---[-app-Executor-1]com.sun.mail.smtp:找到扩展名“8”,arg“BITMIME”
2015-12-25 18:23:31.740调试5677---[-app-Executor-1]com.sun.mail.smtp:找到扩展名“STARTTLS”,arg“”
2015-12-25 18:23:32.436调试5677---[-app-Executor-1]com.sun.mail.smtp:找到扩展名“pipeline”,arg“”
2015-12-25 18:23:32.436调试5677---[-app-Executor-1]com.sun.mail.smtp:找到扩展名“SIZE”,arg“41697280”
2015-12-25 18:23:32.436调试5677---[-app-Executor-1]com.sun.mail.smtp:找到扩展名“8”,参数“BITMIME”
2015-12-25 18:23:32.436调试5677---[-app-Executor-1]com.sun.mail.smtp:找到扩展名“AUTH”,arg“普通登录XOAUTH2 XYMCOOKIE”
2015-12-25 18:23:32.436调试5677---[-app-Executor-1]com.sun.mail.smtp:尝试使用机制进行身份验证:登录普通摘要-MD5 NTLM
2015-12-25 18:23:33.470调试5677---[-app-Executor-1]com.sun.mail.smtp:use8bit false
2015-12-25 18:23:33.703调试5677---[-app-Executor-1]com.sun.mail.smtp:获取响应代码501,响应:501参数中存在语法错误
2015-12-25 18:23:33.945调试5677---[-app-Executor-1]com.sun.mail.smtp:发送时出现MessagineException
com.sun.mail.smtp.SMTPSendFailedException:参数中存在501语法错误
在com.sun.mail.SMTPTransport.issueSendCommand(SMTPTransport.java:2203)~[javax.mail-1.5.4.jar:1.5.4]
在com.sun.mail.SMTPTransport.mailFrom(SMTPTransport.java:1694)~[javax.mail-1.5.4.jar:1.5.4]
在com.sun.mail.SMTPTransport.sendMessage(SMTPTransport.java:1194)~[javax.mail-1.5.4.jar:1.5.4]
在org.springframework.mail.javamail.JavaMailSenderImpl.doSend(JavaMailSenderImpl.java:448)[spring-context-support-4.2.3.RELEASE.jar:4.2.3.RELEASE]
在org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:345)[spring-context-support-4.2.3.RELEASE.jar:4.2.3.RELEASE]
在org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:340)[spring-context-support-4.2.3.RELEASE.jar:4.2.3.RELEASE]
在net.demo.service.MailService.sendmail(MailService.java:65)[classes/:na]
在net.demo.service.MailService.sendActivationEmail(MailService.java:81)[classes/:na]
在net.demo.service.MailService$$FastClassBySpringCGLIB$$bf501f3f.invoke()[classes/:na]
在org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)[spring-core-4.2.3.RELEASE.jar:4.2.3.RELEASE]
位于org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:718)[spring-aop-4.2.3.RELEASE.jar:4.2.3.RELEASE]
在org.springframework.aop.framework.ReflectiveMethodInvocation.procedue(ReflectiveMethodInvocation.java:157)[spring-aop-4.2.3.RELEASE.jar:4.2.3.RELEASE]
在org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.procedue(MethodInvocationProceedingJoinPoint.java:85)[spring-aop-4.2.3.RELEASE.jar:4.2.3.RELEASE]
在net.demo.aop.logging.LoggingAspect.logAround(LoggingAspect.java:51)[classes/:na]
在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)~[na:1.8.0_65]
在sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)~[na:1.8.0\u 65]
在sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)~[na:1.8.065]
在java.lang.reflect.Method.invoke(Method.java:497)~[na:1.8.0_65]
在org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:621)[spring-aop-4.2.3.RELEASE.jar:4.2.3.RELEASE]
在org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:610)[spring-aop-4.2.3.RELEASE.jar:4.2.3.RELEASE]
在org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:68)[spring-aop-4.2.3.RELEASE.jar:4.2.3.RELEASE]
在org.springframework.aop.framework.ReflectiveMethodInvocation.procedue(ReflectiveMethodInvocation.java:179)[spring-aop-4.2.3.RELEASE.jar:4.2.3.RELEASE]
在org.springframework.aop.aspectj.aspectjafthrowingadvice.invoke(aspectjafthrowingadvice.java:58)[spring-aop-4.2.3.RELEASE.jar:4.2.3.RELEASE]
在org.springframework.aop.framework.ReflectiveMethodInvocation.procedue(ReflectiveMethodInvocation.java:179)[spring-aop-4.2.3
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
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
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
@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