2017-10-06 124 views
0

我是新来的春天,我有一些问题使用春季启动邮件发送邮件。 我在我的application.properties文件中定义了用户,密码和其他所有内容,但spring试图使用我的电脑用户名(usuario @ usuario-Inspiron-3647)发送电子邮件。春季启动邮件忽略application.properties

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 = [email protected] 
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 <[email protected]>: 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 <[email protected]>: 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电子邮件配置信息,我没能找到类似的谷歌搜索任何东西。

回答

0

看起来Sender address rejected: need fully-qualified address希望你能为你的邮件设置电子邮件发件人地址:

SimpleMailMessage message = new SimpleMailMessage(); 
message.setFrom("[email protected]"); 

... 
+0

我已经试过了。它没有工作。它仍然尝试使用我的桌面用户名进行身份验证,因此我仍然得到相同的异常。 –