Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -184,14 +184,12 @@
<module>spring-katharsis</module>
<module>spring-ldap</module>
<module>spring-mockito</module>
<module>spring-mvc-email</module>
<module>spring-mvc-forms-jsp</module>
<module>spring-mvc-forms-thymeleaf</module>
<module>spring-mvc-java</module>
<module>spring-mvc-velocity</module>
<module>spring-mvc-webflow</module>
<module>spring-mvc-xml</module>
<module>spring-mvc-simple</module>
<module>spring-mvc-kotlin</module>
<module>spring-security-openid</module>
<module>spring-protobuf</module>
Expand Down
17 changes: 0 additions & 17 deletions spring-mvc-email/README.md

This file was deleted.

40 changes: 0 additions & 40 deletions spring-mvc-email/pom.xml

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

19 changes: 0 additions & 19 deletions spring-mvc-email/src/main/resources/META-INF/application.xml

This file was deleted.

29 changes: 0 additions & 29 deletions spring-mvc-email/src/main/webapp/WEB-INF/web.xml

This file was deleted.

1 change: 1 addition & 0 deletions spring-mvc-simple/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
- [Spring 5 and Servlet 4 – The PushBuilder](http://www.baeldung.com/spring-5-push)
- [Servlet Redirect vs Forward](http://www.baeldung.com/servlet-redirect-forward)
- [Apache Tiles Integration with Spring MVC](http://www.baeldung.com/spring-mvc-apache-tiles)
- [Guide to Spring Email](http://www.baeldung.com/spring-email)
11 changes: 10 additions & 1 deletion spring-mvc-simple/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@
<artifactId>spring-oxm</artifactId>
<version>${spring-oxm.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
</dependency>
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>javax.mail</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
Expand Down Expand Up @@ -171,7 +180,7 @@
<jstl.version>1.2</jstl.version>
<javax.servlet.jsp-api.version>2.3.2-b02</javax.servlet.jsp-api.version>
<javax.servlet-api.version>4.0.0</javax.servlet-api.version>
<hibernate-validator.version>5.4.1.Final</hibernate-validator.version>
<hibernate-validator.version>6.0.10.Final</hibernate-validator.version>
<deploy-path>enter-location-of-server</deploy-path>
<fileupload.version>1.3.2</fileupload.version>
<java.version>1.8</java.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.http.converter.feed.RssChannelHttpMessageConverter;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.web.accept.ContentNegotiationManager;
import org.springframework.web.multipart.MultipartResolver;
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
Expand All @@ -20,10 +23,11 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

@Configuration
@EnableWebMvc
@ComponentScan(basePackages = { "com.baeldung.springmvcforms", "com.baeldung.spring.controller", "com.baeldung.spring.validator" })
@ComponentScan(basePackages = { "com.baeldung.springmvcforms", "com.baeldung.spring.controller", "com.baeldung.spring.validator", "com.baeldung.spring.mail" })
public class ApplicationConfiguration implements WebMvcConfigurer {

@Override
Expand Down Expand Up @@ -60,4 +64,29 @@ public void configureMessageConverters(List<HttpMessageConverter<?>> converters)
converters.add(new RssChannelHttpMessageConverter());
converters.add(new JsonChannelHttpMessageConverter());
}

@Bean
public SimpleMailMessage templateSimpleMessage() {
SimpleMailMessage message = new SimpleMailMessage();
message.setText("This is the test email template for your email:\n%s\n");
return message;
}

@Bean
public JavaMailSender getJavaMailSender() {
JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
mailSender.setHost("smtp.gmail.com");
mailSender.setPort(587);

mailSender.setUsername("my.gmail@gmail.com");
mailSender.setPassword("password");

Properties props = mailSender.getJavaMailProperties();
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.debug", "true");

return mailSender;
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package com.baeldung.spring.controllers;
package com.baeldung.spring.controller;

import com.baeldung.spring.mail.EmailServiceImpl;
import com.baeldung.spring.web.dto.MailObject;
import com.baeldung.spring.domain.MailObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.stereotype.Controller;
Expand Down Expand Up @@ -62,6 +61,11 @@ public class MailController {
props.put("additionalInfo", "To make sure that you send an attachment with this email, change the value for the 'attachment.invoice' in the application.properties file to the path to the attachment.");
labels.put("sendAttachment", props);
}

@RequestMapping(method = RequestMethod.GET)
public String showEmailsPage() {
return "emails";
}

@RequestMapping(value = {"/send", "/sendTemplate", "/sendAttachment"}, method = RequestMethod.GET)
public String createMail(Model model,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.baeldung.spring.web.dto;

import org.hibernate.validator.constraints.Email;
package com.baeldung.spring.domain;

import javax.validation.constraints.Email;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.stereotype.Component;

import java.io.File;

import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
import java.io.File;

/**
* Created by Olga on 7/15/2016.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#this property file will have to be loaded explicitly as this is not a Spring Boot project

# Gmail SMTP
spring.mail.host=smtp.gmail.com
spring.mail.port=587
Expand Down