Send postfix mail to Java application running on Tomcat - java

I have a Postfix mail server, and I want to forward my received emails to my application written in Java and running on a Tomcat web server.
As far as I know, it is possible to forward the whole email (head, body, everything) to a port on localhost, where both the mail server and my application is running.
But I don't have any idea how to achieve this. I assume to a http server like Tomcat I cannot send this data in plain (postfix does not wrap it into a http package), so maybe I have to write another daemon process to receive the data from postfix, wrap it into http, and send this to my application?
I'm a bit confused, and have never been a specialist of protocols and these kind of things.
Please someone explain how can I solve the problem above!
Thank you in advance,
Balázs

Related

How to use Tomcat as SMTP server to send and receive mail using Javamail

I never used Tomcat and Javamail before. My main experiences was SpringBoot services. But now I have got task to create service to send and received mail for application with standalone Tomcat server. I cant understand how to use Tomcat as a mail server. I cant find any lesson on this topic. All tutorials about Javamail use outer SMTP servers like gmail or other.
Please help me where can I find appropriate tutorial or give me advice how to start teach this problem.

Forward http request to other server that will respond to the original requester using java servlets

I have a problem where I have several servers sending HttpRequests (using round robin to decide which server to send to) to several servers that process the requests and return the response.
I would like to have a broker in the middle that examines the request and decides which server to forward it to but the responses can be very big so I would like the response to only be sent to the original requester and not be passed back through the broker. Kind of like a proxy but the way I understand a proxy is that all data is sent back through the proxy. Is this possible?
I'm working with legacy code and would rather not change the way the requests and responses are processed but only put something in the middle that can do some smarter routing of the requests.
All this is currently done using HttpServletRequest/Response and Servlets running on embedded Jetty web servers.
Thank you!
What you're after is that the broker component is using the client's IP address when connecting to the target server. That is called IP spoofing.
Are you sure that you want to implement this yourself? Intricacies of network implementation of such a solution are quite daunting. Consider using software that has this option builtin, such as HAProxy. See these blog posts.

not getting mail from Java application using smtp

I have a java application which send mail using SMTP,but recently a modified its property file and restarted my tomcat server [although property change is a password change and is not related to smtp ].
now it is not sending mails :(
I checked my smtp server and tried to send mail from it.It is sending.
Any idea what went wrong?
any help would be appreciated
thanks in advance
Your SMTP server logs should tell you whether something was sent to it, and why it didn't relay the email.
If your change was password related, an authentication error may be the cause.
I would look at the following first:
Which credentials is your Java application using to send requests to the SMTP server?
Then, are these credentials still accepted on the server?
Finally, most SMTP servers will have a separate list of either included or excluded source IPs, from where to accept message requests, see if your Java app's source machine is allowed there.

Arduino Client send data to Java Server through Sockets

I'm starting a new project where I need to send data from an Arduino to a Java Server. I would like to use the Arduino Wifi shield. Afterwards the java server will send the received data to a web service trough a 3G Router.
Is this setup possible? Does there exist an API to set up a socket connection between an Arduino and a Java Server?
If not which possibilities do i have? Thank in advanced
There is certainly a number of ways you can do this. You can use the Arduino Ethernet library to make connections to your Java server. Here's a nice little program called ClientConnect which uses the ethernet device to make a connection to a server. This little program sends a web request to the server with the following lines:
client.println("GET /search?q=arduino HTTP/1.0");
client.println();
On the server side it would be easiest to use some sort of simple servlet and utilize a Java web framework such as Tomcat.
Your Arduino transactions would then just look like simple web transactions:
GET /your-path-to-your-servley?field1=value1&field2=value2 HTTP/1.0
[[ empty line here ]]
This will send a set of field/value pairs to your Java webserver which will call your servlet. In the example at the top, "q" is the field name and "arduino" is the value.
Hope this helps.
Similar to the answer by #gray which is a "push" solution, is to have the java server query the Arduino at some interval ("pull" model). To do this, just see the Web hosting example in Arduino's ethernet samnple library. You can modify it, to have the arduino return the value of its sensors as part of its http response.

Apache xml-rpc client and server implementation

I have been trying to figure out how to implement a simple xml rpc server and client with apache xml-rpc (http://ws.apache.org/xmlrpc/) but i haven't been successfull. I implemented a server and a client as specified here in the section Webserver: http://ws.apache.org/xmlrpc/server.html
The only thing i did differently was this "phm.addHandler("Calculator",org.apache.xmlrpc.demo.Calculator.class);" instead of this "phm.load(Thread.currentThread().getContextClassLoader(), "MyHandlers.properties");". When i start the server it start properly but I can't see the service when running netstat. Then when I run a request from the client it fails because it cannot find the class to call (i.e. the client doesn't really connect to the server). I have also observed that the client can start (not sending any requests) without any errors even when the server is not running.
Anyone have any ideas. I'm really lost.
Are you trying to run both client and server on the same computer? ...that may be the reason for netstat not working. (It cannot sniff packets on the loopback address.)
If you're still interested I can post a working example.

Categories