This question already has answers here:
Send mail to multiple recipients in Java
(12 answers)
Closed 5 years ago.
Below is the java program which send a mail through java mail api now the issue is that I want to enter multiple addresses into mailTo field. In the below code, you can see there is single entry for mailTo that is avdq#abc.com. However, I want to pass multiple entries as avdq#abc.com, tvdq#abc.com, and pvdq#abc.com. Please advise how to achieve this.
public class abcMailTest {
public static void main(String[] args) {
String mailSmtpHost = "77.77.77.77";
String mailSmtpPort = "4321" ;
String mailTo = "avdq#abc.com";
//String mailCc = "avdg#abc.com ";
String mailFrom = "avdg#abc.com";
String mailSubject = "sgdtetrtrr";
String mailText = "Test Mail for mail body ";
sendEmail(mailTo, mailFrom, mailSubject, mailText, mailSmtpHost ,mailSmtpPort );
}
public static void sendEmail(String to, String from, String subject, String text, String smtpHost , String mailSmtpPort) {
try {
Properties properties = new Properties();
properties.put("mail.smtp.host", smtpHost);
properties.put("mailSmtpPort", mailSmtpPort);
//obtaining the session
Session emailSession = Session.getDefaultInstance(properties);
emailSession.setDebug(true);
//creating the message
Message emailMessage = new MimeMessage(emailSession);
emailMessage.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
Address[] cc = new Address[] {
new InternetAddress("avdg#abc.com"),
new InternetAddress("sWER#gmail.com")};
emailMessage.addRecipients(Message.RecipientType.CC, cc);
emailMessage.setFrom(new InternetAddress(from));
emailMessage.setSubject(subject);
// Create the message part
BodyPart messageBodyPart = new MimeBodyPart();
messageBodyPart.setContent(text, "text/html");
messageBodyPart.setText(text);
// Create a multipart message
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(messageBodyPart);
// Part two is attachment
MimeBodyPart attachPart = new MimeBodyPart();
String filename = "c:\\abc.pdf";
DataSource source = new FileDataSource(filename);
attachPart.setDataHandler(new DataHandler(source));
attachPart.setFileName(filename);
multipart.addBodyPart(attachPart);
// Send the complete message parts
emailMessage.setContent(multipart);
emailSession.setDebug(true);
Transport.send(emailMessage);
} catch (AddressException e) {
e.printStackTrace();
} catch (MessagingException e) {
e.printStackTrace();
}
}
}
You just need to do the same thing as what you did for cc field
Address[] to = new Address[] {InternetAddress.parse("avdq#abc.com"),
InternetAddress.parse("tvdq#abc.com"),
InternetAddress.parse("pvdq#abc.com")};
message.addRecipients(Message.RecipientType.TO, to);
Try this
String cc = "avdg#abc.com;sWER#gmail.com";
StringTokenizer st = new StringTokenizer(cc,":");
while(st.hasMoreTokens()) {
emailMessage.addRecipients(Message.RecipientType.CC, InternetAddress.parse(st.nextToken(),false);
}
Related
I have the below java program which I am executing from eclipse under windows and it is working perfectly. Now I want to create a jar of it which I can make it from eclipse it self by creating a jar option now p, as I want to execute the same program from unix box machine in which java is installed please advise how I will test this same program from unix box machine in which java is installed and jdk is set, shall I go for jar creation process.
public class SSendEmail {
MimeMessage mimeMessage = null;
public static void main(String[] args) throws Exception, IOException, Exception {
String smtpHost = "11.1620.90.520";
String mailSmtpPort = "192381";
String mailTo[] = {"ena#rdbs.com"};
String mailCc[] = {"sena#rdbs.com"};
postEmailForBrokerageNotification(mailTo, mailCc, "k",
"testSubject", "Body123", smtpHost, mailSmtpPort);
}
//Send email for broker post pay email notification
public static void postEmailForBrokerageNotification(String mailTo[], String mailCc[], String from, String subject, String text, String smtpHost, String mailSmtpPort) throws Exception, DocumentException, IOException {
try {
Properties properties = new Properties();
properties.put("mail.smtp.host", smtpHost);
properties.put("mail.store.protocol", "imaps");
properties.put("mail.smtp.port", mailSmtpPort);
properties.put("mail.smtp.auth", "false");
//obtaining the session
Session emailSession = Session.getDefaultInstance(properties);
//Enable for debuging
emailSession.setDebug(true);
Message emailMessage = new MimeMessage(emailSession);
if (mailTo != null) {
InternetAddress[] addressTo = new InternetAddress[mailTo.length];
for (int i = 0; i < mailTo.length; i++) {
addressTo[i] = new InternetAddress(mailTo[i]);
}
emailMessage.setRecipients(RecipientType.TO, addressTo);
}
InternetAddress[] addresscc = new InternetAddress[mailCc.length];
for (int i = 0; i < mailCc.length; i++) {
addresscc[i] = new InternetAddress(mailCc[i]);
}
emailMessage.setRecipients(RecipientType.CC, addresscc);
emailMessage.setFrom(new InternetAddress(from));
emailMessage.setSubject(subject);
emailMessage.setContent(text, "text/html");
//Create the message part
BodyPart messageBodyPart = new MimeBodyPart();
messageBodyPart.setContent(text, "text/html");
messageBodyPart.setText(text);
// Create a multipart message
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(messageBodyPart);
// attachment part
MimeBodyPart attachPart = new MimeBodyPart();
String filename = "c:\\sd-Spec_for_Data-Mapping_P3--SARALE_RETURNswap.xls";
DataSource source = new FileDataSource(filename);
attachPart.setDataHandler(new DataHandler(source));
attachPart.setFileName(filename);
multipart.addBodyPart(attachPart);
// Send the complete message parts
emailMessage.setContent(multipart);
Transport.send(emailMessage);
} catch (AddressException e) {
e.printStackTrace();
} catch (MessagingException messagingException) {
messagingException.printStackTrace();
throw new Exception(messagingException.getMessage());
}
}
}
I am trying to send an HTML email in the body of an email along with few file attachments as well. I came up with below code:
public void sendEmail(final String to, final String from, final String cc, final String subject, final String body,
final String baseDirectory, final List<String> listOfFileNames) {
for (int i = 1; i <= 3; i++) { // retrying
try {
Session session = Session.getInstance(mailProperties, null);
Multipart multipart = new MimeMultipart();
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
InternetAddress[] toAddress = InternetAddress.parse(to);
InternetAddress[] ccAddress = InternetAddress.parse(cc);
message.addRecipients(RecipientType.TO, toAddress);
message.addRecipients(RecipientType.CC, ccAddress);
message.setSubject(subject);
message.setContent(body, "text/html;charset=utf8");
for (String file : listOfFileNames) {
String fileLocation = baseDirectory + "/" + file;
addAttachment(multipart, fileLocation);
}
message.setContent(multipart);
Transport.send(message, toAddress);
break;
} catch (Exception ex) {
// log exception
}
}
}
// this is used for attachment
private void addAttachment(final Multipart multipart, final String filename) throws MessagingException {
DataSource source = new FileDataSource(filename);
BodyPart messageBodyPart = new MimeBodyPart();
messageBodyPart.setDataHandler(new DataHandler(source));
messageBodyPart.setFileName(filename);
multipart.addBodyPart(messageBodyPart);
}
I need to have body String as part of my HTML email and have all the files attach in the same email. I am running like this as in my home directory, I have two files: abc.csv and tree.txt.
EmailTest.getInstance().sendEmail("hello#host.com", "hello#host.com", "hello#host.com",
"Test Subject (" + dateFormat.format(new Date()) + ")", content, "/export/home/david/",
Arrays.asList("abc.csv", "tree.txt"));
After I get an email, I don't see my text in the body of an email at all? And second thing is file attachment name is coming as /export/home/david/abc.csv and /export/home/david/tree.txt?
Is anything wrong I am doing? One thing I see wrong as I am calling setContent method twice with different parameters?
First you need to add the text as an own BodyPart. Next your MimeMultipart needs to be set to the type related so you can have both, HTML-Text and some attachements. Then it should work to have both, attachements and text.
And the filename you pass to messageBodyPart.setFileName(filename) is the filename you see in the attachment name. So just leave out the path and you should just see abc.csv and tree.txt
public void sendEmail(final String to, final String from, final String cc, final String subject, final String body,
final String baseDirectory, final List<String> listOfFileNames) {
for (int i = 1; i <= 3; i++) { // retrying
try {
Session session = Session.getInstance(mailProperties, null);
Multipart multipart = new MimeMultipart("related");
MimeBodyPart bodyPart= new MimeBodyPart();
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
InternetAddress[] toAddress = InternetAddress.parse(to);
InternetAddress[] ccAddress = InternetAddress.parse(cc);
message.addRecipients(RecipientType.TO, toAddress);
message.addRecipients(RecipientType.CC, ccAddress);
message.setSubject(subject);
bodyPart.setText(body, "UTF-8", "html");
multipart.addBodyPart(bodyPart);
for (String file : listOfFileNames) {
String fileLocation = baseDirectory + "/" + file;
addAttachment(multipart, fileLocation, file);
}
message.setContent(multipart);
Transport.send(message, toAddress);
break;
} catch (Exception ex) {
// log exception
}
}
}
// this is used for attachment
private void addAttachment(final Multipart multipart, final String filepath, final String filename) throws MessagingException {
DataSource source = new FileDataSource(filepath);
BodyPart messageBodyPart = new MimeBodyPart();
messageBodyPart.setDataHandler(new DataHandler(source));
messageBodyPart.setFileName(filename);
multipart.addBodyPart(messageBodyPart);
}
I have developed a java mail api program which will send the mail and it also attaches the pdf file , so finally a mail is delivered in which pdf file is attached .
now can you please advise i want to make that pdf file as password protected through my java program itself for example i want to modify my below program such as that for opening an pdf file password 1234 is created and whenever an mail is sent the client should open the pdf file but before opening he should enter 1234 in the pop up box of pdf file to see it , can you please advise how can i achieve this in java program itself please. Thanks in advance below is my java program
public class BrokMailTest {
public static void main(String[] args) {
String mailSmtpHost = "77.77.77.77";
String mailSmtpPort = "4321" ;
String mailTo = "avdg#abc.com";
//String mailCc = "avdg#abc.com ";
String mailFrom = "avdg#abc.com";
String mailSubject = "*****%%%%%%%%*********Email POC Brokerage for Rel 14.0****%%%%%%%%********";
String mailText = "Test Mail for Brokerage POC";
sendEmail(mailTo, mailFrom, mailSubject, mailText, mailSmtpHost ,mailSmtpPort );
}
public static void sendEmail(String to, String from, String subject, String text, String smtpHost , String mailSmtpPort) {
try {
Properties properties = new Properties();
properties.put("mail.smtp.host", smtpHost);
properties.put("mailSmtpPort", mailSmtpPort);
//obtaining the session
Session emailSession = Session.getDefaultInstance(properties);
Message emailMessage = new MimeMessage(emailSession);
emailMessage.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
//emailMessage.addRecipients(Message.RecipientType.CC, InternetAddress.parse("avdg#abc.com"));
Address[] cc = new Address[] {
new InternetAddress("avdg#abc.com"),
new InternetAddress("saxenasaral#gmail.com")};
emailMessage.addRecipients(Message.RecipientType.CC, cc);
emailMessage.setFrom(new InternetAddress(from));
emailMessage.setSubject(subject);
//emailMessage.setContent(text, "text/html");
// Create the message part
BodyPart messageBodyPart = new MimeBodyPart();
messageBodyPart.setContent(text, "text/html");
messageBodyPart.setText(text);
// Now set the actual message
messageBodyPart.setText("This is message body");
//emailMessage.setContent(emailMessage, "text/html");
//emailMessage.setText(text);
// Create a multipart message
Multipart multipart = new MimeMultipart();
// Part two is attachment
messageBodyPart = new MimeBodyPart();
String filename = "c:\\SettingupRulesin outlook2003.pdf";
DataSource source = new FileDataSource(filename);
messageBodyPart.setDataHandler(new DataHandler(source));
messageBodyPart.setFileName(filename);
// Send the complete message parts
emailMessage.setContent(multipart);
emailSession.setDebug(true);
// Set text message part
multipart.addBodyPart(messageBodyPart);
Transport.send(emailMessage);
} catch (AddressException e) {
e.printStackTrace();
} catch (MessagingException e) {
e.printStackTrace();
}
}
}
Taken from the tutorial: http://itextpdf.com/examples/iia.php?id=219
public static byte[] USER = "password 1234".getBytes();
public static byte[] OWNER = "password 1234".getBytes();
public void encryptPdf(String filename, String filename) throws IOException, DocumentException {
PdfReader reader = new PdfReader(filename);
PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(fileName));
stamper.setEncryption(USER, OWNER,
PdfWriter.ALLOW_PRINTING, PdfWriter.ENCRYPTION_AES_128 | PdfWriter.DO_NOT_ENCRYPT_METADATA);
stamper.close();
reader.close();
}
Add encryptPdf(fileName, fileName); after the file string has been declared.
Edit: Used byte[] objects for password names. The usage of strings have been deprecated from this version of iText for encryption purposes.
I'm trying to send an email with an attachment. The whole thing works fine, except for the part that the attachment sent sends the attached file with no extension.
For example, sending File.rar will receive file
This is how I'm doing it:
public class EmailSender {
public static void main(String[] args) {
String TO = "Receiver#yahoo.com";
String host = "smtp.gmail.com";
String port = "465";
String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";
Properties mailConfig = new Properties();
mailConfig.put("mail.smtp.host", host);
mailConfig.put("mail.smtp.socketFactory.port", port);
mailConfig.put("mail.smtp.socketFactory.class", SSL_FACTORY);
mailConfig.put("mail.smtp.auth", "true");
mailConfig.put("mail.smtp.port", port);
Session session = Session.getDefaultInstance(mailConfig,
new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("Username", "Password");
}
});
try {
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress("from#gmail.com"));
message.addRecipient(Message.RecipientType.TO, new InternetAddress(TO));
message.setSubject("Email with Attachment SUBJECT");
BodyPart messageBodyTxt = new MimeBodyPart();
messageBodyTxt.setText("Email with Attachment BODY");
MimeBodyPart messageBodyAttachment = new MimeBodyPart();
String filePath = "D:\\Unlocker1.9.2.rar";
DataSource source = new FileDataSource(filePath);
messageBodyAttachment.setDataHandler(new DataHandler(source));
messageBodyAttachment.setFileName("Unlocker1.9.2" + ".rar");
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(messageBodyTxt);
multipart.addBodyPart(messageBodyAttachment);
message.setContent(multipart);
Transport.send(message);
System.out.println("Email sent successfully");
} catch (MessagingException e) {
throw new RuntimeException(e);
}
}
}
Using the advice from the comment, the proper method would be setDisposition and you would set it for the MimeBodyPart in question. Therefore, with the code above, one would do:
messageBodyAttachment.setDisposition(javax.mail.Part.ATTACHMENT);
Does anyone have an example of sending an email, with an attachment, via Amazon SES (in Java)?
Maybe a little bit late, but you can use this code (you also need Java Mail):
public class MailSender
{
private Transport AWSTransport;
...
//Initialize transport
private void initAWSTransport() throws MessagingException
{
String keyID = <your key id>
String secretKey = <your secret key>
MailAWSCredentials credentials = new MailAWSCredentials();
credentials.setCredentials(keyID, secretKey);
AmazonSimpleEmailService ses = new AmazonSimpleEmailServiceClient(credentials);
Properties props = new Properties();
props.setProperty("mail.transport.protocol", "aws");
props.setProperty("mail.aws.user", credentials.getAWSAccessKeyId());
props.setProperty("mail.aws.password", credentials.getAWSSecretKey());
AWSsession = Session.getInstance(props);
AWStransport = new AWSJavaMailTransport(AWSsession, null);
AWStransport.connect();
}
public void sendEmail(byte[] attachment)
{
//mail properties
String senderAddress = <Sender address>;
String recipientAddress = <Recipient address>;
String subject = <Mail subject>;
String text = <Your text>;
String mimeTypeOfText = <MIME type of text part>;
String fileMimeType = <MIME type of your attachment>;
String fileName = <Name of attached file>;
initAWSTransport();
try
{
// Create new message
Message msg = new MimeMessage(AWSsession);
msg.setFrom(new InternetAddress(senderAddress));
msg.addRecipient(Message.RecipientType.TO, new InternetAddress(recipientAddress));
msg.setSubject(subject);
//Text part
Multipart multipart = new MimeMultipart();
BodyPart messageBodyPart = new MimeBodyPart();
messageBodyPart.setContent(text, mimeTypeOfText);
multipart.addBodyPart(messageBodyPart);
//Attachment part
if (attachment != null && attachment.length != 0)
{
messageBodyPart = new MimeBodyPart();
DataSource source = new ByteArrayDataSource(attachment,fileMimeType);
messageBodyPart.setDataHandler(new DataHandler(source));
messageBodyPart.setFileName(fileName);
multipart.addBodyPart(messageBodyPart);
}
msg.setContent(multipart);
//send message
msg.saveChanges();
AWSTransport.sendMessage(msg, null);
} catch (MessagingException e){...}
}
}
Maybe a little bit late too.
Alternative to send mail using Java Mail and Amazon Raw Mail Sender
public static void sendMail(String subject, String message, byte[] attachement, String fileName, String contentType, String from, String[] to) {
try {
// JavaMail representation of the message
Session s = Session.getInstance(new Properties(), null);
MimeMessage mimeMessage = new MimeMessage(s);
// Sender and recipient
mimeMessage.setFrom(new InternetAddress(from));
for (String toMail : to) {
mimeMessage.addRecipient(javax.mail.Message.RecipientType.TO, new InternetAddress(toMail));
}
// Subject
mimeMessage.setSubject(subject);
// Add a MIME part to the message
MimeMultipart mimeBodyPart = new MimeMultipart();
BodyPart part = new MimeBodyPart();
part.setContent(message, MediaType.TEXT_HTML);
mimeBodyPart.addBodyPart(part);
// Add a attachement to the message
part = new MimeBodyPart();
DataSource source = new ByteArrayDataSource(attachement, contentType);
part.setDataHandler(new DataHandler(source));
part.setFileName(fileName);
mimeBodyPart.addBodyPart(part);
mimeMessage.setContent(mimeBodyPart);
// Create Raw message
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
mimeMessage.writeTo(outputStream);
RawMessage rawMessage = new RawMessage(ByteBuffer.wrap(outputStream.toByteArray()));
// Credentials
String keyID = "";// <your key id>
String secretKey = "";// <your secret key>
AWSCredentials credentials = new BasicAWSCredentials(keyID, secretKey);
AmazonSimpleEmailServiceClient client = new AmazonSimpleEmailServiceClient(credentials);
// Send Mail
SendRawEmailRequest rawEmailRequest = new SendRawEmailRequest(rawMessage);
rawEmailRequest.setDestinations(Arrays.asList(to));
rawEmailRequest.setSource(from);
client.sendRawEmail(rawEmailRequest);
} catch (IOException | MessagingException e) {
// your Exception
e.printStackTrace();
}
}
https://docs.aws.amazon.com/ses/latest/DeveloperGuide/send-email-raw.html has an example that sends both html and text bodies (with an attachment, of course). FWIW, here is the conversion and reorganization of its Java code to Kotlin. The dependency is 'com.sun.mail:javax.mail:1.6.2'.
data class Attachment(val fileName: String, val contentType: String, val data: ByteArray)
fun sendEmailWithAttachment(from: String, to: List<String>, subject: String, htmlBody: String, textBody: String,
attachment: Attachment) {
try {
val textPart = MimeBodyPart().apply {
setContent(textBody, "text/plain; charset=UTF-8")
}
val htmlPart = MimeBodyPart().apply {
setContent(htmlBody, "text/html; charset=UTF-8")
}
// Create a multipart/alternative child container.
val childPart = MimeMultipart("alternative").apply {
// Add the text and HTML parts to the child container.
addBodyPart(textPart)
addBodyPart(htmlPart)
}
// Create a wrapper for the HTML and text parts.
val childWrapper = MimeBodyPart().apply {
setContent(childPart)
}
// Define the attachment
val dataSource = ByteArrayDataSource(attachment.data, attachment.contentType)
// val dataSource = FileDataSource(filePath) // if using file directly
val attPart = MimeBodyPart().apply {
dataHandler = DataHandler(dataSource)
fileName = attachment.fileName
}
// Create a multipart/mixed parent container.
val parentPart = MimeMultipart("mixed").apply {
// Add the multipart/alternative part to the message.
addBodyPart(childWrapper)
addBodyPart(attPart) // Add the attachment to the message.
}
// JavaMail representation of the message
val s = Session.getDefaultInstance(Properties())
val mimeMessage = MimeMessage(s).apply {
// Add subject, from and to lines
this.subject = subject
setFrom(InternetAddress(from))
to.forEach() {
addRecipient(javax.mail.Message.RecipientType.TO, InternetAddress(it))
}
// Add the parent container to the message.
setContent(parentPart)
}
// Create Raw message
val rawMessage = with(ByteArrayOutputStream()) {
mimeMessage.writeTo(this)
RawMessage(ByteBuffer.wrap(this.toByteArray()))
}
val rawEmailRequest = SendRawEmailRequest(rawMessage).apply {
source = from
setDestinations(to)
}
// Send Mail
val client = AmazonSimpleEmailServiceClientBuilder.standard()
.withRegion(Regions.US_EAST_1).build()
client.sendRawEmail(rawEmailRequest)
println("Email with attachment sent to $to")
} catch (e: Exception) {
println(e)
}
}
Here is an updated, cleaned up version with logging and check for production.
public void sendEmail(String to, String subject, String body, String attachment, String mimeType, String fileName) {
if (to == null) return;
String environment = System.getProperty("ENVIRONMENT", System.getenv("ENVIRONMENT"));
String logMessage;
if (environment != null && environment.equals("production")) {
logMessage = "Sent email to " + to + ".";
} else {
to = "success#simulator.amazonses.com";
logMessage = "Email sent to success#simulator.amazonses.com because $ENVIRONMENT != 'production'";
}
// https://docs.aws.amazon.com/ses/latest/DeveloperGuide/examples-send-raw-using-sdk.html
Session session = Session.getDefaultInstance(new Properties());
MimeMessage message = new MimeMessage(session);
try {
message.setSubject(subject, "UTF-8");
message.setFrom(new InternetAddress(FROM));
message.setRecipients(javax.mail.Message.RecipientType.TO, InternetAddress.parse(to));
MimeMultipart msg = new MimeMultipart("mixed");
MimeBodyPart wrap = new MimeBodyPart();
MimeMultipart msgBody = new MimeMultipart("alternative");
MimeBodyPart textPart = new MimeBodyPart();
MimeBodyPart htmlPart = new MimeBodyPart();
textPart.setContent(body, "text/plain; charset=UTF-8");
htmlPart.setContent(body,"text/html; charset=UTF-8");
msgBody.addBodyPart(textPart);
msgBody.addBodyPart(htmlPart);
wrap.setContent(msgBody);
msg.addBodyPart(wrap);
MimeBodyPart att = new MimeBodyPart();
att.setDataHandler(new DataHandler(attachment, mimeType));
att.setFileName(fileName);
// DataSource fds = new FileDataSource(attachment);
// att.setDataHandler(new DataHandler(fds));
// att.setFileName(fds.getName());
msg.addBodyPart(att);
message.setContent(msg);
AmazonSimpleEmailService client = AmazonSimpleEmailServiceClientBuilder
.standard().withRegion(Regions.US_EAST_1).build();
message.writeTo(System.out);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
message.writeTo(outputStream);
RawMessage rawMessage = new RawMessage(ByteBuffer.wrap(outputStream.toByteArray()));
SendRawEmailRequest rawEmailRequest = new SendRawEmailRequest(rawMessage);
// .withConfigurationSetName(CONFIGURATION_SET);
client.sendRawEmail(rawEmailRequest);
Logger.info(this.getClass(), "sendEmail()", logMessage);
} catch (Exception ex) {
Logger.info(this.getClass(), "sendEmail()", "The email was not sent. Error: " + ex.getMessage());
}
}
https://docs.aws.amazon.com/ses/latest/DeveloperGuide/examples-send-raw-using-sdk.html
You use a shared credentials file to pass your AWS access key ID and secret access key. As an alternative to using a shared credentials file, you can specify your AWS access key ID and secret access key by setting two environment variables (AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY, respectively).