The macosxhints Forums

The macosxhints Forums (http://hintsforums.macworld.com/index.php)
-   UNIX - Newcomers (http://hintsforums.macworld.com/forumdisplay.php?f=15)
-   -   Sendmail => AppleMailServer (http://hintsforums.macworld.com/showthread.php?t=12223)

l008com 05-30-2003 12:08 AM

Sendmail => AppleMailServer
 
I run OS X 10.2 Server on my server, and I use Apple's built in mail server. It works absolutely perfect for me, no problems whatsoever! Where I do have problems is PHP. It sends emails, as far as I can tell, by directly communicating with sendmail. I don't use sendmail. What I need to do is get sendmail to automatically forward all email to my AMS so it can be delivered. The way it works right now, PHP can send emails to ME, which is always a local user on the mail server, but it can't send anything OUT. I post this in this forum because I'm not great with the command line and I know how impossible sendmail is to configure so if I have to edit sendmail stuff, you're going to have to talk really slow! :D

Archangel 06-02-2003 06:30 PM

I believe your PHP.ini file has something called 'sendmail_path=' You can set that equal to the program you are using along with the necessary parameters. However, I'm not sure if it works the same way at all.

You could also do it manually yourself, since mail() is, after all, just a wrapper.

Here is an example of a function I wrote to use mail rather than sendmail. You could just code something similar that would work.

Code:

function sendmail($to='', $subject='', $message='')  {
  $fd = popen("/usr/bin/mail  -s \"$subject\" $to", 'w');
 
  fputs($fd, "\n");
  fputs($fd, $message);
  pclose($fd);
}

this is the equivalent to saying on the command line:
>/usr/bin/mail -s "subject" address < message


l008com 06-22-2003 09:29 PM

Anyone know of a way to do it just without changing the scripts? I have lots of phps running, including two vBulletins, and I don't wanna hack through all of the files and any future scripts i might get to make it work.

kfaulhaber 06-22-2003 10:33 PM

php comminuicates to sendmail through the command line, even if you are using mail() and not writing your own mailer equilivant. unless AMS can be accessed through the command line, or you write your own php module to communicate to AMS, your best bet is to either configure sendmail to deliver the mail or configure sendmail to comminucate directly with AMS.

The bottom line is that you probably don't need to have php deliver mail through AMS. Sendmail is more than capable of the job. And you won't need to make any modifications to php or any of your scripts.

l008com 06-22-2003 10:35 PM

Quote:

Originally posted by kfaulhaber
...configure sendmail to comminucate directly with AMS.
Yeah thats exactly what I wanna do! I tried before with absolutely no luck. Maybe someone here knows more about it than the person that was helping me before?

kfaulhaber 06-22-2003 10:42 PM

before I suggest how you would go about getting sendmail to talk to AMS, why would you not want to have sendmail do the delivery, rather than passing it on to AMS? the reason I ask is that in either case you have to do some messing with sendmail configuration.

l008com 06-22-2003 10:44 PM

Because I already have AMS working perfectly as my own mail server, and I read that Mac OS Updates can often mess with sendmail. It just seems easier and quicker to have sendmail just pass to AMS rather than maintaining two full functionaly mail servers at once, you know what im saying?

kfaulhaber 06-23-2003 12:00 AM

It is true that Apple's updates can mess up Sendmail, but that can be worked around. Since in either case, you will be using Sendmail at some point in time, it makes no difference whether Sendmail delivers to AMS or delivers directly; if Sendmail is broken, it won't deliver, period. The only real advantage to having Sendmail relay directly to AMS is if you have to change your delivery path, you only have to alter AMS.

As a side note, if the only php scripts that you currently use to send mail are your boards, you should see if they have an option to send mail through SMTP rather than Sendmail, as then you won't need Sendmail at all.

Since I have never had one mail server talk to another mail server running on the same machine, and since I don't have AMS myself, what follows is pure theory:

On your machine is a file:
Code:

usr/share/sendmail/conf/cf/generic-darwin.mc
copy it somewhere you have write access to and give it a meaningful name, since you will want to save it somewhere in case you need to make changes later...

Open it up in your favorite text editor and add this line:
Code:

define(`confDONT_BLAME_SENDMAIL', `GroupWritableDirPathSafe')
This works around what Apple's updates break and makes Sendmail a little insecure. But since you are not running Sendmail as a service, it should make no difference security-wise.

Right now, if you have a valid domain name, Sendmail is ready to deliver mail. If your machine doesn't have a valid domain name, add the line:
Code:

define(`confDOMAIN_NAME', `VALID.DOMAIN')
Where VALID.DOMAIN is the name you want Sendmail to deliver as. If you do have a valid domain, you can still use this to have it report as something else, as long as something else resolves.

Here is where things go theoretical.
If you want Sendmail to relay through AMS rather than delivering directly, add the following:
Code:

define(`SMART_HOST',`smtp:localhost')
This tells Sendmail to open port 25 to localhost, so as long as AMS accepts connections on port 25 from localhost from whatever domain sendmail is reporting as, and as long as you never have sendmail running as a daemon, everything should be golden.

Now, to convert your config file into something sendmail understands, you need to do the following on the command line from wherever your working config file is:
Code:

> m4 /usr/share/sendmail/conf/m4/cf.m4 meaningful_name.mc > submit.cf
And to put the new submit.cf where sendmail can find it (after moving the old submit.cf out of the way):
Code:

> cd /etc/mail/
> sudo mv submit.cf submit.cf.old
> sudo mv /path/to/new/submit.cf .

Now, if everything works as well as it does in my head, you should be able to do the following:
Code:

> mail -s 'some subject' your@email.address
And the email should show up in your inbox, and if you look at the headers, you should see it was routed through your AMS.

Like I said, this is all theory, since I can't try it myself.

l008com 06-23-2003 12:05 AM

Before i try i need you to clear up one thing. My machine is on a quasi dynamic ip, which changes usually once a year or less. I have 4 domain names that sendmail is going to be forwarding mail as, but my ip reverse dns's to my isp's own long name, not one of those domain names. How would I enter this info into the mix?

kfaulhaber 06-23-2003 12:13 AM

You can either specify a domain with confDOMAIN_NAME or leave that option out and it will use your isp's name. You only need to specify a domain name if your machine can't resolve itself or if you want to force a domain name. As long as php always specifies a FROM header when passing mail to sendmail, no one will ever see the domain name unless they look at the headers. If no FROM is specified, then the end user sees a 'FROM: www@whatever.domain.sendmail.thinks.it.is'

l008com 06-23-2003 12:14 AM

So if i skip it and AMS is set to accept from my servers own internal IP then everything should work nice?

kfaulhaber 06-23-2003 12:19 AM

as long as AMS accepts mail from your isp assinged name, then yes, in theory. I don't know how AMS restricts connections. Spam protection and all... You can try without and see what happens. If the mail goes through, all is good. If not, look at the logs and see if it was denied or if there was some other connection failure.

l008com 06-27-2003 10:47 PM

OK it doesn't seem to be working. I did a search and i couldn't find any new submit.cf files? Where is it supposed to be at? I left it as is thinking maybe it automatically replaced the old one but i tried what you said to send an email and nothing seemed to happen at all, like its timing out or something. Any ideas?

kfaulhaber 06-27-2003 11:32 PM

are you looking for the submit.cf you created? if the end of the m4 command was "> submit.cf" it will be in whatever your working directory was when you issued the command. it won't automatically replace the old one. the old one exists at /etc/mail/submit.cf and that is the only place sendmail will look for it.

as far as where your mail went, you can type
Code:

> sendmail -bp
to see if it is still in the mail queue. if the queue is empty, your email left the machine. to see if there were any errors in delivery, check the log:
Code:

> tail /var/log/mail.log
and look for any errors or stat=sent if it was delivered. if the mail was bounced back to you and you sent it from the command line, type "mail" and it will either say "no mail for USERNAME" or print the headers of any new mail in your mailbox.

l008com 06-30-2003 09:24 PM

OK This is what happens, I make the mc file just like you said, and when I try to make the submit.cf file, this is what I get, I have no idea what it means.
Code:

[blah]jon% > m4 /usr/share/sendmail/conf/m4/cf.m4 customamsforward.mc > submit.cf
Ambiguous output redirect.

And a full search of the HD turns up only the one original submit.cf file, no new one.

kfaulhaber 06-30-2003 10:15 PM

ok, i see what is going on. you need to drop the '>' at the beginning, i was just using those to designate what you type on the command line. the command starts with 'm4'. from your prompt, it would look like:
Code:

[blah]jon% m4 /usr/share/sendmail/conf/m4/cf.m4 customamsforward.mc > submit.cf
that goes for anything else i posted.

l008com 06-30-2003 10:32 PM

OK now i run it and from some places like the sendmail.conf.m4 directory, i get a "Permission denied" error, even if I sudo it. If I run it form the root of the drive, so the submit file would 'come out' there, i get a "m4: Command not found" error
:mad: I'm not liking this one bit!

kfaulhaber 06-30-2003 10:40 PM

without using sudo, run the m4 command in your home (~/) directory. I can't imagine why m4 woud be an unknown command, but if it keeps that error up, try tacking /usr/bin/ to the beginning of the m4 command (/usr/bin/m4 ...).

l008com 06-30-2003 10:46 PM

Quote:

Originally posted by kfaulhaber
without using sudo, run the m4 command in your home (~/) directory. I can't imagine why m4 woud be an unknown command, but if it keeps that error up, try tacking /usr/bin/ to the beginning of the m4 command (/usr/bin/m4 ...).
Did that, still M4: Command Not Found, also /usr/bin/m4 doesn't exist. I have the full BSD package installed, along with I'm pretty sure the Dev tools... although you know what, i don't think I do have the Dev tools installed on the server.

l008com 06-30-2003 10:48 PM

that sounded kinda confusing, to clarify, i DO have the BSD subsystem installed, I do NOT have the Devtools installed.

kfaulhaber 06-30-2003 10:54 PM

that could be why. type 'which m4' and if it returns a path to m4, then there you go. if it returns 'command not found' then you need the developer tools. i didn't think to ask that.

mervTormel 06-30-2003 10:56 PM

m4 is of the dev tools:
Code:

$ grepbom /usr/bin/m4
............................/usr/bin/m4 97,892  Fri Nov 22 15:07:35 2002
  ====> /Library/Receipts/DevTools.pkg/Contents/Archive.bom


l008com 06-30-2003 10:56 PM

:eek: It said /usr/bin/m4 !!!!!!

l008com 06-30-2003 10:58 PM

Keep in mind I'm running 10.2 Server, not "standard" 10.2

kfaulhaber 06-30-2003 10:59 PM

well, now that's pretty funny. we've confirmed that m4 is part of the dev tools, and yet you haven't installed them and your machine thinks it's got it. try "ls -al /usr/bin/m4" and see if is really there.

l008com 06-30-2003 11:01 PM

Result
Code:

-rwxr-xr-x  1 root  wheel  97892 Dec 19  2002 /usr/bin/m4

kfaulhaber 06-30-2003 11:10 PM

well, that confirms that you do indeed have m4 installed, which means that all or part of the dev tools got installed at some point. and none of this is affected by having 10.2 Server. try "m4 --help" and it should print a quick list of options.

l008com 06-30-2003 11:14 PM

I'm so dumb. I didn't notice that I was no longer SSH'd into my server, it must have timed out or something? Well my server does indeed NOT have m4 installed, so I need the dev tools for that? I'll install that tomorrow night and pick up this thread where we left off. You've been very helpful so far, please keep on helping :D

kfaulhaber 06-30-2003 11:19 PM

:)
i've done the opposite. issued commands on local files over SSH! good luck.

l008com 06-30-2003 11:21 PM

I wish SSH had like, colors or something :-D

kfaulhaber 06-30-2003 11:31 PM

never tried this myself, but someone else has a way to do just that:

http://www.macosxhints.com/article.p...30213071650891

mervTormel 06-30-2003 11:32 PM

why not just copy the m4 executable to your server rather than install the entire dev tools?

l008com 06-30-2003 11:34 PM

because I don't wanna get caught short handed every again.

mervTormel 06-30-2003 11:38 PM

... to be able to move forward and focus on your current problem. you can install the dev tools later.

l008com 07-01-2003 11:46 PM

OK i did installed the Dev tools and ran the m4 thing and got the file and everything worked great. But it appears that I still can't send email to anyone but myself, though sendmail. :-( Now what?

kfaulhaber 07-02-2003 12:07 AM

1) how did you configure sendmail?
2) what showed up in /var/log/mail.log?
3) what does 'sendmail -bp' say?

l008com 07-02-2003 12:10 AM

I configured it using exactly what you said in the beginning, the log from today looks like so...
Code:

Jul  1 03:15:01 PowerMac-Dual533 sendmail[1168]: NOQUEUE: SYSERR(root): /etc/mail/sendmail$
Jul  1 03:15:01 PowerMac-Dual533 sendmail[1168]: gethostbyaddr(192.168.0.2) failed: 3
Jul  1 03:15:01 PowerMac-Dual533 sendmail[1168]: gethostbyaddr(10.0.2.1) failed: 3
Jul  1 03:15:02 PowerMac-Dual533 sendmail[1168]: gethostbyaddr(10.0.0.1) failed: 3

and 'sendmail -bp' gives me...
Code:

johnm% sendmail -bp
/etc/mail/sendmail.cf: line 93: fileclass: cannot open '/etc/mail/local-host-names': Group writable directory


kfaulhaber 07-02-2003 12:25 AM

see if this makes a difference: copy submit.cf to sendmail.cf:
Code:

sudo mv /etc/mail/sendmail.cf /etc/mail/sendmail.cf.old
sudo cp /etc/mail/submit.cf /etc/mail/sendmail.cf

i did this so long ago i forgot about the sendmail.cf file.

l008com 07-02-2003 12:36 AM

still nothing

kfaulhaber 07-02-2003 12:57 AM

first, make sure there are no sendmail processes running. those processes won't see the changes. after that, check the logs and sendmail -bp again. if you are still getting the same errors, send the .mc file you used.

l008com 07-02-2003 12:58 AM

too tired, ill have to pick this up again tomorrow, until then...

l008com 07-31-2003 11:43 PM

OK I've been away for a while but now I'm back, can you give me your email address and I'll send you that file?

kfaulhaber 08-01-2003 09:48 AM

kjf@mac.com

send me /var/log/mail.log too


All times are GMT -5. The time now is 10:25 PM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.