Content of attachment is displaying along with subject in mailx


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Content of attachment is displaying along with subject in mailx
# 1  
Old 09-21-2016
Content of attachment is displaying along with subject in mailx

Hi All,
I want to send the csv to an email address.
I have tried the below two approaches.

Approach1: Got error -ksh: uuencode: not found
Code:
$ uuencode test_file.csv test_file.csv | mailx -s "Attaching test" msdc.kiran@gmail.com </usr/home/test_file.csv
-ksh: uuencode: not found

Approach2:
Code:
$ mailx -s "Attaching test" msdc.kiran@gmail.com < /usr/home/test_file.csv

In Approach2 I have received mail successfully but content of the csv file is displaying along with subject of the email.
But I want it as attachment.The content of the file should not be displayed until unless if we open the file.

Please help me.

Thanks in advance.

Last edited by rbatte1; 09-21-2016 at 06:43 AM.. Reason: Added ICODE tags for message and correcting spelling
# 2  
Old 09-21-2016
Hello ROCK_PLSQL,

Could you please try following and let me know if this helps you.
Code:
####Define function here to send email.
sendmail_touser() {
export MAILPART=$(uuidgen)
export MAILPART_BODY=$(uuidgen)
{
        echo "From: $MAILFROM"
        echo "TO: $MAILTO"
        echo "Subject: $SUBJECT"
        echo "MIME-Version: 1.0"
        echo "Content-Type: multipart/mixed; boundary=\"$MAILPART\""
        echo "--$MAILPART"
        echo "Content-Type: multipart/alternative; boundary=\"$MAILPART_BODY\""
        echo ""
        echo "--$MAILPART_BODY"
        echo "Content-Type: text/html"
        echo "Content-Disposition: inline"
        cat $Input_file_to_be_printed_in_BODY
        echo "--$MAILPART_BODY--"
        echo ""
        echo "--$MAILPART"
        echo "Content-Type: text/plain; name=testCPUID3.txt"
        echo "Content-Transfer-Encoding: base64"
        echo "Content-Disposition: attachment; filename=$Input_file_needed_to_be_attached"
        echo ""
        base64 $Input_file_needed_to_be_attached
        echo "--$MAILPART--"
} | /usr/sbin/sendmail -t
}
####Call function here to send email.
sendmail_touser

You could define values of variables above like MAILFROM,MAILTO,SUBJECT,Input_file_to_be_printed_in_BODYandInput_file_needed_to_be_attached as per your need.

Thanks,
R. Singh
# 3  
Old 09-21-2016
Hi Singh,

Thanks for your script.
I have replaced some of the variables.

Code:
MAILFROM msdc.kiran@gmail.com
MAILTO msdc.kiran@gmail.com
SUBJECT test_mail
Input_file_needed_to_be_attached test_file.csv

However I got below error.
Code:
test_mail.ksh[26]: /usr/bin/sendmail: not found [No such file or directory]

Pease help me.

Code:
cat > test_mail.ksh
sendmail_touser() {
export MAILPART=$(uuidgen)
export MAILPART_BODY=$(uuidgen)
{
        echo "From: msdc.kiran@gmail.com"
        echo "TO: msdc.kiran@gmail.com"
        echo "Subject: test_mail"
        echo "MIME-Version: 1.0"
        echo "Content-Type: multipart/mixed; boundary=\"$MAILPART\""
        echo "--$MAILPART"
        echo "Content-Type: multipart/alternative; boundary=\"$MAILPART_BODY\""
        echo ""
        echo "--$MAILPART_BODY"
        echo "Content-Type: text/html"
        echo "Content-Disposition: inline"
        #cat $Input_file_to_be_printed_in_BODY
        echo "--$MAILPART_BODY--"
        echo ""
        echo "--$MAILPART"
        echo "Content-Type: text/plain; name=testCPUID3.txt"
        echo "Content-Transfer-Encoding: base64"
        echo "Content-Disposition: attachment; filename=test_file.csv"
        echo ""
        base64 test_file.csv
        echo "--$MAILPART--"
} | /usr/bin/sendmail -t
}
sendmail_touser

ksh  test_mail.ksh

Thanks.
# 4  
Old 09-21-2016
Quote:
test_mail.ksh[26]: /usr/bin/sendmail: not found [No such file or directory]
can you run this command and see it matches with above call ?
Code:
which sendmail

For ex, i have the utility in /usr/sbin/sendmail

Also, check PATH vairable as well?
Code:
echo $PATH

