I am currently developing a web application based on Java EE, JSF, EJB etc. This application is deployd on a Debian 7.6 and there is Postfix installed.
I can use something like this to send emails via commandline:
/usr/bin/mailx -s "SUBJECT" -a "From: [email protected]" [email protected]
This is working so far.
My attempt is, to use this line and run it as linux command in Java. Is that correct?
Can I use JavaMail for this (send email via postfix) and if so, how can I set up the config for this?
I am really struggeling with this part of my webapplication. Maybe you can help me to find out, what the best solution is.
You can use the ProcessBuilder class to execute the mailx
command from within your Java program. You don't need to use JavaMail if all you want to do is execute the existing mailx
command from within a Java program (assuming that all required infrastructure for sending an email using postfix
is already in place)
You need to understand that JavaMail is a set of APIs (classes, interfaces, methods) that allow you to implement email functionality within a Java application. You either use ProcessBuilder
to execute the mailx
command or you completely scrap this idea and use the JavaMail API. You don't use both these together.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With