2016-04-21

I have test machine (test.domain.com) with dovecot+postfix both configured to work with database users. I can send and recieve mail (smtp) and check all my folders in UI(imap) with addresses like user@domain.com. But I has other server (domain.com) with same mail config and I want to configure test server to be able to send and recieve mails with user@test.domain.com address.

The easiest solution probably is changing code or db or both to handle records with desired "test" prefix but due to some reasons I don't want change code or change DB structure - others test their code on that machine and I want to replace all recipients and outgoing adressess to test.domain.com even if code (java mail api) and db records logic are similar to production.

I almost done with simple trick (replace in dovecot and postfix select queries which imitates I has test.domain.com records) Now I can send to user@test.domain.com from gmail (postfix trick in conf is ok), can see folders in UI (dovecot trick in conf is ok) but I can't send from user@test.domain.com - all my mails from test machine come to my gmail as user@domain.com.

My postfix conf

pqsql-aliases.cf

pqsql-boxes.cf

dovecot-sql.conf

My questions:

Recieve. Does lmtp phrase in postfix config mean that postfix redirects it to dovecot or lmtp only for sending outgoing mail to dovecot? Does dovecot queries run when recieve mail? As I'm recieving mails to @test.domain.com I think my replace in pqsql-boxes WHERE clause is OK but I'm not sure I should replace in select. Is it ok?

Getting mails by imap. I'm surprised that I see mails in UI because I give to dovecot mails without test prefix (from DB) via Java Mail API and thus replace in WHERE clause looks redundunt. What query (password or user) used when reading folders? I thing user_query used when recieving mail and putting to maildirs from that query but I'm not sure)

Send form @test.domainc.com. This is not working part. Is alises postfix config reliable for that? As you see from comments in pqsql-aliases I tried both varinats - replace select result to test prefix and not (reloaded both postfix and dovecot) but both variants failed.

Role of Java in mail. As I understand, Java not taking part in recieving but what about it's role in sending mail and checking folders? I see java connection with smtp and imap protocols with providing credentials from DB (without test prefix email) but what after that? Are postfix or dovecot continue work after Java call or I should change from just in Java? I repeat, I even didn't tryto call Java connect with test prefix as I want to keep code same with production and rely on postfix/dovecot replace tricks.

Finally, I want to say that I think I'm close to working conf but as I'm total noob in mail software and didn't understand how it works under the hood I'm asking such obvious questions. If somebody see short fix to all 3 confs, please, kindly share your thoughts.

Show more