Spring/Java Mail:The sender is always the spring.mail.username. The FROM address is being ignored - spring-boot

I send mail using SimpleMailMessage. Everything is working nicely. But I don't know why on the receiver side shows spring.mail.username's address and not the From Adress.
Each mail sent to the right address but from the address mail which is created in property spring.mail.username
What method will use for this? Is there any method available in SimpleMailMessage Class?
resources/application.properties
spring.mail.host = smtp.gmail.com
spring.mail.port=587
spring.mail.username = ***#otherdomain
spring.mail.password = ***
spring.mail.properties.mail.smtp.auth = true
spring.mail.properties.mail.smtp.starttls.enable=true
Code
private JavaMailSender javaMailSender;
public EmailService(JavaMailSender javaMailSender) {
this.javaMailSender = javaMailSender;
}
public void sendMail(String fromEmail,String toEmail, String subject, String message) {
var mailMessage = new SimpleMailMessage();
mailMessage.setFrom(fromEmail);
mailMessage.setTo(toEmail);
mailMessage.setSubject(subject);
mailMessage.setText(message);
javaMailSender.send(mailMessage);
}

It's not possible to change FROM EMAIL address since it's hard coded: spring.mail.username = ***#otherdomain in resources/application.properties.
But you set the name using MimeMessagePreparator
try {
MimeMessagePreparator preparator = (mimeMessage) -> {
MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true);
helper.setFrom(new InternetAddress("no-reply#gmail.com", "JACK SPARROW"));
helper.setTo("example#gmail.com");
helper.setSubject("Sample email");
helper.setText("Message from ....", true);
};
javaMailSender.send(preparator);
} catch (MailException exception) {
throw exception;
}

Related

Send emails to multiple email addresses, It feeds email addresses from a csv file

