PDA

View Full Version : Postfix for website sending only


dragons
2nd March 2009, 05:33
I need to configure my debian etch server, which is hosted on my lan behind a firewall/router with virtual server port forwarding and a fixed IP to the web. All site request are automatically converted to SSL.
I only need my php scripts to be able to send emails from various tasks carried out on the server websites.
I have dovecot, postfix, exim4, saslauthd installed.
1. do i need all of them and if not which ones can I remove?
2. i dont want the postfix hijacked so I only want my sites to ba able to send from it.
3.how do i setup my main.cf to acheive this.

my current main.cf is a bit messy so i need to clean it up here is the output of postconf -n


BuildFITs1:~# postconf -n
alias_database = hash:/etc/aliases
alias_maps = hash:/etc/aliases
append_dot_mydomain = no
biff = no
config_directory = /etc/postfix
content_filter = smtp-amavis:[127.0.0.1]:10024
inet_interfaces = all
mailbox_command = procmail -a "$EXTENSION"
mailbox_size_limit = 0
mydestination = BuildFITs1.buildfit.com, localhost, localhost.localdomain, localhost
myhostname = BuildFITs1.buildfit.com
mynetworks = 127.0.0.1 10.0.0.0/24
myorigin = /etc/mailname
receive_override_options = no_address_mappings
recipient_delimiter = +
relayhost =
smtp_tls_session_cache_database = btree:${queue_directory}/smtp_scache
smtpd_banner = $myhostname ESMTP $mail_name (Debian/GNU)
smtpd_recipient_restrictions = permit_mynetworks,permit_sasl_authenticated,reject _unauth_destination
smtpd_sasl_auth_enable = yes
smtpd_sasl_local_domain = Buildfits1.buildfit.com
smtpd_sasl_path = private/auth
smtpd_sasl_security_options = noanonymous
smtpd_sasl_type = dovecot
smtpd_tls_auth_only = yes
smtpd_tls_cert_file = /etc/ssl/certs/postfix.pem
smtpd_tls_key_file = /etc/ssl/private/postfix.pem
smtpd_tls_session_cache_database = btree:${queue_directory}/smtpd_scache
smtpd_use_tls = yes
virtual_alias_maps = hash:/etc/postfix/virtual
virtual_gid_maps = static:5000
virtual_mailbox_domains = $virtual_mailbox_maps
virtual_mailbox_maps =
virtual_transport = dovecot
virtual_uid_maps = static:5000


4. iam looking at this HowTo should i just follow this?

http://www.howtoforge.com/postfix_relaying_through_another_mailserver

falko
3rd March 2009, 20:05
1. do i need all of them and if not which ones can I remove?For sending you just need Postfix.

2. i dont want the postfix hijacked so I only want my sites to ba able to send from it.
3.how do i setup my main.cf to acheive this.Use inet_interfaces = 127.0.0.1 in main.cf. That way connections from outside are impossible.


4. iam looking at this HowTo should i just follow this?

http://www.howtoforge.com/postfix_relaying_through_another_mailserverIf you want to use relaying, then yes.

dragons
4th March 2009, 02:11
Thankyou for your response Falko, much appreciated, I am getting the following errors now

this one when i try to send an email from a site

postfix/sendmail[18070]: fatal: Recipient addresses must be specified on the command line or via the -t option


and this one started this morning and is constantly repeating itself every minute

this first

Mar 4 07:35:25 BuildFITs1 postfix/cleanup[22937]: DF416A7971: message-id=<20090303210525.DF416A7971@localhost>
Mar 4 07:35:25 BuildFITs1 postfix/qmgr[17620]: DF416A7971: from=<root@buildfit.com>, size=388, nrcpt=1 (queue active)


and this is constantly repeated

Mar 4 07:35:25 BuildFITs1 postfix/qmgr[17620]: warning: connect to transport local: Connection refused


my current postconf -n is

