LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Running a Perl script with SendMail (https://www.linuxquestions.org/questions/programming-9/running-a-perl-script-with-sendmail-356709/)

NewByy 08-24-2005 10:29 PM

Running a Perl script with SendMail
 
I am new to sendmail and just started on Perl. This might be a really basic question, since I know very
little about sendmail or perl, if anyone can help me it would be greatly appreciated.

I will try to be thorough in my explaination... Here's the problem:

I have an email address userlist@dummy.com and have a lists of emaill addresses in a MySQL database (a mailing list).
if a message is sent to the userlists email address, I want a perl script to be executed
that pulls in the list details from a MySQL database, and forwards the message to all the
emails addresses in the list.

Also I wondered if address extensions are possible with sendmail.I mean I wanted to maintain multiple lists
in the database, if a message is recieved with an address like userlists-1678@dummy.com. I want to pull the
email address for mailinglist_id 1679 from the database and forward the email to the users in the list.

I am ok with perl programming and can handel the database part of pulling the mailing list etc...
but I'm not at all sure on the SendMail configuration part. My questions are

1) How can I configure sendmail to run a perl script when an email is recieved at userlist@dummy.com?
2) How can I take the message from send mail and forward the message to addresses that I pull from the database?
3) Are Address extensions possible in SendMail, if yes then how do I enable that?
4) Can I strip the id (1678 from the address like userlists-1678@dummy.com) so that I can use that to query the database for the appropriate list.

I'd really appreciate any help in this regards. Thanks in Advance

jrtayloriv 08-25-2005 03:57 AM

I haven't messed around with any database programming in Perl, but the answer to your fourth question would be to use a regular expression to pull out the number. For a very simplified example, supposing the there were no other numbers in the email address besides the userlist id (e.g. if they are all formatted as userlist-####@dummy.com) then you can simply store the userlist_id in a scalar variable by saying:

Code:

$email_addr =~ /(\d+)/;
$list_id = $1;

where $email_addr is a string containing the email address and $list_id will be the matched number. What this does is search for one or more(+) "digit" (\d) characters within the string on the left hand side of the binding operator (=~). The $1 simply means whatever was matched within the first set of parentheses. And of course as you've probably heard by now, there is more than one way to do this, and this is a very simple example that will only work under the conditions stated above, if you need something more specific, feel free to ask, and I'll try my best to help out.

Hope this helps,
jrtayloriv

NewByy 08-25-2005 09:56 AM

Thanks a lot for helping me out here.
I'll go ahead and try that out. Appreciate your help. Thank You.


All times are GMT -5. The time now is 08:23 PM.