Override Mailx Command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Override Mailx Command
# 1  
Old 12-05-2012
Override Mailx Command

Hello All,

I am working on a project where the requirement is override mailx command in such way that, instead of sending mailing to email addresses coded in codes, it should send mails to one common email address at run time.
We do not intend to change the email addresses in codes.

This problem was temporarily resolved by setting up aliases in .mailrc file. But I need to take care of any future new email addresses for which everytime I have to define new alias.

I thought of overriding mailx command to a function with name as mailx() in .profile which does this for me. But in that function I will not be able to read the attachment file as in below example:-
Code:
cat $filename |uuencode abcd.xls | mailx -s "Subject" $eml_adrs

I want this command to send the mail to my email address at place of $eml_adrs with AS IS body text and attachment. at RUNTIME.

Is there any way?

Thanks in advance. Looking Forward.

Regards
Shubham

Last edited by Franklin52; 12-14-2012 at 03:33 AM.. Reason: Please use code tags for data and code samples
# 2  
Old 12-07-2012
Rename mailx and put a shell script in its place that sends mail to you? What about other mail clients that talk to sendmail or port 25 or connect off host to some other system port 25? You probably need a rewrite rule, at least for your local sendmail daemon.
# 3  
Old 12-07-2012
Hello,

Thanks for the suggestion.

The main problem with overriding or renaming mailx is how to read the attachment file from the origional command line as
Code:
cat abcd.txt | uuencode abcd.txt | mailx -s "subject" abc@xyz.com

How in the shell script I can read the attachment file - abcd.txt so that I can send the same mail to my email address at place of abc@xyz.com.

Regards
Shubham

Last edited by Franklin52; 12-14-2012 at 03:33 AM.. Reason: Please use code tags for data and code samples
# 4  
Old 12-07-2012
It is just stdin. Your shell script can copy that by calling the real mailx to your address. .profile functions can copy stdin, too, but that is more fragile -- have to ensure exec is from shell, .profile is run, function is not bypassed by absolute path.
# 5  
Old 12-07-2012
Yes, its just stdin, but I can read stdin by read command as

while read -r line
do
????????????
done

but how to copy the file attached is where I am struggling.

Also, I am not able to understand your last suggestion. It will be very helpful i you could explain by a simple example.

Thanks
# 6  
Old 12-13-2012
Not so much having the shell read stdin, as pasing the inherited stdin to a child like the real mailx but to your address, perhaps with a subject expanded to show where it was going.
# 7  
Old 12-13-2012
Thanks for the suggestion.

Today only I wrote a C code with the name of the binary as mailx only. This code is reading the arguments which are provided to real mailx command inside codes and then I am reading stdin to a file. If there is some attachment with uuencode , then writing it to a file as a part of stdin.

What it does is, it write the uuencoded contents in between begin and end. So I will extract all these contents and mark it as to be attached to mail. Rest part is mail body. Hence now I have attached part and mail body part read, and then with the help of arguments (-r... -s....), I am sending mail to me with arguments, attachments stdin contents and mail body stdin contents.

It is working well. But now next challenge is, what if stdin attachement file is zipped?

Any idea?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. HP-UX

Help with Mailx command

I need to do below in mailx : 1. to list 2. CC list (I am using tilde command for this) 3. -r option 4. attach .csv file Below is the command i am using : ( echo '~c abc@xyz.com'; cat mailtext.txt; uuencode attach.csv attach.csv) | mailx -s "${SUBJECT}" -r "abc@xyz.com" -m ${MAIL_LIST}... (4 Replies)
Discussion started by: ManOfSteel
4 Replies

2. UNIX for Dummies Questions & Answers

Override options of rm command

How can i override options of rm command ?? and how can i implement my own options when we delete file using rm commad it will not delete file it has to move some folder....plz suggest some solution. (10 Replies)
Discussion started by: arun508.gatike
10 Replies

3. UNIX for Dummies Questions & Answers

mailx command

Hi, I am seeing that this command is sending mail even when the nawk command in untrue ( does not have any output ). I only want it to send mail, where it goes above the threshold, and has some output. nawk -F'(MOD dn="uid=)|(DEL dn="uid=)|' '/(MOD dn="uid=)|(DEL dn="uid=)/... (2 Replies)
Discussion started by: john_prince
2 Replies

4. Solaris

mailx command

Dear all, Every time if i use mailx it is asking for entering the From Address. I want to set it in some place, So that it will take it by default whenever we send mails. Pl help on this. Regards JeganR (2 Replies)
Discussion started by: jegaraman
2 Replies

5. Solaris

Mailx command

HI All, I have an unix server , where sendmail command works for sending mail. But if i use mailx command it is not working. Is there any specific settings needed for this. Kindly help. Thanks and Regards Rj (1 Reply)
Discussion started by: jegaraman
1 Replies

6. Shell Programming and Scripting

Mailx: How to send a attachment using mailx command

Hi All, Can anyone please provide the command for sending an mail with attachment using mailx command. Thanks in Advance :) Regards, Siram. (3 Replies)
Discussion started by: Sriram.Vedula53
3 Replies

7. UNIX for Advanced & Expert Users

mailx command

hi, i want to pass a unix variable as the subject of the mail alongwith a string. My part of code is as below.. week_end_dt=`sqlplus -s rsamart@martdev.world/rsamart<<EOF SET FEED OFF; SET TIMING OFF; SET HEADING OFF; SET PAGESIZE 500; SET LINESIZE 1000; select... (14 Replies)
Discussion started by: Jalkukdi@10
14 Replies

8. Shell Programming and Scripting

mailx command help

Dear All, I need to send a mail to a group ( the address of which is in a .profile file)..My basic mailing functionality isn't working. When i try to run mailx -s "Hello" abc@xyz.com the command does not return to the prompt an runs infinitely. Request you to help me out here along with... (3 Replies)
Discussion started by: kaushikraman
3 Replies

9. UNIX for Advanced & Expert Users

Mailx Command

Hi, mailx -s "hi" -r "abc@yahoo.com" aaa@yahoo.com<<EOF Hi, ~<!uuencode a.txt a.txt EOF the above code is sending mails, but attachment is not going instead i just get like below ~<!uuencode a.txt a.txt Thanks. (3 Replies)
Discussion started by: shahnazurs
3 Replies

10. Shell Programming and Scripting

mailx command

Hi friends, i have seen the following line in some unix shell script . can some one explain me what exactly the statement is meant for ? ========================================================= mailx -s " Master Data Transmission Report for $TODAY at $TIME " < /etc/tr/tmp/$tmplog... (5 Replies)
Discussion started by: sveera
5 Replies
Login or Register to Ask a Question