Re: [Boston.pm] HTML email messages
On Sun, Feb 02, 2003 at 07:54:31PM -0800, Palit, Nilanjan wrote: > This question is not directly related to Perl, but I'm hoping that someone here can >answer it. > > I have written a tool in Perl, that runs on Unix, to generate daily roll-up reports >and mail it out to a distribution list. Most of the recipients use Microsoft Outlook >to read the reports. I have received several requests for formatting the message, >e.g. with bold or italic or colored or different sized fonts, to make it more >readable. I have very few ideas on how to go about doing that. One option may be to >generate (via Perl) a HTML formatted message. But how would I get Outlook to >recognize that as a HTML message and not a plain text message? Any ideas would be >greatly appreciated. I haven't seen any propose module-based solutions, so here is a copy & paste from some code I wrote before. You'll have to get creative and work out what's going on, but it provides the option to send plain-text, html only, and both. Needs: use Template (); use MIME::Entity (); Code fragment, my $top = MIME::Entity->build( Type => 'multipart/alternative', # XXX this is a bit of a hack since we may only send one part From => 'Robot <[EMAIL PROTECTED]>', To => "$user_info->{name} <$user_info->{email}>", Subject => "Report for $user_info->{name}", ); my $report_format = $user_info->{prefs}{report_format} or die "No report_format set in userprefs!"; if ($report_format ne 'text/html') { my $output; $template->process("email.txt", $params, \$output) or die $template->error; $top->attach( Type => 'text/plain', Data => $output, Encoding => 'quoted-printable' ); } if ($report_format ne 'text/plain') { my $output; $template->process("email.html", $params, \$output) or die $template->error; $top->attach( Type => 'text/html', Data => $output, Encoding => 'quoted-printable' ); } # For reasons unclear, ->send() loses the content-type: headers :-/ $top->smtpsend; It's not optimal; you may want to send a direct text/plain message without the multipart cruft but frankly I've yet to see an MUA that can't deal with it. HTH, Paul -- Paul Makepeace ... http://paulm.com/ "What is the colour red? Pins and needles. No more. No less." -- http://paulm.com/toys/surrealism/ ___ Boston-pm mailing list [EMAIL PROTECTED] http://mail.pm.org/mailman/listinfo/boston-pm
RE: [Boston.pm] HTML email messages
> The example I showed did *not* provide the HTML document as an attachment. > I used a Content-Type of multipart/alternative, which indicates that the > parts of the message are alternative forms of the message, and the mail > client may choose to render whichever part it chooses. Outlook would show > the HTML content and mutt would show the text content, for example. I'm sorry, you're correct. I was thinking multipart-mixed. > In his followup email Nilanjan specifically mentions mutt, which does not > support directly rendering HTML content. Perhaps I erred in choosing the > word "malformed", but I still assert that HTML email should not be sent > without a corresponding plain text part. Actually, I can only find a reference to elm, but that is only as means of creating the email. Please don't misunderstand, I quite regularly use pine for email, however I understand the desire to send HTML email for things such as in-house reports and company newsletters. I only took offense to the statement that these examples were in some way 'broken'. If plain-text is not required as part of the solution (such as in-house items for a company standardized on some HTML-supporting MUA), then there is no reason to send it. In fact, it wastes resources. If however some clients do not have the ability to view HTML, then yes, you're solution would be preferable. Grant M. ___ Boston-pm mailing list [EMAIL PROTECTED] http://mail.pm.org/mailman/listinfo/boston-pm
Re: [Boston.pm] HTML email messages
On Mon, Feb 03, 2003 at 10:39:50AM -0500, Wizard wrote: > > Both of the proposed solutions so far would have you sending HTML-only > > email. Please do not do this; email which contains HTML without a > > corresponding plain text part is malformed. > > I understand the objections people may have to the sole inclusion of HTML > content in email, however providing misinformation doesn't resolve that. > Section 9.1 of RFC 2557, "MIME Encapsulation of Aggregate Documents" > specifically calls out the means by which one sends HTML documents without > included objects, and this mirrors the examples given by myself and Kevin > Pease (more so Kevin's, as mine fails to include mime-version and encoding). > It is an IETF standard, and in his original email Nilanjan specifically > mentions Outlook, which supports this standard. The example Kevin stated is > not 'malformed' and are valid solutions to Nilanjan's question. The example > that you give merely attaches the HTML document to the email, which can be > done with most any email client and I suspect is not quite what was being > asked. The example I showed did *not* provide the HTML document as an attachment. I used a Content-Type of multipart/alternative, which indicates that the parts of the message are alternative forms of the message, and the mail client may choose to render whichever part it chooses. Outlook would show the HTML content and mutt would show the text content, for example. In his followup email Nilanjan specifically mentions mutt, which does not support directly rendering HTML content. Perhaps I erred in choosing the word "malformed", but I still assert that HTML email should not be sent without a corresponding plain text part. Ronald P.S. Disclaimer: mutt is my preferred email client. ___ Boston-pm mailing list [EMAIL PROTECTED] http://mail.pm.org/mailman/listinfo/boston-pm
[Boston.pm] Communication Problem with sendmail???
Recently people on my mailing list have complained of receiving two emails instead of one each time I send them a letter. I use a web interface that I built to manage a very simple list, which takes a message from a form, and mass-mails it to the list. The key subroutine is "publish", which calls a file reading library routine I call "ReadF", and another library routine to communicate with the sendmail program I call "MailM". Everything in the code is simple... seems straightforward. There are no black box module calls. This could probably run in Perl 4. The list has been checked several times and is completely clean of duplicate email addresses. Can anyone see a reason why sendmail might be sending the message in $in{'message'} to everyone twice? - James sub publish { $BaseDir = "/usr/local/etc/httpd/data"; ('master.data'); foreach (@FileArray) { ("ceo\@fat24.com","ceo\@fat24.com",$_,$in{'subject'},$in{'message' },0,0,0,1); } } sub MailM { if ($_[8]) { open (MAIL, "|/bin/sendmail -t") || ('bin/sendmail'); } else { open (MAIL, "|/bin/sendmail -odq -t") || ('bin/sendmail'); } if ($_[1]) { print MAIL "Return-Path: $_[1]\n"; } print MAIL "Content-return: allowed\n"; print MAIL "From: $_[0]\n"; if ($_[1]) { print MAIL "Reply-To: $_[1]\n"; } print MAIL "Subject: $_[3]\n"; print MAIL "To: $_[2]\n"; if ($_[5]) { print MAIL "Cc: $_[5]\n"; } if ($_[6]) { print MAIL "Bcc: $_[6]\n"; } if ($_[7] eq 'e') { print MAIL "Content-Type: text/plain; charset=\"iso-8859-1\"\n"; } elsif ($_[7] eq 'h') { print MAIL "Content-Type: text/html; charset=\"iso-8859-1\"\n"; } elsif ($_[7] eq 'm') { print MAIL "Content-Type: multipart/mixed\n"; } if ($_[9]) { print "Bounces-to: $_[9]\n"; } print MAIL "Importance: high\n"; print MAIL "X-Priority: 1\n\n"; print MAIL "$_[4]\n"; close (MAIL); } sub ReadF { @FileArray = (); open (DATA, "<$BaseDir/$_[0]") || ($_[0]); flock(DATA, 1); @FileArray = ; close (DATA); foreach (@FileArray) { chomp($_); } return @FileArray; } ___ Boston-pm mailing list [EMAIL PROTECTED] http://mail.pm.org/mailman/listinfo/boston-pm
RE: [Boston.pm] HTML email messages
> Both of the proposed solutions so far would have you sending HTML-only > email. Please do not do this; email which contains HTML without a > corresponding plain text part is malformed. I understand the objections people may have to the sole inclusion of HTML content in email, however providing misinformation doesn't resolve that. Section 9.1 of RFC 2557, "MIME Encapsulation of Aggregate Documents" specifically calls out the means by which one sends HTML documents without included objects, and this mirrors the examples given by myself and Kevin Pease (more so Kevin's, as mine fails to include mime-version and encoding). It is an IETF standard, and in his original email Nilanjan specifically mentions Outlook, which supports this standard. The example Kevin stated is not 'malformed' and are valid solutions to Nilanjan's question. The example that you give merely attaches the HTML document to the email, which can be done with most any email client and I suspect is not quite what was being asked. You can find the IETF standard here: http://www.ietf.org/rfc/rfc2557.txt Grant M. ___ Boston-pm mailing list [EMAIL PROTECTED] http://mail.pm.org/mailman/listinfo/boston-pm
RE: [Boston.pm] HTML email messages
Kevin, Grant, Thanks for the pointers. I tried it & it works! I had been using elm to send the email and that doesn't seem to recognize the "text/html" directive. I'll use sendmail now. Regards, -Nilanjan -Original Message- From: Pease, Kevin [mailto:[EMAIL PROTECTED]] Sent: Monday, February 03, 2003 9:03 AM To: Palit, Nilanjan; [EMAIL PROTECTED] Subject: RE: [Boston.pm] HTML email messages Hi Nilanjan, The code below works for me; I've built this into a build script I wrote a while back to control some software builds we do here; The recipients get an HTML-format message in their Outlook inbox, with some bolding, text-formatting, 's, etc. ___ Boston-pm mailing list [EMAIL PROTECTED] http://mail.pm.org/mailman/listinfo/boston-pm
RE: [Boston.pm] HTML email messages
Hi Nilanjan, The code below works for me; I've built this into a build script I wrote a while back to control some software builds we do here; The recipients get an HTML-format message in their Outlook inbox, with some bolding, text-formatting, 's, etc. I found this technique after a lot of searching on google. I'm sorry to say that I don't remember where exactly I dug this up, though. Hope it helps... (I know it's not very pretty, but I think you should be able to get the gist of how to do this from what I've included below. Be gentle, I wrote this about 2.5 years ago, when I was just learning perl. :) Kevin - code snippet begins below - ##-- ## And, now we do the email. Open a pipe for writing to email. The -t flag ## tells it to determine who the message is to using the header that you've so ## graciously provided. Print everything to the filehandle (pipe to sendmail), ## close it out, and the email's as good as on its way. ##-- open (SENDMAIL, "|/usr/lib/sendmail -t") || die "Can't fork for sendmail: $!\n"; ##-- ## Generate the Email header. These might be order-specific, I don't know. ## They DO work as written, and I think you _MUST_ have at least the following ## headers for this to work properly. ## Fields that must be included: From:, To:, Mime-Version:, Content-Type:, # ## Content-Transfer-Encoding:, and Subject: ## I'm not familiar enough with sendmail to know if you can vary the order of ## these header items or not. ##-- printf (SENDMAIL "From: $FROM\n"); printf (SENDMAIL "To: $TO_LIST\n"); printf (SENDMAIL "Mime-Version: 1.0\n"); printf (SENDMAIL "Content-Type: text/html; charset=ISO-8859-1\n"); printf (SENDMAIL "Content-Transfer-Encoding: 7bit\n"); printf (SENDMAIL "Subject: $SUBJECT\n\n"); ##-- ## At this point, we simply write our HTML-format text into the pipe to include ## it in the body of the email. Note that the doctype tag MIGHT be required, ## but I haven't done any experimentation with whether or not you can remove ## it and still have the same functionality. ##-- printf (SENDMAIL "\n"); printf (SENDMAIL "\n"); printf (SENDMAIL "$SUBJECT\n"); printf (SENDMAIL "\n"); printf (SENDMAIL "This build was requested by $REQUESTER and approved by $APPROVER and is now complete. Please refer to the report below for additional details, and contact $ENV{MY_REAL_NAME} with any questions or concerns related to this particular build.\n"); printf (SENDMAIL "Thank you,\n"); printf (SENDMAIL "MDS SCM Team.\n"); #[... more printfs of HTML to filehandle SENDMAIL ...] #[... MAKE SURE YOU CLOSE OUT THE EMAIL PROPERLY! see below ...] ##-- ## Make sure you close out all your tags, or the email could look funky. And, ## then, make sure you close out the mail with a "." on a blank line. ##-- printf (SENDMAIL ".\n"); close(SENDMAIL) or warn "sendmail didn't close nicely"; - end of code snippet - -- Kevin B. Pease FISC - SCME Fidelity Investments Systems Company [EMAIL PROTECTED] (617) 392-9022 SkyTel Page: 1-800-759-, Pin # 4713841 PACE group: SCME -Original Message- From: Palit, Nilanjan [mailto:[EMAIL PROTECTED]] Sent: Sunday, February 02, 2003 10:55 PM To: [EMAIL PROTECTED] Subject: [Boston.pm] HTML email messages This question is not directly related to Perl, but I'm hoping that someone here can answer it. I have written a tool in Perl, that runs on Unix, to generate daily roll-up reports and mail it out to a distribution list. Most of the recipients use Microsoft Outlook to read the reports. I have received several requests for formatting the message, e.g. with bold or italic or colored or different sized fonts, to make it more readable. I have very few ideas on how to go about doing that. One option may be to generate (via Perl) a HTML formatted message. But how would I get Outlook to recognize that as a HTML message and not a plain text message? Any ideas would be greatly appreciated. Thanks, -Nilanjan ___ Boston-pm mailing list [EMAIL PROTECTED] http://mail.pm.org/mailman/listinfo/boston-pm ___ Boston-pm mailing list [EMAIL PROTECTED] http://mail.pm.org/mailman/listinfo/boston-pm
RE: [Boston.pm] HTML email messages
> But how would I get Outlook to recognize that as a HTML > message and not a plain text message? Any ideas would be greatly > appreciated. I've used this from the shell prompt with sendmail: === FILE mail.src === From: "Me" <[EMAIL PROTECTED]> To: "Human Resources" <[EMAIL PROTECTED]> Bcc: [EMAIL PROTECTED] Subject: Perl News Content-Type: text/html;charset="iso-8859-1" (...) Complete web page here. . . === end FILE SHELL PROMPT $> /bin/sendmail -t < mail.src The last '.' in the mail.src file indicates to Sendmail the end of session. It worked for me. Grant M. ___ Boston-pm mailing list [EMAIL PROTECTED] http://mail.pm.org/mailman/listinfo/boston-pm
Re: [Boston.pm] file types in Mac OS X
On 02/02/2003 at 13:33 -0500, Beth Chaplin wrote: I have written a perl script that runs on my OS X system (through the terminal), and produces a text output file that is meant to be later read by a Mac application (Filemaker Pro, which imports the data from the file into a database). The problem: When Perl creates the text file, it does not get assigned the proper 'file type'. Instead of being recognizable by the Mac system as a text file, it has the file type '', and most Mac applications do not recognize it. Is there any way in perl (or UNIX) to change the file type of a newly created file without having to do it manually through the Mac GUI? I get the feeling that this problem has something to do with the unique way the Mac system assigns file types. I assume you have the Developer Tools installed. These install a pair of tools called SetFile and GetFile Info: blech@piezo:~$ /Developer/Tools/SetFile --help Usage: SetFile [option...] file... -c creator# file creator -t type # file type (Edited for space. There are many more options.) For example, "/Developer/Tools/SetFile -t 'TEXT' -c 'R*ch' new.txt" will make BBEdit the default application for opening the text file "new.txt". However, under Mac OS X, you should also be able to get away with merely setting a text extension. For a full description of how double-clicking a file chooses which application handles it, you'll want to examine the Launch Services documentation: http://developer.apple.com/technotes/tn/tn2017.html You might also want to look at the [EMAIL PROTECTED] mailing list: http://lists.perl.org/showlist.cgi?name=macosx Cheers, -- :: paul :: we're like crystal ___ Boston-pm mailing list [EMAIL PROTECTED] http://mail.pm.org/mailman/listinfo/boston-pm