PDA

View Full Version : Sendmail mysql map



<-- R O B -->
07-29-2004, 03:08 AM
Hi

Does any one know if its possible to set up a sendmail - mysql map on a vps?

Alternatively can somebody suggest a good way of doing the following:

My client wants a web site (e.g. mysite.com) where people register with their current email address.
The site then assigns an email address such as joe.bloggs@mysite.com, this email address then forwards the mail to the users main email address.

My thoughts were that if the server's mail was looking up info in mysql then i could write some php code that added the user details when they registered.

Any thoughts really appreciated!

Rob C

FZ
08-01-2004, 11:29 AM
I don't know about a Sendmail-mySQL map - I did a search on Google and found some stuff - I don't think it would work on our VPS system (or it would be a very involved install!)

What I would suggest, though, is to use PHP and mySQL: store all details in mySQL (e.g. the local name and forwarding e-mail address), and then just output those details (perhaps via a cron script, on the hour) to your /etc/mail/aliases file (and then get it to run the "newaliases" command).

If you wanted to be efficient, you could add a "status" column to the table that would signal whether that particular alias had already been added or not - so you'd add new rows to the table with that column set to 0 by default, then your hourly-run script would only add the new details (those with that column value of 0) to the end of the aliases file, after which it would change their values to 1. For removals, you could change the status to 2, meaning that (for example) the entire table should be output again, after removing the rows with a status of 2, and changing all other status values to 1).

That's a rough idea of how I'd do it. Obviously not the most efficient/best way, but it would work and it would save you the trouble of messing with Sendmail and potentially breaking your VPS.

Good luck, and keep me posted on how it goes.

<-- R O B -->
08-02-2004, 02:35 AM
Thanks Fayez

I will keep you informed on how it goes. Just one question - on the aliases file I'm guessing that each email forwarding line is going to look like this:

websiteaccountname: forward@mynormalemailaddress.com

Do I need to set up a user "websiteaccountname" for this to work?

Thanks
Rob

FZ
08-02-2004, 11:12 AM
Rob,

Yes, the format (in keeping with your example) is...


joe.bloggs:jbloggs@bloggsISP.com

Which would enable forwarding for joe.bloggs@mysite.com - so, you don't need to set up a user explicitly, as this is what is done for you already. This way, you can use your PHP and mySQL backend to totally automate the process like you intended to (without touching Sendmail configuration).

The great thing about this is that all aliases you add this way would then also show up in your Site Manager, just as if you had added them via your web browser!

<-- R O B -->
08-02-2004, 11:46 AM
HI Fayez

I've looked a little further and I'm seeing different behaviour between using the site manager to add an alias and editing the aliases file.

If I add joe.bloggs:jbloggs@bloggsISP.com to the aliases file then the site manager says that this is a distribution list alias.

If I add an email alias of joe.bloggs2:jbloggs2ISP.com via the site manager then it appears in the aliases file and the virtusertable file

The first way does not work, in that no email is forwarded. It only works after I add

jbloggsISP.com joe.bloggs

into the virtusertable and then update the virtusertable .db

i guess this means that my cron job is going to need to alter and update both the aliases and virtusers files.

Cheers
Rob

jalal
08-02-2004, 02:38 PM
If you add a user (by hand) to the /etc/mail/aliases file, then you also need to add him to the /etc/mail/.alias_type file.

Otherwise, he'll end up as a distribution list as you've noticed.

And don't forget to run 'newaliases' as well, to update the aliases map file

HTH

FZ
08-02-2004, 02:51 PM
Thanks for grabbing that one, Tim.

Is there really a problem with it being assigned a distribution list? I think it (.alias_type) really is only a differentiation for the sake of the Site Manager. I say this because I added an entry (manually) to /etc/mail/aliases and then ran the newaliases command. I tested out this new forwarding address and it worked perfectly - I saw it in my Site Manager too, but did not notice it was marked as a distribution list...

jalal
08-03-2004, 01:52 AM
I think you're right Fayez, its something internal to Site Manager. Possibly a flag telling Site Manager that it is not a true email address or something along those lines.

<-- R O B -->
08-03-2004, 01:52 AM
Cool, thanks both of you for the help. I'll let you know how things go !