I wanna create an application to send emails to several recipients. It feeds email addresses from a csv file and sends an email to each recipient, and I'm getting some trouble doing this.
Could you help me please?
Here is my CSVHelper.java
#Component
public class CSVHelper
{
public static String TYPE = "text/csv";
static String[] HEADERs = { "id", "email", "dateEcheance"};
//This method is used to filter the csv file and get only the emails
public List<ContactsFile> csvToEmails() throws NumberFormatException, ParseException
{
InputStream is = null;
try (BufferedReader fileReader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
CSVParser csvParser = new CSVParser(fileReader, CSVFormat.DEFAULT.withFirstRecordAsHeader().withIgnoreHeaderCase().withTrim());)
{
List<ContactsFile> emailsList = new ArrayList<>();
Iterable<CSVRecord> csvRecords = csvParser.getRecords();
for (CSVRecord csvRecord : csvRecords)
{
ContactsFile contact = new ContactsFile(csvRecord.get("email"));
emailsList.add(contact);
}
System.out.println(emailsList);
return emailsList;
}
catch (IOException e) { throw new RuntimeException("fail to get emails: " + e.getMessage()); }
}
We call csvToEmails() method in the controller to send the emails
#Autowired
private CSVHelper csvHelper;
#PostMapping("/getdetails")
public #ResponseBody EmailNotification sendMail(#RequestBody EmailNotification details) throws Exception {
MimeMessage message = sender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(message,
MimeMessageHelper.MULTIPART_MODE_MIXED_RELATED,
StandardCharsets.UTF_8.name());
try {
helper.setTo((InternetAddress) csvHelper.csvToEmails());
helper.setText(details.getMessage(),true);
helper.setSubject("Test Mail");
} catch (javax.mail.MessagingException e) {
e.printStackTrace();
}
sender.send(message);
return details;
this is an example of the csv file:
id,email,dateEcheance
1,address#email.com,10/05/2021
2,address2#email.com,10/02/2021
I'm new to spring boot, and I'm in trouble completing this project.
Assuming that you've mail server configurations in place. First, you need to provide the JavaMailSender implementation. Spring does provide the implementation for the same. You've to create a bean and config the mail server configurations as follows.
#Configuration
public class MailConfig {
#Autowired
private Environment env;
#Bean
public JavaMailSender mailSender() {
try {
JavaMailSenderImpl mailSenderImpl = new JavaMailSenderImpl();
mailSenderImpl.setHost(env.getRequiredProperty("mail.smtp.host"));
mailSenderImpl.setUsername(env.getRequiredProperty("mail.smtp.username"));
mailSenderImpl.setPassword(env.getRequiredProperty("mail.smtp.password"));
mailSenderImpl.setDefaultEncoding(env.getRequiredProperty("mail.smtp.encoding"));
mailSenderImpl.setPort(Integer.parseInt(env.getRequiredProperty("mail.smtp.port")));
mailSenderImpl.setProtocol(env.getRequiredProperty("mail.transport.protocol"));
Properties p = new Properties();
p.setProperty("mail.smtp.starttls.enable", "true");
p.setProperty("mail.smtp.auth", "true");
mailSenderImpl.setJavaMailProperties(p);
return mailSenderImpl;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
Configuration settings in application.properties. Add settings according to the mail server.
# SMTP mail settings
mail.smtp.host=**********
mail.smtp.username=**********
mail.smtp.password=**********
mail.smtp.port=**********
mail.smtp.socketFactory.port=**********
mail.smtp.encoding=utf-8
mail.transport.protocol=smtp
mail.smtp.auth=true
mail.smtp.timeout=10000
mail.smtp.starttls.enable=true
mail.smtp.socketFactory.class=javax.net.ssl.SSLSocketFactory
CSVHelper.java
#Component
public class CSVHelper {
// This method is used to filter the csv file and get only the emails
public List<String> csvToEmails() {
InputStream is = ClassLoader.getSystemClassLoader().getResourceAsStream("csvFile.csv");
try (BufferedReader fileReader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
CSVParser csvParser = new CSVParser(fileReader,
CSVFormat.DEFAULT.withFirstRecordAsHeader().withIgnoreHeaderCase().withTrim());) {
List<String> emails = new ArrayList<>();
Iterable<CSVRecord> csvRecords = csvParser.getRecords();
for (CSVRecord csvRecord : csvRecords) {
String email = csvRecord.get("email");
emails.add(email);
}
return emails;
} catch (IOException e) {
throw new RuntimeException("fail to get emails: " + e.getMessage());
}
}
}
Send mail service
#Service
public class MailSenderService {
#Autowired
private CSVHelper csvHelper;
#Autowired
private JavaMailSender sender;
public void sendMail(EmailNotification details) {
try {
List<String> recipients = csvHelper.csvToEmails();
String[] to = recipients.stream().toArray(String[]::new);
JavaMailSenderImpl jms = (JavaMailSenderImpl) sender;
MimeMessage message = jms.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(message, true);
// add the sender email address below
helper.setFrom("sender#mail.com");
helper.setTo(to);
helper.setText(details.getMessage(), true);
helper.setSubject("Test Mail");
sender.send(message);
} catch (javax.mail.MessagingException | NumberFormatException e) {
// action for exception case
}
}
}

how to format tables in Mails / outlook

I am sending email using Spring MVC but It is showing differently In Browser and outlook email
#Service("emailService")
public class EmailService {
#Autowired
private JavaMailSender mailSender;
StringBuilder ResponseTable=new StringBuilder();
public void sendMail(String emailid,String subject,int
tracking_id,String classification_type){
MimeMessage message=mailSender.createMimeMessage();
MimeMessageHelper helper=new MimeMessageHelper(message,true,"UTF- 8");
helper.setTo(emailid);
helper.setText(ResponseTable.toString(),true);
helper.setSubject(subject);
mailSender.send(message);
}
}
You can use a velocity Engine Template to create a custom template :
create your template mailTemplate.vm
create a methode where you can insert you data in a model
create a methode to insert this model in your template
1.mailTemplate.vm
<html>
<head></head>
<body>
<p>hello,</p>
<p>${variable}</p>
</body>
</html>
Create Model to send the Notification Mail
public Boolean NotificationMail(String sender, String receiver, String url,
String subject,String footer) {
LOG.info(" ... Sending new Subscription Notification Mail ");
try {
JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
mailSender.setHost(mailHost);
mailSender.setPort(port);
mailSender.setJavaMailProperties(setMailProperties());
Map<String, Object> model = new HashMap<String, Object>();
model.put("variable", "hello this is the text will be display in the mail");
String body = getVelocityTemplate(model);
LOG.info("Mail host {} , Port {} , url {} , sender {} , receiver {} , subject {} , body {} ",
mailHost, port, url, sender, receiver, subject, body);
Boolean sent = mailService.sendMailWithImg(sender, receiver, subject, body);
return true;
} catch (IllegalArgumentException e) {
LOG.error("IllegalArgumentException , Missing configuration", e);
} catch (Exception e) {
LOG.error("General Exception :{}", e);
}
return false;
}
insert model in the Template
protected String getVelocityTemplateContent(Map<String, Object> model) {
StringWriter stringWriter = new StringWriter();
StringBuilder builder = new StringBuilder();
builder.append("/template/mailTemplate.vm");
try {
VelocityEngineUtils.mergeTemplate(velocityEngine, builder.toString(), "UTF8", model,
stringWriter);
return stringWriter.toString();
} catch (Exception e) {
LOG.error("Error",e);
}
return null;
}
}

Why can't I send CSS decorated html email via spring?

I have successfully sent text email and the bellow implementation sends really basic html emails - I don't get the CSS classes in any of it.
The relevant parts of my MailServiceImpl class are:
protected void prepareAndSendMail(Map<String, String> emailMap) {
try {
InternetAddress[] parsed;
try {
parsed = InternetAddress.parse(emailMap.get("to"));
} catch (AddressException e) {
throw new IllegalArgumentException("Not valid email: " + emailMap.get("to)"), e);
}
MimeMessage mailMessage = javaMailSender.createMimeMessage();
mailMessage.setSubject(emailMap.get("subject"), "UTF-8");
MimeMessageHelper helper = new MimeMessageHelper(mailMessage, true, "UTF-8");
helper.setFrom(emailMap.get("from"));
helper.setTo(parsed);
helper.setText(mailContentBuilderService.buildHTMLTemplate(emailMap.get("text")), true);
javaMailSender.send(mailMessage);
} catch (MessagingException ex) {
throw new RuntimeException(ex);
}
}
protected String buildConfirmRegistrationButton(String label, String confirmationUrl) {
StringBuilder content = new StringBuilder();
content.append("<div class=\"jumbotron\">");
content.append("<div class=\"container-fluid\">");
content.append("<div class=\"form-group row justify-content-md-center justify-content-lg-center justify-content-xl-center\">");
content.append("<label>" + label + "</label> \r\n");
content.append("<br />");
content.append("<a href=\"" + confirmationUrl + "\">");
content.append("<button class=\"btn btn-primary\"> Click here to confirm </button>");
content.append("</a>");
content.append("</div>");
content.append("</div>");
content.append("</div>");
return content.toString();
}
#Override
public void sendNewUserRegistrationToken_HTML(OnRegistrationCompleteEvent onRegistrationCompleteEvent, User user, String token) {
Locale locale = Locale.US;
final String subject = messageSource.getMessage("mail.registrationConfirmationSubject", null, locale);
final String label = messageSource.getMessage("mail.registrationConfirmationLabel", new Object[]{user.getEmail()}, locale);
final String confirmationUrl = onRegistrationCompleteEvent.getAppUrl() + "/admin/user/registration/confirm?token=" + token;
final String content = buildConfirmRegistrationButton(label, confirmationUrl);
Map<String, String> emailMap = new HashMap<>();
emailMap.put("to", user.getEmail());
emailMap.put("from", environment.getProperty("support.email"));
emailMap.put("subject", subject);
emailMap.put("text", content);
prepareAndSendMail(emailMap);
}
The prepareAndSendMail method calls mailContentBuilderService.buildHTMLTemplate(String text) and is defined as:
private TemplateEngine templateEngine;
#Autowired
public MailContentBuilderServiceImpl(TemplateEngine templateEngine) {
this.templateEngine = templateEngine;
}
#Override
public String buildHTMLTemplate(String message) {
StringBuilder html = new StringBuilder();
html.append("<!DOCTYPE html>");
html.append("<html lang=\"en\" xmlns=\"http://www.w3.org/1999/xhtml\" xmlns:th=\"http://www.thymeleaf.org\"> ");
html.append("<head>");
html.append("<meta name=\"viewport\" content=\"width=device-width, initial-scale=1, shrink-to-fit=no\">");
html.append("<link rel=\"stylesheet\" href=\"https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css\" integrity=\"sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T\" crossorigin=\"anonymous\">");
html.append("<script src=\"https://code.jquery.com/jquery-3.3.1.slim.min.js\" integrity=\"sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo\" crossorigin=\"anonymous\"></script>");
html.append("<script src=\"https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js\" integrity=\"sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1\" crossorigin=\"anonymous\"></script>");
html.append("<script src=\"https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js\" integrity=\"sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM\" crossorigin=\"anonymous\"></script>");
html.append("</head>");
html.append("<body>");
html.append("<div class=\"container\">");
html.append("<div class=\"text-center\">");
html.append(message);
html.append("</div>");
html.append("</div>");
html.append("</body>");
html.append("</html>");
return html.toString();
}
The result I get when I try to register a new user is:
How can I make it look nice, obeying the CSS it should inherit from the CDN?
I have tried using a build method as described below (pointing to the right template, obviously), still no joy.
public String build(String message) {
Context context = new Context();
context.setVariable("message", message);
return templateEngine.process("mailTemplate", context);
}
You need to understand that email does not conform to normal web standards. You cannot add scripts to email. You cannot add external stylesheets (most will get stripped; see also this answer: Can you link to a CSS file from an email?).
You must embed CSS in the <head>, i.e.:
html.append('<style type="text/css">.container {...}</style>');

How to handle failover in case of TIBCO

I am struggling to setup fail over in tibco JMS provider. I know how to do this in case of ActiveMQ.
What I have tried is as follows
public class TibcoJMSQueueProducer {
private static final Logger LOGGER = LoggerFactory.getLogger(FDPMetaCacheProducer.class);
private static QueueConnectionFactory factory;
private QueueConnection connection;
private QueueSession session;
#Inject
private FDPTibcoConfigDAO fdpTibcoConfigDao;
private String providerURL;
private String userName;
private String password;
#PostConstruct
public void constructProducer(){
configure();
}
private void configure() {
try {
List<FDPTibcoConfigDTO> tibcoConfigList = fdpTibcoConfigDao.getAllTibcoConfig();
if(!tibcoConfigList.isEmpty()){
FDPTibcoConfigDTO fdpTibcoConfigDTO = tibcoConfigList.get(tibcoConfigList.size()-1);
String providerURL = getProviderUrl(fdpTibcoConfigDTO);
setProviderUrl(providerURL);
String userName = fdpTibcoConfigDTO.getUserName();
String password = fdpTibcoConfigDTO.getPassword();
this.userName = userName;
this.password=password;
factory = new com.tibco.tibjms.TibjmsQueueConnectionFactory(providerURL);
}
} catch (Exception e) {
System.err.println("Exitting with Error");
e.printStackTrace();
System.exit(0);
}
}
private void setProviderUrl(String providerURL) {
this.providerURL = providerURL;
}
private String getProviderUrl(final FDPTibcoConfigDTO FDPTibcoConfigDTO) {
return TibcoConstant.TCP_PROTOCOL + FDPTibcoConfigDTO.getIpAddress().getValue() + TibcoConstant.COLON_SEPERATOR + FDPTibcoConfigDTO.getPort();
}
private Object lookupQueue(String queueName) {
Properties props = new Properties();
Object tibcoQueue = null;
props.setProperty(Context.INITIAL_CONTEXT_FACTORY, TibcoConstant.TIB_JMS_INITIAL_CONTEXT_FACTORY);
props.setProperty(Context.PROVIDER_URL, this.providerURL);
props.setProperty(TibcoConstant.TIBCO_CONNECT_ATTEMPT, "20,10");
props.setProperty(TibcoConstant.TIBCO_RECOVER_START_UP_ERROR, "true");
props.setProperty(TibcoConstant.TIBCO_RECOVER_RECONNECT_ATTEMPT, "20,10");
InitialContext context;
try {
context = new InitialContext(props);
tibcoQueue = context.lookup(queueName);
} catch (NamingException e) {
System.out.println(e.getMessage());
}
return tibcoQueue;
}
public void pushIntoQueueAsync(String message,String queueName) throws JMSException {
connection = factory.createQueueConnection(userName, password);
connection.start();
session = connection.createQueueSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE);
Queue pushingQueue = (Queue)lookupQueue(queueName);
QueueSender queueSender = session.createSender(pushingQueue);
queueSender.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
TextMessage sendXMLRequest = session.createTextMessage(message);
queueSender.send(sendXMLRequest);
LOGGER.info("Pushing Queue {0} ,Pushing Message : {1}", pushingQueue.getQueueName(), sendXMLRequest.getText());
}
public String pushIntoQueueSync(String message,String queueName,String replyQueueName) throws JMSException {
connection = factory.createQueueConnection(userName, password);
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Destination destination = (Destination)lookupQueue(queueName);
MessageProducer messageProducer = session.createProducer(destination);
session = connection.createQueueSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE);
UUID randomUUID =UUID.randomUUID();
TextMessage textMessage = session.createTextMessage(message);
String correlationId = randomUUID.toString();
//Create Reply To Queue
Destination replyDestination = (Destination)lookupQueue(queueName);
textMessage.setJMSReplyTo(replyDestination);
textMessage.setJMSCorrelationID(correlationId);
String messgeSelector = "JMSCorrelationID = '" + correlationId + "'";
MessageConsumer replyConsumer = session.createConsumer(replyDestination,messgeSelector);
messageProducer.send(textMessage, javax.jms.DeliveryMode.PERSISTENT, javax.jms.Message.DEFAULT_PRIORITY, 1800000);
Message replayMessage = replyConsumer.receive();
TextMessage replyTextMessage = (TextMessage) replayMessage;
String replyText = replyTextMessage.getText();
LOGGER.info("Pushing Queue {0} ,Pushing Message : {1}", queueName, message);
return replyText;
}
public static QueueConnectionFactory getConnectionFactory(){
return factory;
}
}
In case of activeMQ we use
failover:(tcp://127.0.0.1:61616,tcp://127.0.0.1:61616)?randomize=false&backup=true url to handle failover as provider url in ActiveMQconnectionfactory constructor. I have seen somewhere to use multiple url in case of TIBCO like this
tcp://169.144.87.25:7222,tcp://127.0.0.1:7222
How I checked failover like this.
First at all I checked using single IP (tcp://169.144.87.25:7222) . Message is getting sent and received normally(I have not posted TibcoJMSReceiver code).
I tried with another IP(tcp://169.144.87.25:7222). It was working fine.
But when I tried with
final String
PROVIDER_URL="tcp://169.144.87.25:7222,tcp://127.0.0.1:7222";
I started my program. But before giving input I shutdown first server. As a failover the message should be sent to other server.
But It shows me session closed Exception.
So Am I handling failover in a correct way or is there other configuration I have to do.
Two TIBCO EMS daemons only work 'as one' if you enable fault-tolrance in both of them. Only then will they heartbeat with each other and share resources. You should have this in the remote daemon's tibemsd.conf:
listen = tcp://7222
...
ft_active = tcp://<ip to your box>:7222
and this on your local box:
listen = tcp://7222
...
ft_active = tcp://169.144.87.25:7222
And you don't need to create connection and session every time! One Connection and Session for many messages - 'Fault Tolerance' means it'll reconnect automatically for you. You could have an init() or connect() method you call once or just add it inside your configure method:
private void configure() {
try {
...
connection = factory.createQueueConnection(userName, password);
connection.start();
session = connection.createQueueSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE);
Then pushIntoQueue becomes as simple as this:
public void pushIntoQueueAsync(String message,String queueName) throws JMSException {
Queue pushingQueue = (Queue)lookupQueue(queueName);
QueueSender queueSender = session.createSender(pushingQueue);
queueSender.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
TextMessage sendXMLRequest = session.createTextMessage(message);
queueSender.send(sendXMLRequest);
LOGGER.info("Pushing Queue {0} ,Pushing Message : {1}", pushingQueue.getQueueName(), sendXMLRequest.getText());
}

Java send email through gmail, sometimes works sometimes hang

I am sending email by Gmail through my web app.
However, sometimes it is working fine but sometimes it just stop without any message.
Does anyone know how to solve this?
In my spring AppConfig.java
#Bean
public JavaMailSender getMailSender(){
JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
mailSender.setHost("smtp.gmail.com");
mailSender.setPort(587);
mailSender.setUsername("my email from");
mailSender.setPassword("my email password");
Properties javaMailProperties = new Properties();
javaMailProperties.put("mail.smtp.starttls.enable", "true");
javaMailProperties.put("mail.smtp.auth", "true");
//javaMailProperties.put("mail.transport.protocol", "smtps");
javaMailProperties.put("mail.transport.protocol", "smtp");
javaMailProperties.put("mail.debug", "true");
mailSender.setJavaMailProperties(javaMailProperties);
return mailSender;
}
In my mailService.java
public void sendEmailWithTemplate(Activity activity, Object object) {
Member member = (Member) object;
MimeMessagePreparator verificationEmail = getEmailFromActivity(activity, member);
try {
mailSender.send(verificationEmail);
System.out.println("Message sent.............................");
} catch (MailException ex) {
System.err.println(ex.getMessage());
}
}
private MimeMessagePreparator getEmailFromActivity(final Activity activity, final Member member) {
MimeMessagePreparator preparator = new MimeMessagePreparator() {
public void prepare(MimeMessage mimeMessage) throws Exception {
MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true);
helper.setSubject(activity.getActivity_subject());
helper.setFrom("my from email");
helper.setTo(member.getEmail());
String mailContent = activity.getActivity_content();
helper.setText(mailContent, true);
}
};
return preparator;
}
Sometimes its working fine and I will be able to send the mail, but sometime is just stop for more than 20 minutes at:
DEBUG SMTP: enable SASL
DEBUG SMTP: useEhlo true, useAuth false
DEBUG SMTP: trying to connect to host "smtp.gmail.com", port 587, isSSL false
This is the method I get from other post, but I can't look back the post.
Activity is one of my object storing the subject and content.
public void sendEmailWithActivity(Activity activity, Object object, String path) {
try {
Member member = (Member) object;
String host = "smtp.gmail.com";
String username = "email";
String password = "password";
String body = activity.getActivity_content();
String name = activity.getActivity_name();
String subject = activity.getActivity_subject();=
//Set the properties
Properties props = new Properties();
props.put("mail.smtps.auth", "true");
// Set the session here
Session session = Session.getDefaultInstance(props);
MimeMessage msg = new MimeMessage(session);
// set the message content here
msg.setSubject(subject);
msg.setContent(body, "text/html");
msg.setFrom(new InternetAddress(username));
msg.addRecipient(Message.RecipientType.TO,
new InternetAddress(member.getEmail()));
Transport t = session.getTransport("smtps");
t.connect(host, username, password);
t.sendMessage(msg, msg.getAllRecipients());
t.close();
} catch (Exception e) {
e.printStackTrace();
} finally {
}
}

Resources