Send email via Java via Postfix

I am currently developing a web application based on Java EE, JSF, EJB, etc. This application is deployed on Debian 7.6 and installed by Postfix.

I can use something like this to send email via the command line:

/ usr / bin / mailx -s "SUBJECT" -a "From: from@email.de " to@email.de

It still works.

My attempt is to use this line and run it as a linux command in Java. It's right?

Can I use JavaMail to do this (send email via postfix), and if so how can I tweak the configuration for this?

I am really struggling with this part of my web application. Maybe you can help me find out which is the best solution.

+3


source to share


2 answers


I don't think using ProcessBuiler and running executable commands to send email is caused when JavaMail has already provided an API for mail (send / receive) clients like your webapp. Assuming you've set up a mail server like SMTP, you can follow a tutorial like this to get it done smoother.



+1


source


You can use the ProcessBuilder class to execute a command mailx

from your Java program. You don't need to use JavaMail if all you want to do is execute an existing command mailx

from a Java program (assuming all the necessary infrastructure to send email using is postfix

already installed)



You need to understand that JavaMail is a set of APIs (classes, interfaces, methods) that allow you to implement email functionality in a Java application. You either use ProcessBuilder

to execute the command mailx

, or you completely abandon this idea and use the JavaMail API. You don't use them together.

+2


source







All Articles