# 5  
Old 09-21-2016
Hi,

Thanks for your suggestion.

I have executed
Code:
which sendmail

According to that I have changed this part
Code:
/usr/bin/sendmail -t

to
Code:
 /usr/sbin/sendmail -t

The script is executed successfully but not received mail.
Any thing else is wrong.
Please help me.

Thanks.
# 6  
Old 09-21-2016
Hello ROCK_PLSQL,

Without showing us what changes you have made and what is running and what is not or any error messages you are getting, it is impossible for anyone to tell what's happening. Please let us know complete details with code tags.

Thanks,
R. Singh
# 7  
Old 09-21-2016
Hi,

Please write with more details as RavinderSingh13 said.

However, my apologizes to you to divert to your first post/command .

Seems mailx itself has option to attach a file.
Code:
man mailx
-a file
              Attach the given file to the message.

Here is what i tried and it worked successfully.
Code:
mailx -s "hello" -a 123.csv myaddress@domainxyz.com <<< hi

I got a mail as follows:
"hi" in body message with subject "hello" and file attachment "123.csv".
i could read 3 lines of its contents.

Please give a try.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Variable not displaying in subject line of mailx email

Hi Newbie here with first post. I've got a shell script (ksh) whereby I run a SQL*Plus script and output the results to a file. I then check the output file in an if statement that looks like this: if ]; then export GAPNUM=`awk '{print $4}' $OUTFILE` if ] then mailx -s... (10 Replies)
Discussion started by: ltzwoman
10 Replies

2. Shell Programming and Scripting

Mailx with attachment and html content

Hi, Please see my code below i'm trying get an email send with attachment and html content in the body. Using the code below will put the encoding for attachment in the body as well SUBJECT="$(echo "XPI Monitoring "${tcnt}" transactions waiting \nContent-Type: text/html")" cat... (3 Replies)
Discussion started by: bhoshan
3 Replies

3. Shell Programming and Scripting

Facing issues with Content-Type:application/x-download Content-Disposition:attachment

I am in the process of developing a perl cgi page. I had succeeded in developing the page but there are few errors/issues with the page. description about cgi page: My CGI page retrieves all the file names from an directory and displays the files in drop down menu for downloading the... (5 Replies)
Discussion started by: scriptscript
5 Replies

4. Shell Programming and Scripting

Mailx attachment not getting attached.

Hi Friends, Please help me with this problem. I have a number of split files in a directory. each split files has pdf filenames in it. pdf files are also in the same directory. I send a mail for each split files present in the directory with the pdf file mentioned in the file. I have... (4 Replies)
Discussion started by: jcebalaji
4 Replies

5. Solaris

mailx with attachment

Hi, When i used below command, i am able to send mail mailx -s "Testing mail working or not " babu.sudhakar@ymail.com" but if i want send attachment with mail,which syntax i need to follow to send a file as attachment. (3 Replies)
Discussion started by: sridhardwh
3 Replies

6. HP-UX

mailx with -m attachment corrupted

mailx with -m command sending emails with attachments correctly to all users except users who have email on microsoft exchange server. They are receiving attachments as garbled text in mail body (5 Replies)
Discussion started by: sankalpag
5 Replies

7. 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

8. Shell Programming and Scripting

Adding an attachment as an attachment to mailx

I don't want the attachment embedded in the mail. I would like a file attached. When I do mailx -s "Report, `date +'%D %r` " -r "Notifications" bob@bob.com < /usr/local/bin/myreport.log> /dev/null It gets embedded in my email. I want a file attachment. How do I do that? (2 Replies)
Discussion started by: guessingo
2 Replies

9. Shell Programming and Scripting

Attachment getting corrupted using mailx

Hi , Whenever I try to mail to external email Id's ( like yahoo , gmail etc ) the attachment is getting corrupted. In the script I am using the mailx option as follows:- (cat $temp_mail; uuencode $temp_info_csv $temp_info_csv)|mailx -s "Report" -m $c_mail_id; where $temp_mail is the... (1 Reply)
Discussion started by: Sandipan
1 Replies

10. UNIX for Dummies Questions & Answers

mail or mailx attachment

I have used the forum to determine the format required to send attachments from hp-ux 11. the problem I have is that using mailx does not attach the file, but subsititing mailx for mail on the command line attaches the file but i'm not able to specify a subject? The attachment has been convert... (3 Replies)
Discussion started by: brettmartin99
3 Replies
Login or Register to Ask a Question