Email Adapter Support
Email Adapter Support
*;
import java.sql.*;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.zip.*;
import javax.mail.*;
import javax.mail.internet.*;
if (functionality.equals("queries")) {
sendQueriesAsCsvAttachment(connection, sender, recipients, subject, smtpHost,
smtpPort);
} else if (functionality.equals("zip")) {
zipFilesAndSendAsAttachment(connection, sender, recipients, subject, smtpHost,
smtpPort, date);
} else {
System.out.println("Invalid functionality.");
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
if (connection != null) {
try {
connection.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
// Create session
Session session = Session.getDefaultInstance(properties);
try {
// Create MimeMessage
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(sender));
message.setSubject(subject);
// Set recipients
String[] recipientList = recipients.split(",");
for (String recipient : recipientList) {
message.addRecipient(Message.RecipientType.TO, new
InternetAddress(recipient.trim()));
}
// Create Multipart
Multipart multipart = new MimeMultipart();
// Attach file
MimeBodyPart attachmentPart = new MimeBodyPart();
attachmentPart.attachFile(new File(attachmentFileName));
multipart.addBodyPart(attachmentPart);
// Set content
message.setContent(multipart);
// Send message
Transport.send(message);
System.out.println("Email sent successfully.");
} catch (MessagingException | IOException e) {
e.printStackTrace();
}
}
}