Hello Hassan,
if you are writing a mailet, you are just inside a java class with full access
to the mail object.
So you could do what you like in accessing a database.
There is no limit for accessing a database from your class, but I think there
is no direct support for predefined database objects or something like that.
I could only offer hints from our implementation.
We are using James v2.3.2, together with a database (postgres, but that does
not matter).
We implemented this independent from James, handling all thing by our own code.
Just few hints:
- Be failsave. The database could be offline and all that worse things. You
need to handle that.
- Be failsave. The mail object may not be as defined by RFC, fields may missing
(like "from" or "to"). Many spam mails are far away from mail standards. Expect
parsing errors every time.
- If you throw an exception, or your database clients does, or java mail does,
the mail will "fail".
Failed mails will not be sent and will be stored to the error processor.
- Configure your db access. We used "JPA" for database access. JPA has own
properties for configuring the database access (user, password and so on). We
used "eclipselink", for accessing and defining JPA. You may have a look at that.
- Your database client jar (eg. postgresql-jdbc3-9.1.jar) should reside in
/var/james-2.3.2/apps/james/SAR-INF/lib/ for 2.3.2. (not sure for 3.x).
- Think about what will happen for "database schema updates". At the time you
will deliver the next version of your software, you may need to update your
database schema. We use "Liquibase" for that. You may have a look at that.
We configured the database access inside the config.xml, like:
<mailet match="All" class="myMailet">
<jpa-javax.persistence.jdbc.url>jdbc:postgresql:myUsername</jpa-javax.persistence.jdbc.url>
<jpa-javax.persistence.jdbc.user>myPass</jpa-javax.persistence.jdbc.user>
....
</mailet>
Most of that hints are independend from James. Every mail project using a
database may have this hints in mind.
Good look!
Bernd
-----Ursprüngliche Nachricht-----
Von: Hassan Latif [mailto:[email protected]]
Gesendet: Dienstag, 3. März 2015 09:48
An: James Users List
Betreff: Access DB via mailet
Hello,
This maybe a very basic question as I'm new to James. I'm trying to figure out
what are the options of accessing a database through a custom mailet and what
are the caveats. For my scenario I need to save the headers of an incoming
email. I can also prepare a document providing the details of accessing DB from
the mailet for the benefits of others if someone can point me in the right
direction.
Thanks.
Hassan