The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
.
google unix.com



UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Mailx : can we have the body to be a binary file ? CKIRCH UNIX for Dummies Questions & Answers 5 01-01-2008 07:33 PM
mailx: concatenating strings for message body (KSH) rockysfr Shell Programming and Scripting 1 07-29-2007 08:12 AM
AIX send mail with HTML message body and a binary attachment G-Man UNIX for Dummies Questions & Answers 4 03-22-2007 02:15 PM
MAILX Body containing SQL results dstinsman UNIX for Dummies Questions & Answers 2 10-05-2006 11:12 PM
How can I write a HTML file in UNIX and sent it as a body of a mail diwa81 Shell Programming and Scripting 0 10-13-2004 09:07 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #8 (permalink)  
Old 07-29-2008
lyradsr lyradsr is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 1
Talking mailx and html formatted email

It is actually possible, and easy to send email in html format.
Here is an example perl script to do just that.

Quote:
#!/usr/bin/perl

########################
# Variables
########################
$mail="/usr/lib/sendmail -t"; # Path to the sendmail program and switches
$mail="/usr/bin/mailx -t"; # Path to the mailx program and switches

$temp="/home/cager/htmlcode"; #<---- File and Path to the HTML
$rcpt="returntome\@xxxx.com"; #<----- The return to email address
$users ="sendtome\@xxxx.com"; #<---- List of "to" email addresses
$ccusers= ""; #<---- List of Cc'd email addresses
$bccusers=""; #<---- List of Bcc'd email addresses
$subject="Get off the web and work"; #<----Title of the email

########################
# Create the Email Pipe
########################
open(MAIL, "| $mail") or die "Can not access $mail $!\n";

########################
# Open the HTML
########################
open(TEMP, "$temp") or die "Can not open $temp $!\n";

########################
# Send the html to the Pipe
########################
print MAIL "From: $rcpt\n";
print MAIL "To: $users\n";
print MAIL "Cc: $ccusers\n";
print MAIL "Bcc: $bccusers\n";
print MAIL "Subject: $subject\n";
print MAIL "Content-Type: text/html;\n";

while (<TEMP>) { #<---- insert the html into the body of the email
print MAIL; #<---- send the email
}
close (TEMP);
close (MAIL);
Give that a shot.
  #9 (permalink)  
Old 07-30-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
You don't really need Perl for that, either. And you should make sure there is an empty line between the headers and the body.

Code:
( cat <<HERE; cat /path/to/file.html) | sendmail -oi -t
From: sender@example.com
To: recipients@example.net
Subject: We hate you, so we send HTML instead of plain text
Mime-Version: 1.0
Content-type: text/html
Content-transfer-encoding: 8bit

HERE
You should properly have Mime-Version and Content-Transfer-Encoding headers as well as Content-Type. The issue of correct MIME transfer encoding is one of the many possible complexities which is simply ignored here (and one of the reasons simple shell scripts don't work well in the general case).

If your cat can combine standard input with a regular file, more power to you.

Code:
cat - /path/to/file.html <<HERE | sendmail -oi -t
...
Sponsored Links
Closed Thread

Bookmarks

Tags
mailx, mailx attachment, sendmail

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:41 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0