我是春天的新手,我在使用Spring启动邮件发送邮件时遇到了一些问题。 我在application.properties文件中定义了用户,密码和其他所有内容,但是Spring正在尝试使用我的pc用户名发送电子邮件(usuario @ usuario-Inspiron-3647)。
application.properties
#spring boot properties
#Mon Oct 02 08:41:37 EDT 2017
spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.username=postgres
spring.datasource.password=postgres
spring.datasource.url=jdbc\:postgresql\://localhost/database
spring.jpa.hibernate.ddl-auto=validate
#Spring Mail Config
spring.mail.host = email-ssl.com.br
spring.mail.port = 587
spring.mail.username = teste@teste.com
spring.mail.password = teste
spring.mail.properties.mail.smtp.auth = true
spring.mail.properties.mail.smtp.starttls.enable = true
EmailServiceImpl
@Component
public class EmailServiceImpl implements EmailService {
@Autowired
public JavaMailSender emailSender;
@Override
public boolean sendSimpleMessage(String to, String subject, String text, String cc, String bcc) {
try {
SimpleMailMessage message = new SimpleMailMessage();
message.setTo(to);
message.setSubject(subject);
message.setText(text);
message.setCc(cc);
message.setBcc(bcc);
emailSender.send(message);
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
}
这是我得到的例外
org.springframework.mail.MailSendException: Failed messages: javax.mail.SendFailedException: Invalid Addresses;
nested exception is:
com.sun.mail.smtp.SMTPAddressFailedException: 504 5.5.2 <usuario@usuario-Inspiron-3647>: Sender address rejected: need fully-qualified address
; message exception details (1) are:
Failed message 1:
javax.mail.SendFailedException: Invalid Addresses;
nested exception is:
com.sun.mail.smtp.SMTPAddressFailedException: 504 5.5.2 <usuario@usuario-Inspiron-3647>: Sender address rejected: need fully-qualified address
的pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<packaging>war</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.3.RELEASE</version>
</parent>
<groupId>com.spring.teste</groupId>
<artifactId>webservice</artifactId>
<version>1.0.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>1.7</maven.compiler.source>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.target>1.7</maven.compiler.target>
<jjwt.version>0.6.0</jjwt.version>
</properties>
<dependencyManagement />
<dependencies>
<!-- Spring Boot -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<scope>compile</scope>
</dependency>
<!-- Spring Data -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<!-- Spring Security -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<!-- Spring Mail -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
<!-- Spring Boot Tomcat -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<!-- Hibernate -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>5.4.1.Final</version>
<scope>compile</scope>
</dependency>
<!-- PostgreSQL -->
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.4-1201-jdbc41</version>
</dependency>
<!-- Jackson JSON Processor -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.8.8</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.8.8</version>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
<version>${jjwt.version}</version>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.1.0.Final</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp.jstl</groupId>
<artifactId>jstl-api</artifactId>
<version>1.2</version>
<scope>compile</scope>
<exclusions>
<exclusion>
<artifactId>servlet-api</artifactId>
<groupId>javax.servlet</groupId>
</exclusion>
<exclusion>
<artifactId>jsp-api</artifactId>
<groupId>javax.servlet.jsp</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.glassfish.web</groupId>
<artifactId>jstl-impl</artifactId>
<version>1.2</version>
<scope>compile</scope>
<exclusions>
<exclusion>
<artifactId>servlet-api</artifactId>
<groupId>javax.servlet</groupId>
</exclusion>
<exclusion>
<artifactId>jsp-api</artifactId>
<groupId>javax.servlet.jsp</groupId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
其他所有内容都运行正常,但我无法找到为什么它没有从application.properties获取电子邮件配置信息,而且我也无法找到任何类似的Google搜索信息。
答案 0 :(得分:0)
看起来import * as React from "react";
import { NavLink, Link } from 'react-router-dom';
export interface LeftNavigationProps {
title: string;
path: string;
}
export class LeftNavigationItem {
title: string;
path: string;
constructor(title: string, path: string) {
this.title = title;
this.path = path;
}
}
export const LeftNavigation: React.StatelessComponent<LeftNavigationProps> = (props: LeftNavigationProps) => {
const items: Array<LeftNavigationItem> = [
new LeftNavigationItem('On demand tests', '/ondemandtests'),
new LeftNavigationItem('Fleet status', '/fleetstatus')
];
return (
<div id="synth-left-nav" className="uk-margin-bottom">
<h1 className="uk-h3">
<span><Link id="synth-left-nav-title" to={props.path}>{props.title}</Link></span>
</h1>
<hr className="uk-width-1-1" />
<ul className="uk-nav uk-margin-remove"> {
items.map(function (m, index) {
return (
<li key={m.path}>
<NavLink activeClassName="uk-text-bold uk-active"
to={props.path + m.path} replace>{m.title}</NavLink>
</li>
);
})
}
</ul>
</div>
);
};
希望您为邮件设置电子邮件发件人地址:
Sender address rejected: need fully-qualified address
答案 1 :(得分:0)
解决了添加到application.properties:
的问题spring.mail.properties.mail.smtp.from=teste@teste.com