๋ค์ด๋ฒ ์์๋ฐ์ด๋ ๋ฉ์ผ๋ฌ๋ฅผ ์ฌ์ฉํ ์ผ์ด ์์ด
JAVA ๊ตฌํ ์์๋ฅผ ์ฐพ๋ค๊ฐ ๋ค์์ ๋ฐ๊ฒฌํ์๋ค.
[Java] Naver Cloud Platform _ Cloud Outbound Mailer ์ฌ์ฉํ๊ธฐ
์ด๋ฒ์๋ ๋ค์ด๋ฒ Cloud Outbound Mailer๋ฅผ ์๋ฐ๋ก ๊ฐ๋ฐ ํด๋ณด๊ฒ ๋ค. ๊ตฌ๊ธ๋ง์ ํด๋ณด๋ฉด ๋ค์ด๋ฒ์์ ์ ๊ณตํ๋ gitHub์ ํ์ด์ฌ์ ์ฌ์ฉํ ๋ฒ์ https://github.com/NaverCloudPlatform/outbound_mailer_python_sample So..
yoshinari.tistory.com
์ ๊ฒ์๊ธ์ ์ฐธ๊ณ ํ์ฌ ์งํํ๋ค.
๋ค์ด๋ฒ API ๊ฐ์ด๋์์ SDK๋ฅผ ๋ค์ด๋ฐ๋๋ค.
docs.gov-ncloud.com/ko/email/email-1-3.html
์ค๋ช ์
๋ค์ด๋ฒ ํด๋ผ์ฐ๋ ํ๋ซํผ[๊ณต๊ณต๊ธฐ๊ด์ฉ]์ ์ํ ์ฌ์ฉ ๋ฐฉ๋ฒ์ ๋ณด๋ค ์์ธํ๊ฒ ์ ๊ณตํ๊ณ , ๋ค์ํ API์ ํ์ฉ์ ๋๊ธฐ ์ํด [์ค๋ช ์]์ [API ์ฐธ์กฐ์]๋ฅผ ๊ตฌ๋ถํ์ฌ ์ ๊ณตํ๊ณ ์์ต๋๋ค. Cloud Outbound Mailer API ๊ฐ
docs.gov-ncloud.com
๋ค์ด ๋ฐ์ ์์ค ๋ด
nes-client-1.6.0G.jar ๋ฅผ ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ ์ถ๊ฐํ๊ณ
generated-code\src\main\java\com ์ ์๋ nbp ์์ค ์ ์ฒด๋ฅผ ํ๋ก์ ํธ์ ์ถ๊ฐํ๋ค.
์ดํ ์๋ ๋ชฉ๋ก์ jar ํ์ผ๋ค์ ์ ๋ถ ๋ค์ด๋ฐ๊ฑฐ๋ pom ์ ์ถ๊ฐํ์ฌ ํ๋ก์ ํธ๋ก ๊ฐ์ ธ์จ๋ค.
<!-- https://mvnrepository.com/artifact/commons-codec/commons-codec -->
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.11</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.7</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-annotations -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.9.3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.dataformat/jackson-dataformat-xml -->
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
<version>2.9.3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.googlecode.json-simple/json-simple -->
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.squareup.okhttp3/logging-interceptor -->
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>logging-interceptor</artifactId>
<version>3.9.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.squareup.okhttp3/okhttp -->
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>3.9.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.squareup.okio/okio -->
<dependency>
<groupId>com.squareup.okio</groupId>
<artifactId>okio</artifactId>
<version>2.2.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.jetbrains.kotlin/kotlin-runtime -->
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-runtime</artifactId>
<version>1.1.1</version>
</dependency>
์ดํ, ์์ค ๋ด์ ์๋ credentials.properties ์ ๋ฐ๊ธ๋ฐ์ API ํค์ Secret ํค๋ฅผ ์์ฑ ํ, ํ๋ก์ ํธ์ ์ถ๊ฐํ๋ค.
๊ทธ ํ, ์๋์ ์ฝ๋๋ฅผ ๋ฃ๊ณ ์คํํ๋ฉด ๋๋ค.
ํ๋กํผํฐ ๊ฒฝ๋ก๋ ์ค์ ํ๋ก์ ํธ์ ์กด์ฌํ๋ ๊ฒฝ๋ก๋ฅผ ์ฝ์ ํ๋ฉด๋๋ค.
์๋๋ ์ค์ ์์ ๋์ ์, ๋์ํ๋ ์ฝ๋์ด๋ค.
public static void createMailRequest() {
String propertiesLocation = "{properties ํ์ผ ์์น}"
ApiClient apiClient = new ApiClient.ApiClientBuilder()
.addMarshaller(JsonMarshaller.getInstance())
.addMarshaller(XmlMarshaller.getInstance())
.addMarshaller(FormMarshaller.getInstance())
.setCredentials(new PropertiesFileCredentialsProvider(propertiesLocation)
.getCredentials()).setLogging(true).build();
// API ๊ฐ์ฒด ์์ฑ
V1Api apiInstance = new V1Api(apiClient);
// ๋ฉ์ผ ์์ ์ ๋ฆฌ์คํธ ์์ฑ.
List<EmailSendRequestRecipients> esrrList = new ArrayList<EmailSendRequestRecipients>();
// ์์ ์ ๋ฆฌ์คํธ ์ค์
EmailSendRequestRecipients esrr = new EmailSendRequestRecipients();
esrr.setAddress("์์ ์์ด๋ฉ์ผ");
esrr.setName("์์ ์์ด๋ฆ");
esrr.setType("R"); // ํ์
๊ณ ์ : R ( ์ผ๋ฐ ์์ ์ )
esrrList.add(esrr);
EmailSendRequest requestBody = new EmailSendRequest();
// ๋ฉ์ผ ๋ณธ๋ฌธ ์์ฑ
String body = "{๋ฉ์ผ ๋ด์ฉ, html ์ฝ๋ ๋ฐ ๋ด์ฉ ๋ฑ}"
// ์์ฒญ์ ๋ณธ๋ฌธ ๋ฐ ์์ ์ ๋ฆฌ์คํธ ์ค์
requestBody.setBody(body);
requestBody.setRecipients(esrrList);
// requestBody.setTemplateSid({templateID}); ํ
ํ๋ฆฟ ์์ด๋ ์ถ๊ฐ.
// ๋ฐ์ ์ ์ ๋ณด ์ค์
requestBody.setSenderAddress("๋ฐ์ ์์ด๋ฉ์ผ");
requestBody.setSenderName("๋ฐ์ ์๋ช
");
// ๋ฉ์ผ ์ ๋ชฉ ์ค์
requestBody.setTitle(title);
// ์ ์ก ํ์ธ ๊ธฐ๋ฅ ์ค์
requestBody.setConfirmAndSend(false);
// ์ ๋ฌ ์ธ์ด ์ค์
String X_NCP_LANG = "ko-KR"; // String | ์ธ์ด (ko-KR, en-US, zh-CN), default:en-US
try {
// Handler Successful response
ApiResponse<EmailSendResponse> res = apiInstance.mailsPost(requestBody, X_NCP_LANG);
} catch (ApiException e) {
// Handler Failed response
int statusCode = e.getHttpStatusCode();
Map<String, List<String>> responseHeaders = e.getHttpHeaders();
InputStream byteStream = e.getByteStream();
e.printStackTrace();
} catch (SdkException e) {
// Handle exceptions that occurred before communication with the server
e.printStackTrace();
}
}
'๐Java' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
Dto ์ฌ์ฉ์ ๊ดํ ์๊ฐ (0) | 2022.05.29 |
---|---|
java POI Excel ํ์ฌ ์ปฌ๋ผ(์ด)์ ์ ์คํ์ผ ์ ์ฒด ์ ์ฉํ๊ธฐ (0) | 2022.05.19 |
User-Agent ๋ก ์ ์ํ ์ฌ์ฉ์ ๋ธ๋ผ์ฐ์ ์ฒดํฌํ๊ธฐ (0) | 2021.05.03 |
ํ์ฌ์๊ฐ ๊ตฌํ๊ธฐ (0) | 2021.04.30 |
YouTube ๊ฒ์ ๋ฐ์ดํฐ ๊ฐ์ ธ์ค๊ธฐ - YouTube Data Api ์ฐ๋ (0) | 2021.02.28 |
๋๊ธ