Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

'mail' from command line for script use - not working. =(

Status
Not open for further replies.

linuxtricks

IS-IT--Management
May 24, 2000
111
US
Hi.

As part of the logging db project, I need to send PHP-generated email out of one of the Linux machines onto the internet. I do not want to run an smtp daemon on the linux server, I just want to be able to send a few outgoing emails. I do not want to run a service and have port 25 listening for connections.

Side note: I am using Sendmail and RedHat 7.1.

I have been playing with the 'mail' command but have not gotten the following line to work - without it error'ing or prompting me for further information (such as subject line, etc.)

mail("bogus@somedomain.com", "My Subject", "Line 1\nLine 2\nLine 3");

I have even tried that line with a space after the 'mail' command but then it inserts the entire line into the TO: field and prompts me for a subject. =(

1. Does anyone see what I am doing wrong with this command?
Thanks! ---
Try not. Do. Or do not. There is no try.
 
Hi Halfcircles,
If you have sendmail, then you already have an smtp server (used by some of the largest ISPs in the world). If you have it running, then it is already listening to port 25. If you don't have it running, mail can't go out.
Mail is for local mail only and passes everything outbound to sendmail it also receives inbout from sendmail and passes it to your pop3 server on port 110.
 
Sendmail is installed on the linux server, yes. Sendmail is *not* running - nor does it need to be running in order to send mail outbound.

i.e. sendmail is stopped (not running)
If I type the following at a command prompt:
&quot;mail user@domain.com&quot; <and hit enter>

I will then be prompted to fill in the subject and body fields - and it will send out the email.

I am really trying to ask if the following command is 'legal' - and if not, how do I fix it so it works.

[red]mail(&quot;bogus@somedomain.com&quot;, &quot;My Subject&quot;, &quot;Line 1\nLine 2\nLine 3&quot;);[/red]

You see, I am trying to send mail using a 'one-line' command without user intervention.

Many thanks! ---
Try not. Do. Or do not. There is no try.
 
ok - now I gotcha. What you will be doing then is using your ISPs smtp server. I'm not too familiar with using mail with a script but I might be able to give you a few ideas to work with. I tried using your script line and got errors also. First try using the '-n' switch to tell mail not to read the /etc/mail.rc file. This file contains lines like 'ask' and 'askcc' telling mail to promt for them. You can also use the '-s' switch to tell mail the next group of text is the subject. If your subject has spaces (i.e. more than one word), use quotes. That's about the extent of my wisdom . :eek:) It seems everthing after the recipients name was also considered another recipient. Maybe you can download a few scipts that use mail and see how they do it. I hope you whoop this puppy. Good luck. Oh, one more thing. I got syntax (token) errors when I put everything in braces.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top