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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MAILING QUESTION 2

Status
Not open for further replies.

PrgrmsAll

Programmer
Apr 8, 2003
180
US
Hello:
I am new to UNIX (HP) and have what might be a simple question. (I have browsed the other mail related postings as well as the FAQs and none have been exactly what I want.)

I need to, in a job (not at the prompt), to send an email. Using the 'mail' command i get half way there, except it seems to be interactive and the job doesn't complete until I hit [CTRL]+[D]. Can this be written into the code? As a VB Programmer, I am thinking along the lines of a SendKeys command ....

Any suggestions would be greatly appreciated.

Thank you in advance.

CH
 
Chrishunter21,

I'm not exactly sure what you are looking for, but you can try something like the following:

echo "This is the body of the e-mail" | mailx -s "This is a test e-mail" user@domain.com

You can just add this to a script and mail whatever you would like.

Hope this helps.

John
 
You can also read a file into the mail command.

mailx -s "TESTING" user@domain.com <my_mail_file.txt

John
 
thank you, johngiggs. both seem to work. the only other thing i am having issues with, however, is getting multiple recipients to work, i.e. a CC and/or BCC. any suggestions?
 
Chris,

from man mailx

-b bcc Set the blind carbon copy list to bcc. bcc should be enclosed in quotes if it contains more than one name.

-c cc Set the carbon copy list to cc. cc should be enclosed in quotes if it contains more than one name.

You can also send to multiple recipients by using the mail command as follows:

mailx -s "TESTING" user@domain.com user2@domain.com <my_mail_file.txt

John
 
Actually, I think the -c is from Solaris, not HP-UX. I believe it is the ~c flag for cc and ~b for bcc.

John
 
Urm, actually ~b and ~c are not "flags". They need to be included in the body of the message, e.g...
[ignore]
(
echo "~b blindcopy1@mail.com blindcopy2@mail.com"
echo "~c carboncopy@mail.com etc@mail.com"
echo "This is the body of the e-mail"
) | mailx -s "This is the subject" user1@mail.com user2@mail.com
[/ignore]



 
Can someone briefly explain the difference in the 'mail' -v- 'mailx' commands? Is it something to do with interactivity?
 
i am trying, unsuccessfully, to add a Cc: to an email. the code from a job is pasted below. the commented lines are efforts that did not work for me. can anyone show me where i am going wrong or offer me a better way to add a Cc:?

thank you in advance!

= = = = = = = = = = = = = = =

MESSAGE=email1.txt
+1 FROM=me@abc.com
+2 TO=123@abc.com
+3 # CC=xyz@abc.com
+4 SUBJECT="File Transfer"
+5
+6 # echo ~c xyz@abc.com
+7 echo "From: $FROM" > $MESSAGE
+8 echo "To: " >> $MESSAGE
+9 echo "Subject: $SUBJECT" >> $MESSAGE
10 echo "The requested files have been successfully transferred" >> $MESSAGE
11 echo "to the designated directory. They were processed on " >> $MESSAGE
12 echo "Monday May 10, 2004 at 0900. No errors were reported." >> $MESSAGE
13 echo "" >> $MESSAGE
14 echo "Thank you." >> $MESSAGE
15 echo "" >> $MESSAGE
16 echo "IS" >> $MESSAGE
17 /usr/sbin/sendmail $TO < $MESSAGE

= = = = = = = = = = = = = = =
 
PrgrmsAll,

Uncomment out the echo ~c xyz@abc.com and output it to $MESSAGE and change:

/usr/sbin/sendmail $TO < $MESSAGE

to

mailx -s $SUBJECT $TO < $MESSAGE

So you should have...

Code:
MESSAGE=email1.txt
+1  FROM=me@abc.com
+2  TO=123@abc.com
+3  # CC=xyz@abc.com
+4  SUBJECT="File Transfer"
+5  
+6  echo ~c xyz@abc.com > $MESSAGE
+7  echo "From: $FROM" >> $MESSAGE
+8  echo "To: " >> $MESSAGE
+9  echo "Subject: $SUBJECT" >> $MESSAGE
10  echo "The requested files have been successfully transferred" >> $MESSAGE
11  echo "to the designated directory.  They were processed on " >> $MESSAGE
12  echo "Monday May 10, 2004 at 0900.  No errors were reported." >> $MESSAGE
13  echo "" >> $MESSAGE
14  echo "Thank you." >> $MESSAGE
15  echo "" >> $MESSAGE
16  echo "IS" >> $MESSAGE
17  mailx -s $SUBJECT $TO < $MESSAGE
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top