hosted by liquidweb


Go Back   Web Hosting Talk : Web Hosting Main Forums : Hosting Security and Technology : sendmail forwarding help
Reply

Hosting Security and Technology Configuring and optimizing web hosting servers and operating systems, developing administration scripts, building servers, protecting against hackers, and general security (SSL certificates, etc.)
Forum Jump

sendmail forwarding help

Reply Post New Thread In Hosting Security and Technology Subscription
 
Send news tip View All Posts Thread Tools Search this Thread Display Modes
  #1  
Old 10-05-2004, 01:30 PM
pphillips pphillips is online now
Web Hosting Master
 
Join Date: May 2003
Location: California, USA, Earth
Posts: 929

sendmail forwarding help


What i want to do is send an email notification to an address after sendmail receives a message to a mailbox. For example:

1. Server receives a message to something@domain.com.
2. Server sends a message to something@anotherdomain.com with a personalized message, such as, something@domain.com has mail.

Just a little reminder that you've received mail on another address so that you know to check it. Anyone know how I would do this with sendmail? I've looked at .forward options, but haven't found what I'm looking for. I just need to enable this for 1 email box. I dont want the whole message to be forwarded, just a simple personalized message.

__________________
Blesta - Professional Billing Software
Innovation that benefits the user experience
Trial - Demo | 866.478.7567 | Twitter @blesta

Reply With Quote


Sponsored Links
  #2  
Old 10-05-2004, 02:31 PM
Angelo Angelo is offline
Web Hosting Master
 
Join Date: Mar 2004
Location: Los Angeles
Posts: 617
Do you want the message forwarded exactly with the same body as its received, this is very easy by adding a valias but i think you want to send something else to another e-mail adress if any mail is received; than:

You can forward something@domain.com to a cgi or a php processor locally. Than this processor can look for the mail, headers, subjects and the body and use it in mailing anywhere you want. But this may be difficult if you are not experienced with cgi/php.

__________________
Hosting Reviews

Reply With Quote
  #3  
Old 10-05-2004, 02:58 PM
andreyka andreyka is offline
Linux Guru
 
Join Date: Mar 2004
Location: Odessa, Ukraine
Posts: 604
alias or procmail

__________________
My CVV Page

Reply With Quote
Sponsored Links
  #4  
Old 10-05-2004, 03:17 PM
pphillips pphillips is online now
Web Hosting Master
 
Join Date: May 2003
Location: California, USA, Earth
Posts: 929
I am very familiar with PHP, and have heard of forwarding mail to a script, but I'm not sure how this works. Do you know where I can find more info on how I can interpret the message from PHP? If the message is in an array or something, then I can make it do whatever I want with it. If I do this, can the message be forwarded to the PHP script AND sent to the users mailbox?

Thanks!

__________________
Blesta - Professional Billing Software
Innovation that benefits the user experience
Trial - Demo | 866.478.7567 | Twitter @blesta

Reply With Quote
  #5  
Old 10-05-2004, 03:28 PM
pphillips pphillips is online now
Web Hosting Master
 
Join Date: May 2003
Location: California, USA, Earth
Posts: 929
I think I found the answer to my question at http://gvtulder.f2o.org/articles/incoming-mail/

If I come up with a working solution I'll post it here. Thanks!

__________________
Blesta - Professional Billing Software
Innovation that benefits the user experience
Trial - Demo | 866.478.7567 | Twitter @blesta

Reply With Quote
  #6  
Old 10-05-2004, 03:34 PM
Angelo Angelo is offline
Web Hosting Master
 
Join Date: Mar 2004
Location: Los Angeles
Posts: 617
Yes, that could indeed be a solution, but usually i get a bounce error-message even if the processor gets the mail and do the operation. If you have it run clean, i would like to hear

__________________
Hosting Reviews

Reply With Quote
  #7  
Old 10-05-2004, 05:24 PM
pphillips pphillips is online now
Web Hosting Master
 
Join Date: May 2003
Location: California, USA, Earth
Posts: 929
I got it working, at first I would get the message bounced back with the following error:

----- The following addresses had permanent fatal errors -----|/home/script.php (reason: Service unavailable) (expanded from: <email@address.com>) ----- Transcript of session follows -----smrsh: "script.php" not available for sendmail programs (stat failed)554 5.0.0 Service unavailable

The solution was to create a symbolic link in /etc/smrsh to point to the script because smrsh only allows programs to be run from /etc/smrsh directory.

ln -s /home/script.php script.php

Below is the PHP code I used:

PHP Code:
#!/usr/bin/php
<?php
/*
symbolic link in /etc/smrsh for file
and a .forward file with the following info

"|/etc/smrsh/script.php"
[email]emailbox@address.com[/email]
*/
// read from stdin
$fd fopen("php://stdin""r");
$email "";
while (!
feof($fd)) {
    
$email .= fread($fd1024);
}
fclose($fd);

// handle email
$lines explode("\n"$email);

// empty vars
$from "";
$subject "";
$headers "";
$message "";
$splittingheaders true;

for (
$i=0$i<count($lines); $i++) {
    if (
$splittingheaders) {
        
// this is a header
        
$headers .= $lines[$i]."\n";

        
// look out for special headers
        
if (preg_match("/^Subject: (.*)/"$lines[$i], $matches)) {
            
$subject $matches[1];
        }
        if (
preg_match("/^From: (.*)/"$lines[$i], $matches)) {
            
$from $matches[1];
        }
    } else {
        
// not a header, but message
        
$message .= $lines[$i]."\n";
    }

    if (
trim($lines[$i])=="") {
        
// empty line, header section has ended
        
$splittingheaders false;
    }
}

// Cell Phone to notify
$to "sendtoaddress@domain.com";

// Headers
//empty headers from above
$headers "";
$headers "From: [email]email@domain.com[/email] <email@domain.com>\r\n";

// Mail it
mail($to$subject$message$headers);

?>
Basically I will be using this script with Vonage, to notify my cell phone when I receive a new message, and also send the entire message to another box so that I can check it. But I'm sure it can have many more applications. I just threw this together as an example, I realize its not that clean and more can be done with it, but I figure someone will come across this thread in the future and wish there was some code. Hope it helps someone!

And it does run clean!!!

__________________
Blesta - Professional Billing Software
Innovation that benefits the user experience
Trial - Demo | 866.478.7567 | Twitter @blesta

Reply With Quote
Reply

Related posts from TheWhir.com
Title Type Date Posted
Web Hosting Sales and Promos Roundup - January 4, 2013 Web Hosting News 2013-01-04 16:50:32
Go Daddy Identifies Causes of September 10 DNS Failure in Detailed Postmortem Post Web Hosting News 2012-11-12 13:49:14
Amazon Web Services Adds New Features to Gold and Platinum Level Support Web Hosting News 2012-01-30 16:12:34
Web Host Bluehost Launches Reseller Hosting Web Hosting News 2011-10-14 15:16:37
Web Hosting Sales and Promos Roundup - August 5, 2011 Web Hosting News 2011-08-05 20:48:41


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
Postbit Selector

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

Forum Jump
Login:
Log in with your username and password
Username:
Password:



Forgot Password?
Advertisement:
Web Hosting News:



 

X

Welcome to WebHostingTalk.com

Create your username to jump into the discussion!

WebHostingTalk.com is the largest, most influentual web hosting community on the Internet. Join us by filling in the form below.


(4 digit year)

Already a member?