LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 04-11-2007, 07:54 PM   #1
czamora
Member
 
Registered: May 2006
Posts: 52

Rep: Reputation: 15
Sending mail using a remote server


Hi,

I'm sending mail from my applications in PHP by using the mail() function. This function uses the local sendmail to do the work. But I would like to free the server from the burden of also being a mail server, and wanted to know if I can use the sendmail program in my other server. Or somehow make the local sendmail to relay to the other server to send the mail for it.

That is, is there a way to tell PHP, or sendmail, to use a given IP instead of local, to send mail?

Any ideas or suggestions?

Thanks a lot.

Last edited by czamora; 04-11-2007 at 07:56 PM.
 
Old 04-12-2007, 01:47 AM   #2
timmeke
Senior Member
 
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515

Rep: Reputation: 61
Configuring sendmail is not so easy. Consider using postfix as drop-in replacement instead.

According to http://www.sitepoint.com/article/advanced-email-php, you can use the standard mail() function in PhP. Just use the SMTP option to specify the name of your SMTP server (ie the name of the computer where you have a running sendmail that accepts SMTP connections from the machine that runs PhP).

By default, sendmail is probably only listening to e-mails originating from the machine it runs on. So the "burden" of running the mail server (which is running on many systems this way) is not so high. Relaying and stuff is more troublesome. Remember also that other services, like cron for one, often rely on a running MUA like sendmail that listens to the SMTP port of the localhost interface.

Have you also taken a look at:
http://phpmailer.sourceforge.net/
I haven't tried it, but it seems to promise what you need - specifying random SMTP servers to use for mailing).
 
Old 04-12-2007, 06:19 AM   #3
czamora
Member
 
Registered: May 2006
Posts: 52

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by timmeke
Configuring sendmail is not so easy. Consider using postfix as drop-in replacement instead.
I don't know, I have been using sendmail for long now and can configure lots of things with it, so changing now would imply an effort and investment that would need some justification. Why do you say postfix is better than sendmail in this case?

Quote:
Originally Posted by timmeke
According to http://www.sitepoint.com/article/advanced-email-php, you can use the standard mail() function in PhP. Just use the SMTP option to specify the name of your SMTP server (ie the name of the computer where you have a running sendmail that accepts SMTP connections from the machine that runs PhP).
Yes, that article seems to imply that you can indicate the SMTP server in php.ini also for Linux servers, but I have tried it (commenting out the sendmail_path parameter) and it didn't change anything. It looks like sendmail must not be installed for this to work (I tried stopping sendmail, but that just delayed the sending until I started it up again).

Quote:
Originally Posted by timmeke
By default, sendmail is probably only listening to e-mails originating from the machine it runs on. So the "burden" of running the mail server (which is running on many systems this way) is not so high. Relaying and stuff is more troublesome. Remember also that other services, like cron for one, often rely on a running MUA like sendmail that listens to the SMTP port of the localhost interface.
You are right there, I will need sendmail for the cron processes, and maybe just sending mail is not so consuming. In fact, does anyone know if using a remote SMTP server to send an email requires less processing and memory than sending it from the local SMTP?
 
Old 04-12-2007, 08:30 AM   #4
timmeke
Senior Member
 
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515

Rep: Reputation: 61
Quote:
Originally Posted by czamora
I don't know, I have been using sendmail for long now and can configure lots of things with it, so changing now would imply an effort and investment that would need some justification. Why do you say postfix is better than sendmail in this case?
I didn't know about your ample experience with sendmail. So forget about postfix. I prefer postfix over sendmail just because it's easier to configure.

Quote:
Originally Posted by czamora
Yes, that article seems to imply that you can indicate the SMTP server in php.ini also for Linux servers, but I have tried it (commenting out the sendmail_path parameter) and it didn't change anything. It looks like sendmail must not be installed for this to work (I tried stopping sendmail, but that just delayed the sending until I started it up again).
That's a sign that the mail gets spooled. You can use the sendmail binary (or /bin/mail) to add new mails to sendmail's queue. They'll stay in that queue until sendmail either delivers them or decides to give up trying. So, my guess is that you're still accessing your MUA somehow, even though the sendmail daemon was stopped. What you should do instead is open an SMTP connection on the remote machine (that's running sendmail) and use that to send out the mail. The SMTP protocol is fairly simple, so you could try to do that yourself, but I don't recommend it. Does the link to the sourceforge tool for sending out mails via PhP help?

Quote:
Originally Posted by czamora
You are right there, I will need sendmail for the cron processes, and maybe just sending mail is not so consuming. In fact, does anyone know if using a remote SMTP server to send an email requires less processing and memory than sending it from the local SMTP?
The sendmail daemon will sleep for most of the time (until you use it to send out a mail) and probably just checks its configuration and the mail spool from time to time. Sending out the mails themselves isn't very demanding on resources either, unless you add large attachments that consume network bandwidth.
So, in general, sendmail daemon shouldn't be a resource hog if you configure it properly and if it listens only to the SMTP port on the localhost interface (ie no relaying for other hosts). Sending mail via SMTP to a remote server uses probably less memory/cpu/resources (in fact, I do this on one of my machines via "nail"), but it won't make much difference, unless your machine is under very heavy load or sending out tons of mails.
 
Old 04-13-2007, 04:38 AM   #5
czamora
Member
 
Registered: May 2006
Posts: 52

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by timmeke
What you should do instead is open an SMTP connection on the remote machine (that's running sendmail) and use that to send out the mail. The SMTP protocol is fairly simple, so you could try to do that yourself, but I don't recommend it. Does the link to the sourceforge tool for sending out mails via PhP help?
That php class looks interesting and I'll keep it in mind for other things, but I was hoping for a solution that didn't imply code changes.

Quote:
Originally Posted by timmeke
Sending mail via SMTP to a remote server uses probably less memory/cpu/resources (in fact, I do this on one of my machines via "nail"), but it won't make much difference, unless your machine is under very heavy load or sending out tons of mails.
Isn't "nail" a mail client? Do you use it to send mail programatically from your software?
 
Old 04-13-2007, 06:19 AM   #6
timmeke
Senior Member
 
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515

Rep: Reputation: 61
nail is indeed a mail client, but you need a client to send out mail. Sendmail was originally an MUA, not a client, but the standalone sendmail application (not in daemon mode) can be used to send out mails too (like a client).

I use nail to send out reports of processing jobs (mostly scheduled via cron). The nail program is then called as part of the cron job and from scripts. nail is configured to use a different machine's postfix daemon to send out the mails. This 2nd machine is a mail server and it's contacted via SMTP directly.
 
  


Reply



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
Help pls with Mail Sending from Evo via Exim on remote server stardotstar Linux - Software 1 01-29-2007 03:19 AM
not so 'remote' mail sending Lobbezoo Linux - Networking 0 03-10-2006 09:19 AM
Sending fax from a remote box via e-mail ricky_ds Linux - Networking 0 11-11-2004 09:23 AM
Fetching mail from remote POP and sending it to local SMTP leshka_uk Linux - Software 1 02-27-2004 07:38 AM
Sending mail via Postfix smtpd through remote host requiring authentication Saffsd Linux - Networking 0 01-26-2004 05:05 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 02:48 PM.

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