Review your favorite Linux distribution.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 08-24-2005, 11:29 PM   #1
LQ Newbie
Registered: Aug 2005
Posts: 4

Rep: Reputation: 0
Question 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 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 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
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 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
Old 08-25-2005, 04:57 AM   #2
Registered: Jun 2004
Location: Inland NW, US
Distribution: Ubuntu
Posts: 366
Blog Entries: 1

Rep: Reputation: 44
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 then you can simply store the userlist_id in a scalar variable by saying:

$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,
Old 08-25-2005, 10:56 AM   #3
LQ Newbie
Registered: Aug 2005
Posts: 4

Original Poster
Rep: Reputation: 0
Thanks a lot for helping me out here.
I'll go ahead and try that out. Appreciate your help. Thank You.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Running a Perl script with SendMail NewByy Linux - Newbie 4 08-25-2005 02:02 PM
Running a perl script bobfinners Linux - Software 1 06-23-2005 06:18 PM
running perl script dav_y2k Linux - Newbie 3 04-25-2005 06:00 AM
Running Perl Script upon startup andy7t Linux - Software 1 04-20-2005 05:43 PM
Perl script not running on FreeBSD J_Szucs *BSD 12 07-13-2002 10:05 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:58 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration