DevHeads.net

Sending with Multiple Domain Suffixes from Single Apache Server Box

How do I configure postfix to append the correct domain on outgoing emails
from php on apache:

I have LAMP on Centos 7 and a static IP. There are several domain names
registered to that static IP:
first.com -> my static ip
another.com -> my static ip
third.com -> my static ip
My postfix MX server is also on the webserver box.

php uses the following format:
$result = mail($to, $subject, $message, $headers, "-f returndomain")

So how do I configure postfix to append the correct domain on outgoing
emails:
if returndomain is first.com, I would like postfix to send it with the
virtual <a href="mailto: ... at first dot com"> ... at first dot com</a> from addy
if returndomain is another.com, I would like postfix to send it with the
virtual <a href="mailto: ... at another dot com"> ... at another dot com</a> from addy

Details:
1. I need to send confirmation emails using php on apache to people
registering for my services from the internet
2. I need to have the correct domain suffix and return path added to the
sender's email:
<a href="mailto: ... at first dot com"> ... at first dot com</a> sending from /var/www/html/first/ needs the email headers
all consistent with mail sent from first.com
<a href="mailto: ... at another dot com"> ... at another dot com</a> sending from /var/www/html/another needs mail sent from
<a href="mailto: ... at another dot com"> ... at another dot com</a>
3. these emails go TO pretty much anywhere - google, yahoo - anywhere
visitors request confirmation to go
4. these emails come FROM my MX on the webserver DIRECTLY to their email
addy, not relayed thru google etc.
5. the machine hostname isn't any of the above domain names, it is simply
somehost

Apache sends first.com requests to /var/www/html/first/ using DocumentRoot
"/var/www/html/first/"
Apache sends another.com requests to /var/www/html/first/ using DocumentRoot
"/var/www/html/another/"

obviously the user and group will be apache:apache

So how do I configure postfix to append the correct domain on outgoing
emails:
if returndomain is first.com, I would like postfix to send it with the
virtual <a href="mailto: ... at first dot com"> ... at first dot com</a> from addy
if returndomain is another.com, I would like postfix to send it with the
virtual <a href="mailto: ... at another dot com"> ... at another dot com</a> from addy

Note that I don't want to receive email on my MX.

Comments

Re: Sending with Multiple Domain Suffixes from Single Apache Ser

By certified at 10/11/2017 - 11:08

Actually I don't know the postfix main and master config file edits required
to send outgoing mail. The default ones seem to be only local?

BTW Thanks Bill for the php script. Are you saying that will work with
default config files? Will definitely use something like that one the config
files are OK.

Re: Sending with Multiple Domain Suffixes from Single Apache Ser

By Wietse Venema at 10/11/2017 - 12:59

There is nothing about Postfix that needs editing. You just need to
set up PHP to supply the correct sender address.

Wietse

Re: Sending with Multiple Domain Suffixes from Single Apache Ser

By Bill Shirley at 10/11/2017 - 13:12

If your outbound mail isn't working, you should post the output of
postconf -n
so someone can help you.

Bill

On 10/11/2017 1:59 PM, Wietse Venema wrote:

Re: Sending with Multiple Domain Suffixes from Single Apache Ser

By certified at 10/11/2017 - 15:02

OK did some experimenting, sending to a very sophisticated email service:

Used the php command:
$result = mail($to, $subject, $message, $headers, "-f address")

