Skip to content

Instantly share code, notes, and snippets.

View sintongPanjaitan's full-sized avatar

sintong panjaitan sintongPanjaitan

View GitHub Profile
package id.medium.spring.mail.service;
import id.medium.spring.mail.Mail.MailRequest;
import id.medium.spring.mail.Mail.MailResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.stereotype.Service;
package id.medium.spring.mail.Mail;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
package id.medium.spring.mail.Mail;
import lombok.Data;
@Data
public class MailRequest {
private String name;
private String to;
private String from;
package id.medium.spring.mail.controller;
import id.medium.spring.mail.Mail.MailRequest;
import id.medium.spring.mail.Mail.MailResponse;
import id.medium.spring.mail.service.EmailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
spring:
mail:
default-encoding: UTF-8
host: smtp.gmail.com
username: email
password: password
port: 587
properties:
mail: