앱)AWS SES Email Util java spring 예제 샘플
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-ses</artifactId>
<version>1.11.0</version>
</dependency>
@Service
public class AWSEmail{
@Value("${ses.accessKey}")
private String accessKey;
@Value("${ses.secretKey}")
private String secretKey;
@Value("${ses.region}")
private String region;
public String sendMail(String fromEmail, List<String> toAddress, String subject, String emailBody) throws AmazonClientException, Exception {
String resultMsg = "";
SendEmailRequest request = new SendEmailRequest().withSource(fromEmail);
Destination dest = new Destination().withToAddress(toAddress);
request.setDestination(dest);
Content subjContent = new Content().withData(subject);
Message msg = new Message().withSubject(subjContent);
//Include a body in HTML formats.
Content htmlContent = new Content().withData(emailBody);
Body body = new Body.withHtml(htmlContent);
msg.setBody(body);
request.setMessage(msg);
//Set AWS access credentials
String tmpAccessKey = "";
String tmpSecretKey ="";
if("Local".equals(System.getProperty("server.type"))){
tmpAccessKey = accessKey;
tmpSecretKey = secretKey;
} else {
try{
tmpAccessKey = AESCipherUtil.decrypt(accessKey);
tmpSecretKey = AESCipherUtil.decrypt(secretKey);
}catch(Exception e){
sysout("Credential decryption failed !");
}
}
AWSCredentilas credentilas = new BasicAWSCredentials(tmpAcessKey, tmpSecretKey);
AmazonSimpleEmailServiceClient client = null;
if("Local".equals(System.getProperty("server.type"))){
ClientConfiguration clientCfg = new ClientConfiguration();
clientCfg.setProtocol(Protocol.HTTP);
clientCfg.setProxyHost("XXX.XXX.XXX.XXX");
clientCfg.setProxyPort(8080);
client = new AmazonSimpleEmailServiceClient(credentials, clientCfg);
} else{
client = new AmazonSimpleEmailServiceClient(credentials);
}
Region regionCode = null;
switch(region){
case "EU_WEST_1":
regionCode = Region.getRegion(Region.EU_WEST_1);
break;
case "AP_NORTHEAST_1":
regionCode = Region.getRegion(Region.AP_NORTHEAST_1);
break;
}
client.setRegion(regionCode);
//Call Amazon SES to send the message
SendEmailResult rs = client.sendEmail(request);
resultMsg = rs.toString();
return resultMsg;
}
}
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-ses</artifactId>
<version>1.11.0</version>
</dependency>
@Service
public class AWSEmail{
@Value("${ses.accessKey}")
private String accessKey;
@Value("${ses.secretKey}")
private String secretKey;
@Value("${ses.region}")
private String region;
public String sendMail(String fromEmail, List<String> toAddress, String subject, String emailBody) throws AmazonClientException, Exception {
String resultMsg = "";
SendEmailRequest request = new SendEmailRequest().withSource(fromEmail);
Destination dest = new Destination().withToAddress(toAddress);
request.setDestination(dest);
Content subjContent = new Content().withData(subject);
Message msg = new Message().withSubject(subjContent);
//Include a body in HTML formats.
Content htmlContent = new Content().withData(emailBody);
Body body = new Body.withHtml(htmlContent);
msg.setBody(body);
request.setMessage(msg);
//Set AWS access credentials
String tmpAccessKey = "";
String tmpSecretKey ="";
if("Local".equals(System.getProperty("server.type"))){
tmpAccessKey = accessKey;
tmpSecretKey = secretKey;
} else {
try{
tmpAccessKey = AESCipherUtil.decrypt(accessKey);
tmpSecretKey = AESCipherUtil.decrypt(secretKey);
}catch(Exception e){
sysout("Credential decryption failed !");
}
}
AWSCredentilas credentilas = new BasicAWSCredentials(tmpAcessKey, tmpSecretKey);
AmazonSimpleEmailServiceClient client = null;
if("Local".equals(System.getProperty("server.type"))){
ClientConfiguration clientCfg = new ClientConfiguration();
clientCfg.setProtocol(Protocol.HTTP);
clientCfg.setProxyHost("XXX.XXX.XXX.XXX");
clientCfg.setProxyPort(8080);
client = new AmazonSimpleEmailServiceClient(credentials, clientCfg);
} else{
client = new AmazonSimpleEmailServiceClient(credentials);
}
Region regionCode = null;
switch(region){
case "EU_WEST_1":
regionCode = Region.getRegion(Region.EU_WEST_1);
break;
case "AP_NORTHEAST_1":
regionCode = Region.getRegion(Region.AP_NORTHEAST_1);
break;
}
client.setRegion(regionCode);
//Call Amazon SES to send the message
SendEmailResult rs = client.sendEmail(request);
resultMsg = rs.toString();
return resultMsg;
}
}
'백엔드개발 > 자바스프링' 카테고리의 다른 글
앱)자바 멀티스레드 샘플 코드 (0) | 2018.07.09 |
---|---|
앱)JSP(JavaServer Pages)에 대해서 (0) | 2018.07.03 |
앱)jstl list search result table sample 예제 (0) | 2018.06.12 |
앱)jstl sample 예제 (0) | 2018.06.12 |
앱)java spring framework excel export jstl (0) | 2018.06.11 |