With the generic posftix master and main files.
I got greylisted for 300 seconds ( <a href="http://greylisting.org" title="http://greylisting.org">http://greylisting.org</a> )
postfix retried after 300 seconds and I got rejected because the sender was
myhost.localdomain, neither of which resolve on the internet.

So I changed the main.cf file as follows:
myhostname = <a href="http://www.first.com" title="www.first.com">www.first.com</a>
mydomain = first.com
myorigin = $mydomain

That worked after getting greylisted again and postfix retried in 300
seconds.
There are some issues however:
I can't set another domain. If I send email from second.com the header file
on the recipient reads:
Return-Path: <a href="mailto:second. ... at first dot com">second. ... at first dot com</a>

Here are the values:
$to = " ... at sophisticated dot com";
$subject = "test message";
$message = "some message";
$headers = "From: ... at second dot com";

$result = mail($to, $subject, $message, $headers, "-f second.com") ;

On the second try, I don't get greylisted.

$result always seems to be 1 regardless

Bill Shirley wrote

Bill Shirley wrote

Re: Sending with Multiple Domain Suffixes from Single Apache Ser

By Wietse Venema at 10/11/2017 - 15:58

I told you to specify an email address (user@domain) form for 'address'.
That was on the line immediately after the above example.

But you failed to do what I told you.

I'm sorry, but email systems work only when you are precise.

Wietse

Re: Sending with Multiple Domain Suffixes from Single Apache Ser

By certified at 10/11/2017 - 16:22

Yup, garbage in, garbage out.

OK, so I reworked the php and voila, the sender is now <a href="mailto: ... at first dot com"> ... at first dot com</a>
or <a href="mailto: ... at second dot com"> ... at second dot com</a>

However:
Using the default main.cf I get
Return-Path: <a href="mailto: ... at second dot com"> ... at second dot com</a>
(The reply to works fine, though still getting response = 1)
But
Received: from myhost.localdomain (unknown [nnn.nnn.nnn.nnn] where nnn is my
ip

So I went back to using
mydomain = first.com
The reply to works fine but
gives: Received: from <a href="http://www.first.com" title="www.first.com">www.first.com</a> (unknown [nnn.nnn.nnn.nnn]) regardless
if sent by first or second.

Maybe that is something I have to live with?

Re: Sending with Multiple Domain Suffixes from Single Apache Ser

By Wietse Venema at 10/11/2017 - 16:31

The RECEIVED line contains Postfix myhostname value, not the email
address. And you should have proper DNS so that <a href="http://www.first.com" title="www.first.com">www.first.com</a>
resolves to the IP address, and the IP address resolves to
<a href="http://www.first.com" title="www.first.com">www.first.com</a>. This is often part of a spam check.

The "-f ... at example dot com" specifies among others the Return-Path
address, as well as the from= address in Postfix logs. This is also
the address in the MAIL FROM command in the SMTP protocol, which
is what remote hosts use for early spam blocks.

Wietse

Re: Sending with Multiple Domain Suffixes from Single Apache Ser

By certified at 10/11/2017 - 16:42

Appreciate all the help.

Have that, but I have three domains pointing to that IP from and1.com
So I guess there is nothing that can be done to get rid of
Received: from myhost.localdomain or first.com if I send it from second.com.
I guess the reply to will have to do.

Re: Sending with Multiple Domain Suffixes from Single Apache Ser

By Bill Shirley at 10/11/2017 - 15:22

You're not using an address.  man sendmail:
-f sender
    Set the envelope sender address. This is the address where delivery problems are sent to. With Postfix versions before 2.1,
the Errors-To:  message  header
    overrides the error return address.

It should be:

$result = mail($to, $subject, $message, $headers, "-f ... at second dot com")

Bill

On 10/11/2017 4:02 PM, certified wrote:

Re: Sending with Multiple Domain Suffixes from Single Apache Ser

By Bill Shirley at 10/11/2017 - 07:55

I let PHPMailer do the heavy lifting:
      $email_addresses = array(
        'first.com'=>' ... at first dot com'
        ,'another.com'=>' ... at another dot com'
      );
      if (is_set($email_addresses[$returndomain])) $from_address = $email_addresses[$returndomain];
      else die("returndomain=$returndomain not in array");

      require_once(PHPMailer);
      $mail = new PHPMailer();
      $mail->IsMail();
      $mail->IsHTML(true);
      $mail->SetFrom($from_address);
      $mail->AddAddress($to_address, $to_name);
      $mail->Subject = "Order $order_item was rescheduled";
      $mail->Body = $html_body;
      $mail->AltBody = "Order $order_item was rescheduled.\n\n$body_2nd_line";
      $mail->Send();
$to_name is something like 'Mike Smith'. Leave it out if you don't have it.

HTH,
Bill

On 10/10/2017 3:23 PM, certified wrote:

Re: Sending with Multiple Domain Suffixes from Single Apache Ser

By Wietse Venema at 10/10/2017 - 15:17

That is incorrect. The correct syntax is:

$result = mail($to, $subject, $message, $headers, "-f address")

where the address is in user@domain form.

Wietse

Re: Sending with Multiple Domain Suffixes from Single Apache Ser

By Fazzina, Angelo at 10/10/2017 - 14:54

Hi,

i am not too savvy, but i think you could do this in PHP or in Postfix.

My guess is, if you know what the "returndomain" is from using PHP code you could add it to the transport file maybe, and run postmap to update transport file ?

I assume you are pulling the "returndomain" from your PHP code to find it in the first place, if so can you just write code to insert it where you want when calling the mail(x,y,...) function ?

Is this the type of code you are doing as an example ?

$body="Hello ". $row['First_N']."\n\nPlease remember you have the following appointment scheduled for today.\n\nDate: $month/$day/$year \nTime: $time $showroom \nWith: ".$row['F_Name']." ". $row['L_Name']."\n\nFor more details on your appointment or to cancel your appointment, please go to the link below.\n\nhttp://uconn.edu/secure_per/index.php";

$from = " ... at uconn dot edu<mailto: ... at uconn dot edu>";

$headers = "From: $from";

//***********************

//PREPARE EMAIL HEADER

$headers = array ('From' => $from,

'To' => $to,

'Subject' => $subject);

//SEND EMAIL

$mail = $smtp->send($to, $headers, $body);

//THIS APPEARS TO CHECK FOR ERRORS IN THE EMAIL BEING SENT

if (PEAR::isError($mail)) {

$failed++;

}

else {

$success++;

}

//***********************

//mail($to,$subject,$body,$headers);

//echo "<P>$message</P>";

$i++;

Not sure i am any help or confusing the matter, you let me know.
-ALF

How do I configure postfix to append the correct domain on outgoing emails
from php on apache:

I have LAMP on Centos 7 and a static IP. There are several domain names
registered to that static IP:
first.com -> my static ip
another.com -> my static ip
third.com -> my static ip
My postfix MX server is also on the webserver box.

php uses the following format:
$result = mail($to, $subject, $message, $headers, "-f returndomain")

So how do I configure postfix to append the correct domain on outgoing
emails:
if returndomain is first.com, I would like postfix to send it with the
virtual <a href="mailto: ... at first dot com"> ... at first dot com</a> from addy
if returndomain is another.com, I would like postfix to send it with the
virtual <a href="mailto: ... at another dot com"> ... at another dot com</a> from addy

Details:
1. I need to send confirmation emails using php on apache to people
registering for my services from the internet
2. I need to have the correct domain suffix and return path added to the
sender's email:
<a href="mailto: ... at first dot com"> ... at first dot com</a> sending from /var/www/html/first/ needs the email headers
all consistent with mail sent from first.com
<a href="mailto: ... at another dot com"> ... at another dot com</a> sending from /var/www/html/another needs mail sent from
<a href="mailto: ... at another dot com"> ... at another dot com</a>
3. these emails go TO pretty much anywhere - google, yahoo - anywhere
visitors request confirmation to go
4. these emails come FROM my MX on the webserver DIRECTLY to their email
addy, not relayed thru google etc.
5. the machine hostname isn't any of the above domain names, it is simply
somehost

Apache sends first.com requests to /var/www/html/first/ using DocumentRoot
"/var/www/html/first/"
Apache sends another.com requests to /var/www/html/first/ using DocumentRoot
"/var/www/html/another/"

obviously the user and group will be apache:apache

So how do I configure postfix to append the correct domain on outgoing
emails:
if returndomain is first.com, I would like postfix to send it with the
virtual <a href="mailto: ... at first dot com"> ... at first dot com</a> from addy
if returndomain is another.com, I would like postfix to send it with the
virtual <a href="mailto: ... at another dot com"> ... at another dot com</a> from addy

Note that I don't want to receive email on my MX.

Re: Sending with Multiple Domain Suffixes from Single Apache Ser

By Fazzina, Angelo at 10/10/2017 - 15:03

Umm.... forget what i said about transport.

check this out

<a href="http://www.postfix.org/ADDRESS_REWRITING_README.html" title="http://www.postfix.org/ADDRESS_REWRITING_README.html">http://www.postfix.org/ADDRESS_REWRITING_README.html</a>

This sounds like your idea :

Replace an internal address by an external address. For example, replace " ... at localdomain dot local" by "isp- ... at isp dot example" when sending mail from a home computer to the Internet.

Hi,

i am not too savvy, but i think you could do this in PHP or in Postfix.

My guess is, if you know what the "returndomain" is from using PHP code you could add it to the transport file maybe, and run postmap to update transport file ?

I assume you are pulling the "returndomain" from your PHP code to find it in the first place, if so can you just write code to insert it where you want when calling the mail(x,y,...) function ?

Is this the type of code you are doing as an example ?

$body="Hello ". $row['First_N']."\n\nPlease remember you have the following appointment scheduled for today.\n\nDate: $month/$day/$year \nTime: $time $showroom \nWith: ".$row['F_Name']." ". $row['L_Name']."\n\nFor more details on your appointment or to cancel your appointment, please go to the link below.\n\nhttp://uconn.edu/secure_per/index.php";

$from = " ... at uconn dot edu<mailto: ... at uconn dot edu>";

$headers = "From: $from";

//***********************

//PREPARE EMAIL HEADER

$headers = array ('From' => $from,

'To' => $to,

'Subject' => $subject);

//SEND EMAIL

$mail = $smtp->send($to, $headers, $body);

//THIS APPEARS TO CHECK FOR ERRORS IN THE EMAIL BEING SENT

if (PEAR::isError($mail)) {

$failed++;

}

else {

$success++;

}

//***********************

//mail($to,$subject,$body,$headers);

//echo "<P>$message</P>";

$i++;

Not sure i am any help or confusing the matter, you let me know.
-ALF

How do I configure postfix to append the correct domain on outgoing emails
from php on apache:

I have LAMP on Centos 7 and a static IP. There are several domain names
registered to that static IP:
first.com -> my static ip
another.com -> my static ip
third.com -> my static ip
My postfix MX server is also on the webserver box.

php uses the following format:
$result = mail($to, $subject, $message, $headers, "-f returndomain")

So how do I configure postfix to append the correct domain on outgoing
emails:
if returndomain is first.com, I would like postfix to send it with the
virtual <a href="mailto: ... at first dot com"> ... at first dot com</a> from addy
if returndomain is another.com, I would like postfix to send it with the
virtual <a href="mailto: ... at another dot com"> ... at another dot com</a> from addy

Details:
1. I need to send confirmation emails using php on apache to people
registering for my services from the internet
2. I need to have the correct domain suffix and return path added to the
sender's email:
<a href="mailto: ... at first dot com"> ... at first dot com</a> sending from /var/www/html/first/ needs the email headers
all consistent with mail sent from first.com
<a href="mailto: ... at another dot com"> ... at another dot com</a> sending from /var/www/html/another needs mail sent from
<a href="mailto: ... at another dot com"> ... at another dot com</a>
3. these emails go TO pretty much anywhere - google, yahoo - anywhere
visitors request confirmation to go
4. these emails come FROM my MX on the webserver DIRECTLY to their email
addy, not relayed thru google etc.
5. the machine hostname isn't any of the above domain names, it is simply
somehost

Apache sends first.com requests to /var/www/html/first/ using DocumentRoot
"/var/www/html/first/"
Apache sends another.com requests to /var/www/html/first/ using DocumentRoot
"/var/www/html/another/"

obviously the user and group will be apache:apache

So how do I configure postfix to append the correct domain on outgoing
emails:
if returndomain is first.com, I would like postfix to send it with the
virtual <a href="mailto: ... at first dot com"> ... at first dot com</a> from addy
if returndomain is another.com, I would like postfix to send it with the
virtual <a href="mailto: ... at another dot com"> ... at another dot com</a> from addy

Note that I don't want to receive email on my MX.