Forum Moderators: coopster

Message Too Old, No Replies

IMAP Forward Email

         

FiRe

2:21 pm on Jul 2, 2006 (gmt 0)

10+ Year Member



I am trying to automatically forward emails to another account using IMAP. Is there any easy way of doing this?
I am currently looping through each email, retrieving who its from/subject/message, then sending those details on to the new address using mail(). This isn't great as you wont receive things like attachments and other headers. Is there like a forward function or anyway of retrieving the raw email contents and sending on to another address?

mcavic

4:59 pm on Jul 2, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you call sendmail directly, and pipe the entire email to it, it should take all the headers and attachments.
/usr/lib/sendmail -fFromAddress@domain.com Destination@domain.com

FiRe

5:52 pm on Jul 2, 2006 (gmt 0)

10+ Year Member



what like an exec() command?

FiRe

5:53 pm on Jul 2, 2006 (gmt 0)

10+ Year Member



I found this function:

function mailfrom($fromaddress, $toaddress, $subject, $body, $headers) {
$fp = popen('/usr/sbin/sendmail -f'.$fromaddress.' '.$toaddress,"w");
if(!$fp) return false;
fputs($fp, "To: $toaddress\n");
fputs($fp, "Subject: $subject\n");
fputs($fp, $headers."\n\n");
fputs($fp, $body);
fputs($fp, "\n");
pclose($fp);
return true;
}

But I would still have to pass to the function the subject and stuff?!

mcavic

10:44 pm on Jul 2, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yep, but all you have to pass to sendmail is the from and to (on the command line) and then the entire message text including headers.

$fp = popen("/usr/sbin/sendmail -f$fromaddress $toaddress", "w");
if ($fp) {
fputs($fp, $message);
fputs($fp, "\n.\n");
pclose($fp);
}
else {
print "an error occurred\n";
}

FiRe

2:27 pm on Jul 3, 2006 (gmt 0)

10+ Year Member



how do you get the entire message + headers in IMAP, is there a function?