You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-user@james.apache.org by Bernd Waibel <BW...@intarsys.de> on 2015/03/03 11:17:23 UTC

AW: Access DB via mailet [unsigned]

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:hassan.latif@gmail.com] 
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

Re: Access DB via mailet [unsigned]

Posted by Hassan Latif <ha...@gmail.com>.
Hi Bernd,

Thanks a lot for your invaluable advice and hints, they will definitely go
a long away in helping me implementing my project.

We are leaning towards using James 3.0 beta for two primary reasons. One,
it's based on the Spring framework so I assume it could be made scale-able
with some effort. Two, if the James community is planning to roll out a
stable version of James 3.0 in the near future then my team wouldn't want
to miss the bandwagon.

I'm also quite new to the Spring framework, but as per my understanding it
does provide some level of database transaction capabilities, and I was
wondering whether we can utilize those capabilities in the context of the
custom mailet.

Appreciate any thoughts on this.

Thanks.

Hassan



On Tue, Mar 3, 2015 at 1:17 PM, Bernd Waibel <BW...@intarsys.de> wrote:

> 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:hassan.latif@gmail.com]
> 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
>