SMTP (Simple Mail Transfer Protocol):
주로 이메일 발송에 사용됩니다.
클라이언트에서 메일 서버로, 메일 서버에서 다른 메일 서버로 이메일을 전송합니다.
IMAP (Internet Message Access Protocol):
이메일을 서버에 저장하고 클라이언트에서 이를 접근 및 관리하는 데 사용됩니다.
이메일을 서버에 남겨두고 여러 기기에서 동기화하여 확인할 수 있습니다.
POP3 (Post Office Protocol version 3):
이메일을 서버에서 클라이언트로 가져오고, 서버에서 이메일을 삭제합니다.
이메일을 하나의 기기에서 관리할 때 주로 사용됩니다.
MIME (Multipurpose Internet Mail Extensions):
이메일 본문에 여러 종류의 콘텐츠(텍스트, 이미지, 비디오 등)를 포함할 수 있도록 확장합니다.
Exchange ActiveSync:
Microsoft Exchange 서버와 클라이언트 간의 이메일, 캘린더, 연락처 동기화를 위해 사용됩니다.
WebDAV:
웹 기반의 분산 저작 프로토콜로, 서버에 저장된 데이터를 관리하고 동기화합니다.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
plugins {
id 'org.springframework.boot' version '2.7.5'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '17'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-mail'
imple

mentation 'org.springframework.boot:spring-boot-starter-web'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
test {
useJUnitPlatform()
}
spring.mail.host=smtp.example.com
spring.mail.port=587
spring.mail.username=your-email@example.com
spring.mail.password=your-password
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;
@Service
public class EmailService {
@Autowired
private JavaMailSender mailSender;
public void sendSimpleEmail(String to, String subject, String body) {
SimpleMailMessage message = new SimpleMailMessage();
message.setTo(to);
message.setSubject(subject);
message.setText(body);
message.setFrom("your-email@example.com");
mailSender.send(message);
}
}
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/email")
public class EmailController {
@Autowired
private EmailService emailService;
@PostMapping("/send")
public String sendEmail(@RequestParam String to,
@RequestParam String subject,
@RequestParam String body) {
emailService.sendSimpleEmail(to, subject, body);
return "Email sent successfully!";
}
}