Beefy Boxes and Bandwidth Generously Provided by pair Networks Frank
Perl Monk, Perl Meditation
 
PerlMonks  

Programmatically Adding E-Mail Accounts

by rjahrman (Scribe)
on Sep 15, 2004 at 05:04 UTC ( #391075=perlquestion: print w/ replies, xml ) Need Help??
rjahrman has asked for the wisdom of the Perl Monks concerning the following question:

I have a shared hosting account (cPanel, with SSH), and I want to programmatically add e-mail accounts that can receive e-mails and then be checked via POP3. I don't care about webmail, spam protection, outgoing mail, or anything else. I just want to add an account, then put ftp.domain.com as the POP3 server in Outlook/Thunderbird/whatever with the account's username and password and to have it get e-mails sent to user@domain.com.

So, I assume that this is done by system calls. As far as I know, I need to do:

Adduser username -g mail
Passwd username password

Is this all? Should I then be able to send e-mails to username@domain.com and get e-mails in a client? Since it's a shared host, do I somehow need to compensate for that? (Will the e-mails sent to my domain end up at the right users? Are the users created server-wide, or just from my account?) Will this work with the existing daemon?

Thanks in advance.

BTW: Supposedly I could also hack a cPanel call, but this way is cooler. :) And I know that I shouldn't be doing this on a shared account, but I'm just playing around.

Comment on Programmatically Adding E-Mail Accounts
Re: Programmatically Adding E-Mail Accounts
by Anonymous Monk on Sep 15, 2004 at 05:16 UTC
    You misunderstand, this is not comp.unix
Re: Programmatically Adding E-Mail Accounts
by matija (Priest) on Sep 15, 2004 at 05:45 UTC
    And I know that I shouldn't be doing this on a shared account, but I'm just playing around.
    Buddy, if you "shouldn't be doing that" then "just playing around" is no excuse.

    Unless you have root on the machine, adduser won't work. And passwd doesn't accept a password on the command line (it would be a huge security breach if it did), you'll have to use Expect;

    As for the rest of your questions, they depend on the details of how the server was set up, and this is not the place to discuss them. You want a unix discussion forum. Go back two routers and turn left.

      And passwd doesn't accept a password on the command line (it would be a huge security breach if it did), you'll have to use Expect;

      That is not actually correct. For example you can (as root) do:

      sub add_shell_passwd { my ( $user, $shellpwd ) = @_; open PWD, "|$PASSWD_BIN --stdin $user" or die "Can't open pipe to +$PASSWD_BIN $!\n"; print PWD $shellpwd, "\n"; close PWD; }

      On the other hand adding a shell password adds a full shell account for the user. For the benefit of the OP there are many ways to skin this cat. If you want to make real user accounts you either want to make /dev/null the users default shell (so they can't login) or use say cram-md5 so they can have a pop3 pwd but no shell password. This is typically NOT what you want to do. Try Googling for 'creating virtual pop3 accounts linux'

      cheers

      tachyon

        That is not actually correct.
        Actually, it IS.

        The passwd manpage on Linux (Debian) and Solaris do not list the --stdin switch. Quite possibly you are running some system that supports it, but that DOES NOT make what I said incorrect.

        The question did not define which operating system the machine he is using actually runs, but it's far more likely that it doesn't support --stdin that that it does.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://391075]
Approved by Paladin
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (8)
As of 2014-04-21 08:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (492 votes), past polls