BuildFITs1:~# postconf -n
alias_database = hash:/etc/aliases
alias_maps = hash:/etc/aliases
append_dot_mydomain = no
biff = no
config_directory = /etc/postfix
inet_interfaces = 127.0.0.1
mailbox_command = procmail -a "$EXTENSION"
mailbox_size_limit = 0
mydestination = buildfit.com, localhost, localhost.localdomain, localhost
myhostname = localhost
mynetworks = 127.0.0.0/8
myorigin = /etc/mailname
recipient_delimiter = +
relayhost = milton.worldispnetwork.com
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options =
smtp_tls_session_cache_database = btree:${queue_directory}/smtp_scache
smtpd_banner = $myhostname ESMTP $mail_name (Debian/GNU)
smtpd_tls_cert_file = /etc/ssl/certs/ssl-cert-snakeoil.pem
smtpd_tls_key_file = /etc/ssl/private/ssl-cert-snakeoil.key
smtpd_tls_session_cache_database = btree:${queue_directory}/smtpd_scache
smtpd_use_tls = yes


any ideas on how to fix this thankyou again?

falko
4th March 2009, 15:04
Did you set a sender address in your PHP scripts?

dragons
4th March 2009, 16:11
this is one of my mail scripts that works on other servers i lease elsewhere

// Get Newsletter Variables
$title = $_REQUEST['title'];
$news = $_REQUEST['news'];
$sent = date('l jS \of F Y');
// Start Email
$subject = BIZ_NAME." Newsletter";
$core = nl2br($news);
$sender = OWNER." <".EMAIL.">";
// Email Newsletter Content
$message = "<html><head></head><body>\n";
$message .= "<table align='center' border='1' bordercolor='#330000' width='759' cellpadding='5' cellspacing='0'>";
$message .= "<tr>";
$message .= "<td align='center'>";
$message .= "<table align='center' border='0' width='739' cellpadding='0' cellspacing='0'>";
$message .= "<tr>";
$message .= "<td width='140' height='61'><img src='".DOMAIN.IMAGES.LOGO."' alt='".LOGO_ALT."'></td>";
$message .= "<td align='left' valign='bottom'><font color='#000066' face='Verdana, Arial, Helvetica, sans-serif' size='+1'><b>".BIZ_NAME." News</b></font></td>";
$message .= "<td align='right' valign='top'><font color='#000066' face='Verdana, Arial, Helvetica, sans-serif' size='-1'>" . date('l jS \of F Y') . "<br></font></td>";
$message .= "</tr>";
$message .= "<tr>";
$message .= "<td colspan='3' height='50' valign='middle' align='left'><font color='#000066' face='Verdana, Arial, Helvetica, sans-serif' size='+1'><b>$title</b></font></td>";
$message .= "</tr>";
$message .= "<tr>";
$message .= "<td colspan='3' align='left' valign='top'><br><font color='#000000' face='Verdana, Arial, Helvetica, sans-serif' size='-1'>$core</font><br><br></td>";
$message .= "</tr>";
$message .= "<tr>";
$message .= "<td colspan='3' align='left' valign='middle'><font color='#000066' face='Verdana, Arial, Helvetica, sans-serif'><b>".OWNER."</b><br>".BIZ_NAME." Pty Ltd</td>";
$message .= "</tr>";
$message .= "</table>";
$message .= "</td>";
$message .= "</tr>";
$message .= "</table>";
$message .= "</body></html>\n";
// Email Headers
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: $sender\r\n";
$headers .= "Reply-To: $sender\r\n";
$headers .= "X-Mailer: PHP/" . phpversion();
// Get Subscriber email list
$x = 1;
$hold = 50; // quantity of emails sent before 3 sec delay
$emails = mysql_query("SELECT email FROM subscribers");
while ($sendemail = mysql_fetch_array($emails)) {
$email = $sendemail["email"];
// Send Email
mail($email, $subject, $message, $headers);
// Prevent timeout
$x++;
if($x == $hold) { // When $x is equal to $hold, a 3 sec delay will occur avoiding php to timeout
sleep(3);
$x = 0;
}

the sender is set here but still i get the following error

Mar 5 00:27:01 BuildFITs1 postfix/sendmail[31590]: fatal: Recipient addresses must be specified on the command line or via the -t option

falko
5th March 2009, 19:16
Does $email contain a valid email address? Other than that, I'm not sure what could cause this problem...

dragons
6th March 2009, 17:26
Thanks so much for your help Falko its appreciated, do you know what the -t option is by any chance or how it should be set?

falko
7th March 2009, 16:08
-t : Read message for recipients. To:, Cc:, and Bcc: lines will be scanned for recipient addresses. The Bcc: line will be deleted before transmission.
(See man sendmail)
You can set it as $additional_parameters in PHP's mail() function: http://de.php.net/manual/en/function.mail.php