Send multi content email using sendemail utility


 
Thread Tools Search this Thread
Operating Systems Solaris Send multi content email using sendemail utility
# 1  
Old 04-02-2015
Send multi content email using sendemail utility

Hi Guys,
I am trying to send email from solaris server using sendemail utility. I want to send multi content email. For example, i want to send email body with html file and a attachment of txt file. I using below code but the html not render correctly in email body.

Code:
(
echo "To: tharmendran@carsem.com.my"
echo "Subject: Testinglah"
echo "MIME-Version: 1.0"
echo 'Content-Type: multipart/mixed; boundary="-q1w2e3r4t5"'
echo
echo '---q1w2e3r4t5'
echo "Content-Type: text/html"
echo "Content-Disposition: inline"
cat testtharmen2.html 
echo '---q1w2e3r4t5'
echo 'Content-Type: application; name="'$(basename /export/home/oracle/testCPUID3.txt)'"'
echo "Content-Transfer-Encoding: uuencode" 
echo 'Content-Disposition: attachment; filename="'$(basename /export/home/oracle/testCPUID3.txt)'"'
uuencode testCPUID3.txt $(basename testCPUID3.txt)
echo '---q1w2e3r4t5'
)| /usr/sbin/sendmail tharmendran@carsem.com.my

# 2  
Old 04-02-2015
I would suggest base64 instead of uuencode. Also specify the right Content-Type for attachment.
Code:
export MAILPART=$(uuidgen)
export MAILPART_BODY=$(uuidgen)

{
        echo "From: from@domain.com"
        echo "To: to@domain.com"
        echo "Subject: Testinglah"
        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 testtharmen2.html
        echo "--$MAILPART_BODY--"
        echo ""
        echo "--$MAILPART"
        echo "Content-Type: text/plain; name=testCPUID3.txt"
        echo "Content-Transfer-Encoding: base64"
        echo "Content-Disposition: attachment; filename=testCPUID3.txt"
        echo ""
        base64 /export/home/oracle/testCPUID3.txt
        echo "--$MAILPART--"
} | /usr/sbin/sendmail -t

uuidgen

base64
These 2 Users Gave Thanks to Yoda For This Post:
# 3  
Old 04-03-2015
Quote:
Originally Posted by Yoda
I would suggest base64 instead of uuencode. Also specify the right Content-Type for attachment.
Code:
export MAILPART=$(uuidgen)
export MAILPART_BODY=$(uuidgen)

{
        echo "From: from@domain.com"
        echo "To: to@domain.com"
        echo "Subject: Testinglah"
        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 testtharmen2.html
        echo "--$MAILPART_BODY--"
        echo ""
        echo "--$MAILPART"
        echo "Content-Type: text/plain; name=testCPUID3.txt"
        echo "Content-Transfer-Encoding: base64"
        echo "Content-Disposition: attachment; filename=testCPUID3.txt"
        echo ""
        base64 /export/home/oracle/testCPUID3.txt
        echo "--$MAILPART--"
} | /usr/sbin/sendmail -t

uuidgen

base64
Hi Yoda,
Thanks for the reply.
I got error as below
Code:
ksh:uuidgen not found
ksh:base64 not found


Last edited by rbatte1; 09-29-2017 at 10:17 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sendemail how to send an email with a subject variable

Hi,:) I try this : #!/bin/bash sender="me@example.com" recipient="you@example.com" subject="TEST FILE" server="0.0.0.0" file=$(cat file.txt) /usr/bin/sendemail -f $sender -t $recipient -u $subject -m $file My file.txt: BLABLALA BLABLABLA (7 Replies)
Discussion started by: Arnaudh78
7 Replies

2. UNIX for Dummies Questions & Answers

new to ldap, send email to a ou or group, and see a list from email client

hi, i'm running openldap on ubuntu 10.04, creating new items with apache directory studio (windows version). i use the ldap just as an address book to our small office (email clients are windows live mail 2009, 2011, microsoft outlook 2007 and 2010). a. i cant see a list of the contacts,... (0 Replies)
Discussion started by: V4705
0 Replies

3. Shell Programming and Scripting

Script to send email after comparing the folder permissions to a certain permission & send email

Hello , I am trying to write a unix shell script to compare folder permission to say drwxr-x-wx and then send an email to my id in case the folders don't have the drwxr-x-wx permissions set for them . I have been trying to come up with a script for few days now , pls help me:( (2 Replies)
Discussion started by: nairshar
2 Replies

4. Solaris

Send an email from Solaris using Linux email server

Hello everyone I have a problem and I need your help: I have a Solaris 10 and Solaris 8 UNIX Servers, and Linux Centos4 as email server. I need send an email from Solaris servers preferably using Centos4 email server. I have no mail service configured in my Solaris computers (1 Reply)
Discussion started by: aflores
1 Replies

5. Shell Programming and Scripting

how to send an email with some body content and attachment

hi plz help me in sending a mail with some data in body and an attachment as some txt file. currently i am able to send mail with some body content, i need an example how to send the same along with attachment. thanks in advance -bali (2 Replies)
Discussion started by: balireddy_77
2 Replies

6. UNIX for Dummies Questions & Answers

Looking for an X11 Utility - Send Keystrokes to Multiple Clients

A long time ago, I frequently used a small X11 utility that allows you to manage multiple systems at the same time. It worked by opening a small window that had a button you used to "Add" X Clients to it. These would be xterms on different systems for example. You would then type inside that... (5 Replies)
Discussion started by: Alon.Albert
5 Replies

7. UNIX for Dummies Questions & Answers

To send an email with the body content extracted from a file

Hi, I have been trying to shoot an email with the email body to be obtained from a file. Can someone please help me with it.. I have been trying to use the MAILX commad for the same. mailx -s "test email" -r sender@test.com < file.txt but it sends the file as an attachment,while i... (3 Replies)
Discussion started by: rohit.shetty84
3 Replies

8. UNIX for Dummies Questions & Answers

Send email where # is in the email address - Using Unix

Hi All, How do I send an email using malix where email address contains a #. I have a email address like this : #test@test.com I want to send email like malix -s "TEST" #test@test.com < SOMEFILE I tried \# but doesn't work. Please let me know how we can achieve this? I am in... (1 Reply)
Discussion started by: jingi1234
1 Replies

9. UNIX for Advanced & Expert Users

Unable to send eMail from a UNIX-Host ( using mailx ) to a Outlook-email-addres(Win)

Hi A) I am able to send eMail using mailx from a UNIX ( solaris 8 ) host to my Outlook-email-ID : FName.Surname@Citigroup.com ( This is NOT my actual -eMail-ID). But in Outlook the "From :" eMail address is displayed as " usr1@unix-host1.unregistered.email.citicorp.com " .i.e the words... (2 Replies)
Discussion started by: Vetrivela
2 Replies
Login or Register to Ask a Question