shell send html email | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

shell send html email

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 09-12-2008
Ikon's Avatar
Ikon Ikon is offline Forum Advisor  
Computer Geek
 
Join Date: Jul 2008
Last Activity: 10 July 2013, 11:06 AM EDT
Location: Frederick, MD
Posts: 748
Thanks: 4
Thanked 10 Times in 9 Posts
shell send html email

I know how to send an email with sendmail in a shell script.

I know how to send an email with an attachment in a script.



But im trying to send an email and need to set Content-Type to text/html and insert a file as the body and not attachment.

Send email with file as attachment:

Code:
#!/bin/bash
 
ATTFILE=$1
ATTNAME=$1
MAILTO=me@home.com
MAILFROM=someone@mail.com
 
( cat <<HERE; uuencode "${ATTFILE}" "${ATTNAME}" ) | sendmail -oi -t
From: ${MAILFROM}
To: ${MAILTO}
Subject: Requested file attached $ATTNAME
 
HERE

How can I change this to put the ATTFILE directly in the body?

Im pretty sure it will take Content-Type like this:

Code:
.
.
From: ${MAILFROM}
To: ${MAILTO}
Content-Type: text/html
.
.

Thanks....
Sponsored Links
    #2  
Old 09-12-2008
strike-2 strike-2 is offline
Registered User
 
Join Date: Dec 2007
Last Activity: 23 April 2009, 2:38 AM EDT
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
It might work if you change this line:
( cat <<HERE; uuencode "${ATTFILE}" "${ATTNAME}" ) | sendmail -oi -t
to:
( cat <<HERE; < "${ATTFILE}" ) | sendmail -oi -t

I'm not too sure about the order of appearance (either the header or the attachment coomes first, I'm not sure...

Quote:
Originally Posted by Ikon View Post
I know how to send an email with sendmail in a shell script.

I know how to send an email with an attachment in a script.



But im trying to send an email and need to set Content-Type to text/html and insert a file as the body and not attachment.

Send email with file as attachment:

Code:
#!/bin/bash
 
ATTFILE=$1
ATTNAME=$1
MAILTO=me@home.com
MAILFROM=someone@mail.com
 
( cat <<HERE; uuencode "${ATTFILE}" "${ATTNAME}" ) | sendmail -oi -t
From: ${MAILFROM}
To: ${MAILTO}
Subject: Requested file attached $ATTNAME
 
HERE

How can I change this to put the ATTFILE directly in the body?

Im pretty sure it will take Content-Type like this:

Code:
.
.
From: ${MAILFROM}
To: ${MAILTO}
Content-Type: text/html
.
.

Thanks....
Sponsored Links
    #3  
Old 09-15-2008
Ikon's Avatar
Ikon Ikon is offline Forum Advisor  
Computer Geek
 
Join Date: Jul 2008
Last Activity: 10 July 2013, 11:06 AM EDT
Location: Frederick, MD
Posts: 748
Thanks: 4
Thanked 10 Times in 9 Posts
This still make the file an attachment with a .dat filename.

FYI: this is on a HP-UX system with Korn shell.
    #4  
Old 09-15-2008
Ikon's Avatar
Ikon Ikon is offline Forum Advisor  
Computer Geek
 
Join Date: Jul 2008
Last Activity: 10 July 2013, 11:06 AM EDT
Location: Frederick, MD
Posts: 748
Thanks: 4
Thanked 10 Times in 9 Posts
I figured it out:


Code:
( cat <<HERE; cat /path/to/file ) | sendmail -oi -t
From: ${MAILFROM}
To: ${MAILTO}
Subject: Some subject
Content-Type: text/html

HERE

Sponsored Links
    #5  
Old 09-16-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
 
Join Date: Mar 2008
Last Activity: 28 March 2011, 6:41 AM EDT
Location: /there/is/only/bin/sh
Posts: 3,653
Thanks: 0
Thanked 10 Times in 8 Posts
Strictly speaking you should also have MIME-Version and Content-Transfer-Encoding headers. MIME-Version is simply 1.0, there has never been any other version; for Content-Transfer-Encoding, 7bit is appropriate if the content is plain 7-bit ASCII text with no long lines (longer than 1024 characters IIRC). (If it's not plain 7-bit ASCII you should also define the character set in Content-Type.)

Some versions of cat will accept standard input as an argument, so you can say


Code:
cat - /path/to/file <<HERE | sendmail -oi -t
From: ${MAILFROM}
To: ${MAILTO}
Subject: Same subject
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit
MIME-Version: 1.0

HERE

Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Display both html and plain text in email in shell script sreelu Shell Programming and Scripting 4 05-31-2011 10:34 AM
How to send email as HTML format with attachment ? bh_hensem UNIX for Advanced & Expert Users 4 12-09-2010 10:22 AM
Script to send email after comparing the folder permissions to a certain permission & send email nairshar Shell Programming and Scripting 2 12-07-2010 08:22 PM
How to send email through shell script nileshbhawsar Shell Programming and Scripting 3 11-01-2010 01:30 PM
How to send message in html format using shell script baps Shell Programming and Scripting 1 02-06-2010 02:33 PM



All times are GMT -4. The time now is 04:13 AM.