-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from RamonMR95/feature/37
37- EmailController.
- Loading branch information
Showing
3 changed files
with
81 additions
and
1 deletion.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
src/main/java/com/ramonmr95/tiky/olc/controllers/EmailController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.ramonmr95.tiky.olc.controllers; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.core.env.Environment; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import com.ramonmr95.tiky.olc.entities.ContactMessage; | ||
import com.ramonmr95.tiky.olc.services.EmailService; | ||
|
||
@RestController | ||
@RequestMapping("/api/email") | ||
public class EmailController { | ||
|
||
@Autowired | ||
private EmailService emailService; | ||
|
||
@Autowired | ||
private Environment env; | ||
|
||
@PostMapping("/contact-us") | ||
public ResponseEntity<?> contactUs(@RequestBody ContactMessage contactMessage) { | ||
this.emailService.sendEmail(env.getProperty("spring.mail.username"), contactMessage.getSubject(), "Name: " | ||
+ contactMessage.getName() + ", email: " + contactMessage.getEmail() + "\n" + contactMessage.getBody()); | ||
return new ResponseEntity<>(HttpStatus.OK); | ||
} | ||
|
||
} |
46 changes: 46 additions & 0 deletions
46
src/main/java/com/ramonmr95/tiky/olc/entities/ContactMessage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.ramonmr95.tiky.olc.entities; | ||
|
||
import java.io.Serializable; | ||
|
||
public class ContactMessage implements Serializable { | ||
|
||
private static final long serialVersionUID = -1595672012284907193L; | ||
|
||
private String subject; | ||
private String body; | ||
private String name; | ||
private String email; | ||
|
||
public String getSubject() { | ||
return subject; | ||
} | ||
|
||
public void setSubject(String subject) { | ||
this.subject = subject; | ||
} | ||
|
||
public String getBody() { | ||
return body; | ||
} | ||
|
||
public void setBody(String body) { | ||
this.body = body; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public String getEmail() { | ||
return email; | ||
} | ||
|
||
public void setEmail(String email) { | ||
this.email = email; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters