Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Using mail to send HTML emails Post 2297 by dmennis on Saturday 5th of May 2001 04:04:40 AM
Old 05-05-2001
Computer

Hi,

I'm a programmer not a sys admin, so please excuse this if it seems a little out of place, but I think it applies to this forum. When I send my HTML newsletter from the server it comes in as plain text on some email programs and not others. Eudora is fine; Outlook Express, Hotmail, and Lotus Notes come in as plain text.

We are using "mail" to send the messages inside a php file and stepping through a user db in MYSQL. I suspect it is something to do with the way mail works or we need to add a line of code, but this is not my area of expertise, so any thoughts or suggestions would be greatly appreciated.

Thank you in advance for your time!
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Send an attachment and html text both in the same mail

Hi all, I am working on UNIX (Solaris28). I would like to send an email in which the body will be in html format and, in the same mail, a xls file has to be attached. I have tried this: the file is correctly attached but the body comes as html source and not formatted. If I do not attach the... (4 Replies)
Discussion started by: stefan.yu
4 Replies

2. UNIX for Dummies Questions & Answers

AIX send mail with HTML message body and a binary attachment

I'm trying to script sending an e-mail message on an AIX 5.x server with the following requirements: 1. command line switch to specify file name containing message body in HTML format 2. command line switch to specify file name of a binary attachment 3. command line or input file to specify... (4 Replies)
Discussion started by: G-Man
4 Replies

3. AIX

Command line/Script to send E-mail with HTML body and binary attachment

I apoligize for the cross-post but I'm not getting much in the way of help in the dummies forum: I'm trying to script sending an e-mail message on an AIX 5.x server with the following requirements: 1. command line switch to specify file name containing message body in HTML format 2. command... (3 Replies)
Discussion started by: G-Man
3 Replies

4. Shell Programming and Scripting

Send mail with rich text / HTML with image

Hi, Is it possible to send mail from my HP-Ux system with images, rich text? I would like to program in such a way that I have my company's logo(.jpg) image attached in the mail geeting triggered. I would like to send a rich text/HTML email instead of plain text mail to the recipients. Is it... (2 Replies)
Discussion started by: rythym05
2 Replies

5. UNIX for Dummies Questions & Answers

How to send html file in a mail not as an attachment but it should display in the mail in table for

Hi The below script working when we are sending the html as attachment can u please guide how to send thesmae data in table form direct in the mail and not in mail attachment . cat Employee.sql SET VERIFY OFF SET PAGESIZE 200 SET MARKUP HTML ON SPOOL ON PREFORMAT OFF ENTMAP ON - HEAD... (0 Replies)
Discussion started by: mani_isha
0 Replies

6. Shell Programming and Scripting

PHP Mail Script Takes Hours to Send emails

guys, i have a php script that i wrote that takes hours to send emails to recipients. i can't post the content of this script in here because the script contains some very important confidential information. so my question is, why is it that when the php script runs, it runs successfully, but... (3 Replies)
Discussion started by: SkySmart
3 Replies

7. Shell Programming and Scripting

Unable to send mail with inline html along with attachment. Please help!

The below code is not working. I am able to send only inline html or only attachment. When trying to do both, only inline html is sent without attachment. Please help! #!/bin/ksh (echo "Subject: Test Mail - HTML Format" echo "MIME-Version: 1.0" echo "Content-Type: text/html" echo... (1 Reply)
Discussion started by: thulasidharan2k
1 Replies

8. Shell Programming and Scripting

Send mail using html tag pre

Need assistance. Trying to send a test.csv file using html tag <PRE> </PRE>. Used to work without any issue . But now gets me and stdin issue. Please give me any suggestions #!/usr/bin/ksh export MAILTO=" <userid>@a.com" export SUBJECT="Test mail " ( echo "Subject: $SUBJECT" echo... (6 Replies)
Discussion started by: ajayram_arya
6 Replies

9. Shell Programming and Scripting

Send multiple HTML output in one mail

HI, I have two scripts which is sending the mail in html format. Script 1: 1.IFILE=/home/home01/Report.csv if #Checks if file exists and readable then if awk -F, '{ T += $13 } END { exit(!T) }' ${IFILE} then awk -F, 'BEGIN{ c=split("3,4,8,9,13", col) print "To:... (0 Replies)
Discussion started by: Vivekit82
0 Replies

10. Shell Programming and Scripting

Script that gathers specific values from files and puts it into HTML to send e-mail

Hi All, Sorry for long topic here. So the drill goes like that, I need a script which gathers different values from different files/locations. A_CT=`cat a.dat | awk -F'|' '{print $1}' >> report.txt` B_CT=`cat b.dat | awk -F'|' '{print $3}' >> report.txt` C_CT=`cat c.dat | awk -F'|'... (4 Replies)
Discussion started by: shivakid
4 Replies
Email::MIME::CreateHTML(3pm)				User Contributed Perl Documentation			      Email::MIME::CreateHTML(3pm)

NAME
Email::MIME::CreateHTML - Multipart HTML Email builder SYNOPSIS
use Email::MIME::CreateHTML; my $email = Email::MIME->create_html( header => [ From => 'my@address', To => 'your@address', Subject => 'Here is the information you requested', ], body => $html, text_body => $plain_text ); use Email::Send; my $sender = Email::Send->new({mailer => 'SMTP'}); $sender->mailer_args([Host => 'smtp.example.com']); $sender->send($email); DESCRIPTION
This module allows you to build HTML emails, optionally with a text-only alternative and embedded media objects. For example, an HTML email with an alternative version in plain text and with all the required images contained in the mail. The HTML content is parsed looking for embeddable media objects. A resource loading routine is used to fetch content from those URIs and replace the URIs in the HTML with CIDs. The default resource loading routine is deliberately conservative, only allowing resources to be fetched from the local filesystem. It's possible and relatively straightforward to plug in a custom resource loading routine that can resolve URIs using a broader range of protocols. An example of one using LWP is given later in the "COOKBOOK". The MIME structure is then assembled, embedding the content of the resources where appropriate. Note that this module does not send any mail, it merely does the work of building the appropriate MIME message. The message can be sent with Email::Send or any other mailer that can be fed a string representation of an email message. Mail Construction The mail construction is compliant with rfc2557. HTML, no embedded objects (images, flash, etc), no text alternative text/html HTML, no embedded objects, with text alternative multipart/alternative text/plain text/html HTML with embedded objects, no text alternative multipart/related text/html embedded object one embedded object two ... HTML with embedded objects, with text alternative multipart/alternative text/plain multipart/related text/html embedded object one embedded object two ... METHODS
There is only one method, which is installed into the Email::MIME package: Email::MIME->create_html(%parameters) This method creates an Email::MIME object from a set of named parameters. Of these the "header" and "body" parameters are mandatory and all others are optional. See the "PARAMETERS" section for more information. LOW-LEVEL API Email::MIME::CreateHTML also defines a lower-level interface of 3 building-block routines that you can use for finer-grain construction of HTML mails. These may be optionally imported: use Email::MIME::CreateHTML qw(embed_objects parts_for_objects build_html_mail); ($modified_html, $cid_mapping) = embed_objects($html, \%options) This parses the HTML and replaces URIs in the embed list with a CID. The modified HTML and CID to URI mapping is returned. Relevant parameters are: embed inline_css base object_cache resolver The meanings and defaults of these parameters are explained below. @mime_parts = parts_for_objects($cid_mapping, \%options) This creates a list of Email::MIME parts for each of the objects in the supplied CID mapping. Relevant options are: base object_cache resolver The meanings and defaults of these parameters are explained below. $email = build_html_email(@headers, $html, \%body_attributes, @html_mime_parts, $plain_text_mime) The assembles a ready-to-send Email::MIME object (that can be sent with Email::Send). PARAMETERS
header => list A list reference containing a set of headers to be created. If no Date header is specified, one will be provided for you based on the gmtime() of the local machine. body => scalar A scalar value holding the HTML message body. body_attributes => hash reference This is passed as the attributes parameter to the "create" method (supplied by "Email::MIME::Creator") that creates the html part of the mail. The body content-type will be set to "text/html" unless it is overidden here. embed => boolean Attach relative images and other media to the message. This is enabled by default. The module will attempt to embed objects defined by "embed_elements". Note that this option only affects the parsing of the HTML and will not affect the "objects" option. The object's URI will be rewritten as a Content ID. embed_elements => reference to hash of hashes with boolean values The set of elements that you want to be embedded. Defaults to the %Email::MIME::CreateHTML::EMBED package global. This should be a data structure of the form: embed_elements => { $elementname_1 => {$attrname_1 => $boolean_1}, $elementname_2 => {$attrname_2 => $boolean_2}, ... } i.e. resource will be embedded if "$embed_elements->{$elementname}->{$attrname}" is true. resolver => object If a resolver is supplied this will be used to fetch the resources that are embedded as MIME objects in the email. If no resolver is given the default behaviour is to choose the best available resolver to read $uri with any $base value prefixed. Resources fetched using the resolver will be cached if an "object_cache" is supplied. base => scalar This must be a filepath or a URI. If "embed" is true (the default) then "base" will be used when fetching the objects. Examples of good bases: ./local/images /home/somewhere/images http://mywebserver/images inline_css => boolean Inline any CSS external CSS files referenced through link elements. Enabled by default. Some mail clients will only interpret css if it is inlined. objects => hash reference A reference to a hash of external objects. Keys are Content Ids and the values are filepaths or URIs used to fetch the resource with the resolver. We use "MIME::Types" to derive the type from the file extension. For example in an HTML mail you would use the file keyed on '12345678@bbc.co.uk' like "<img src="cid:12345678@bbc.co.uk" alt="a test" width="20" height="20" />" object_cache => cache object A cache object can be supplied to cache external resources such as images. This must support the following interface: $o = new ... $o->set($key, $value) $value = $o->get($key) Both the Cache and Cache::Cache distributions on CPAN conform to this. text_body => scalar A scalar value holding the contents of an additional plain text message body. text_body_attributes => hash reference This is passed as the attributes parameter to the "create" method (supplied by "Email::MIME::Creator") that creates the plain text part of the mail. The body Content-Type will be set to "text/plain" unless it is overidden here. GLOBAL VARIABLES
%Email::MIME::CreateHTML::EMBED This is the default set of elements (and the relevant attributes that point at a resource) that will be embedded. The for this is: 'bgsound' => {'src'=>1}, 'body' => {'background'=>1}, 'img' => {'src'=>1}, 'input' => {'src'=>1}, 'table' => {'background'=>1}, 'td' => {'background'=>1}, 'th' => {'background'=>1}, 'tr' => {'background'=>1} You can override this using the "embed_elements" parameter. COOKBOOK
The basics This builds an HTML email: my $email = Email::MIME->create_html( header => [ From => 'my@address', To => 'your@address', Subject => 'My speedy HTML', ], body => $html ); If you want a plaintext alternative, include the "text_body" option: my $email = Email::MIME->create_html( header => [ From => 'my@address', To => 'your@address', Subject => 'Here is the information you requested', ], body => $html, text_body => $plain_text #<-- ); If you want your images to remain as links (rather than be embedded in the email) disable the "embed" option: my $email = Email::MIME->create_html( header => [ From => 'my@address', To => 'your@address', Subject => 'My speedy HTML', ], body => $html, embed => 0 #<-- ); Optimising out HTML parsing By default, the HTML is parsed to look for objects and stylesheets that need embedding. If you are controlling the construction of the HTML yourself, you can use Content Ids as the URIs within your HTML and then pass in a set of objects to associate with those Content IDs: my $html = qq{ <html><head><title>My Document</title></head><body> <p>Here is a picture:</p><img src="cid:some_image_jpg@bbc.co.uk"> </body></html> }; You then need to create a mapping of the Content IDs to object filenames: my %objects = ( "some_image_jpg@bbc.co.uk" => "/var/html/some_image.jpg" ); Finally you need to disable both the "embed" and "inline_css" options to turn off HTML parsing, and pass in your mapping: my $quick_to_assemble_mime = Email::MIME->create_html( header => [ From => 'my@address', To => 'your@address', Subject => 'My speedy HTML', ], body => $html, embed => 0, #<-- inline_css => 0, #<-- objects => \%objects #<-- ); Preprocessing templates If you have for example a personalised newsletter where your HTML will vary slightly from one email to the next, but you don't want to re- parse the HTML each time to re-fetch and attach objects, you can use the "embed_objects" function to pre-process the template, converting URIs into CIDs: use Email::MIME::CreateHTML qw(embed_objects); my ($preproc_tmpl_content, $cid_mapping) = embed_objects($tmpl_content); You can then reuse this and the CID mapping: my $template = compile_template($preproc_tmpl_content); foreach $newsletter (@newsletters) { #Do templating my $html = $template->process($newsletter); #Build MIME structure my $mime = Email::MIME->create_html( header => [ From => $reply_address, To => $newsletter->address, Subject => 'Weekly newsletter', ], body => $html, embed => 0, #Already done inline_css => 0, #Already done objects => $cid_mapping #Here's one we prepared earlier ); #Send email send_email($mime); } Note that one caveat with this approach is that all possible images that might be used in the template will be attached to the email. Depending on your template logic, it may be that some are never actually referenced from within the email (e.g. if an image is conditionally displayed) so this may create unnecessarily large emails. Plugging in a custom resource resolver A custom resource resolver can be specified by passing your own object to resolver: my $mime = Email::MIME->create_html( header => [ From => 'my@address', To => 'your@address', Subject => 'Here is the information you requested', ], body => $html, base => 'http://internal.foo.co.uk/images/', resolver => new MyResolver, #<-- ); The object needs to have the following API: package MyResolver; sub new { my ($self, $options) = @_; my $base_uri = $options->{base}; #... YOUR CODE HERE ... (probably want to stash $base_uri in $self) } sub get_resource { my ($self, $uri) = @_; my ($content,$filename,$mimetype,$xfer_encoding); #... YOUR CODE HERE ... return ($content,$filename,$mimetype,$xfer_encoding); } where: $uri is the URI of the object we are embedding (taken from the markup or passed in via the CID mapping) $base_uri is base URI used to resolve relative URIs $content is a scalar containing the contents of the file $filename is used to set the name attribute of the Email::MIME object $mimetype is used to set the content_type attribute of the Email::MIME object $xfer_encoding is used to set the encoding attribute of the Email::MIME object (note this is the suitable transfer encoding NOT a character encoding) Plugging in different types of object cache You can use a cache from the Cache::Cache distribution: use Cache::MemoryCache; my $mime = Email::MIME->create_html( header => @headers, body => $html, object_cache => new Cache::MemoryCache( { 'namespace' => 'MyNamespace', 'default_expires_in' => 600 } ) ); Or a cache from the Cache distribution: use Cache::File; my $mime = Email::MIME->create_html( header => @headers, body => $html, object_cache => Cache::File->new( cache_root => '/tmp/mycache', default_expires => '600 sec' ) ); Alternatively you can roll your own. You just need to define an object with get and set methods: my $mime = Email::MIME->create_html( header => @headers, body => $html, object_cache => new MyCache() ); package MyCache; our %Cache; sub new {return bless({}, shift())} sub get {return $Cache{shift()}} sub set {$Cache{shift()} = shift()} 1; SEE ALSO
Perl Email Project <http://pep.pobox.com> Email::Simple, Email::MIME, Email::Send, Email::MIME::Creator TODO
Maybe add option to control the order that the text + html parts appear in the MIME message. VERSION
$Revision: 1.30 $ on $Date: 2010/02/12 17:44:26 $ by $Author: jamiel $ AUTHOR
Tony Hennessy and Simon Flack with cookbook + some refactoring by John Alden <cpan _at_ bbc _dot_ co _dot_ uk> COPYRIGHT
(c) BBC 2005,2006. This program is free software; you can redistribute it and/or modify it under the GNU GPL. See the file COPYING in this distribution, or http://www.gnu.org/licenses/gpl.txt perl v5.10.1 2010-02-12 Email::MIME::CreateHTML(3pm)
All times are GMT -4. The time now is 09:08 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy