|
|
 |
 |
 |
 |
Perl Programming Language
|
 |
 |
 |
 |
 |
 |
 |
 |
Sending RTF email with Perl?
I am trying to use a module to send an RTF email (because I need to use color codes) from Perl. I have been using MIME::Lite to send email attachments, but am unable to get it to send the mail itself as RTF. I found a FAQ (not a newsgroup one) on sending HTML email: http://www.cyberciti.biz/faq/how-do-i-send-html-email-from-perl/ and that works OK, but extrapolating their method to RTF fails. Here is their suggestion for HTML email: #!/usr/bin/perl -w use strict; use MIME::Lite; # SendTo email id my $email = '@somewhere.com'; # create a new MIME Lite based email my $msg = MIME::Lite->new ( Subject => 'HTML email test', From => '@somewhere.com', To => $email, Type => 'text/html', Data => '<H1>Hello</H1><br>This is a test email. Please visit our site <a href="http://cyberciti.biz/">online</a><hr>' ); $msg->send(); As noted, this works fine. If I change this to #!/usr/bin/perl -w use strict; use MIME::Lite; use RTF::Writer; my $rtfstring; my $rtf = RTF::Writer->new_to_string(\$rtfstring); $rtf->prolog; $rtf->printf( \'{\pard\cf1'); $rtf->printf( \'Hello, World'); $rtf->printf( \'\par}'); $rtf->close; my $msg = MIME::Lite->new( Subject => 'TEST RTF MESSAGE', From => '@somewhere.com', To => $email, Type => 'text/rtf', Data => $rtfstring ); $msg->send; ... it simply doesn't work. The "raw" RTF shows up as plain text in the email. If anyone has any ideas along these lines, I would appreciate hearing them. -- _+_ From the catapult of |If anyone disagrees with any statement I make, I _|70|___:)=}- J.D. Baldwin |am quite prepared not only to retract it, but also \ / bald@panix.com|to deny under oath that I ever made it. -T. Lehrer ***~~~~-------------------------------------------------------------------- ---
INVALID_SEE_ @example.com.invalid (J.D. Baldwin) writes: > I am trying to use a module to send an RTF email (because I need to > use color codes) from Perl. I have been using MIME::Lite to send > email attachments, but am unable to get it to send the mail itself as > RTF. I found a FAQ (not a newsgroup one) on sending HTML email: > http://www.cyberciti.biz/faq/how-do-i-send-html-email-from-perl/ > and that works OK, but extrapolating their method to RTF fails.
... > my $msg = MIME::Lite->new( > Subject => 'TEST RTF MESSAGE', > From => ' @somewhere.com', > To => $email, > Type => 'text/rtf', > Data => $rtfstring > ); > $msg->send; > ... it simply doesn't work. The "raw" RTF shows up as plain text in > the email.
The MIME type for RTF isn't "text/rtf", it's "application/rtf". > If anyone has any ideas along these lines, I would appreciate hearing them.
You may be better off sending HTML anyway - I'd expect more email clients to understand HTML than RTF. sherm-- -- Web Hosting by West Virginians, for West Virginians: http://wv-www.net Cocoa programming in Perl: http://camelbones.sourceforge.net
In the previous article, Sherm Pendley <spamt@dot-app.org> wrote: > The MIME type for RTF isn't "text/rtf", it's "application/rtf".
I tried application/rtf first, then changed it to text/rtf out of desperation; the latter version got posted. But good catch. > > If anyone has any ideas along these lines, I would appreciate hearing them. > You may be better off sending HTML anyway - I'd expect more email clients to > understand HTML than RTF.
The project spec is RTF. On the other hand, I wrote the spec, and I can change it unilaterally ... I guess I'd prefer RTF, but I can live with going to HTML if there's no good alternative. Thanks for the response. -- _+_ From the catapult of |If anyone disagrees with any statement I make, I _|70|___:)=}- J.D. Baldwin |am quite prepared not only to retract it, but also \ / bald@panix.com|to deny under oath that I ever made it. -T. Lehrer ***~~~~-------------------------------------------------------------------- ---
J.D. Baldwin wrote: > I am trying to use a module to send an RTF email (because I need to > use color codes) from Perl. I have been using MIME::Lite to send > email attachments, but am unable to get it to send the mail itself as > RTF. I found a FAQ (not a newsgroup one) on sending HTML email:
We've got a system which does this at the moment. The (slightly modified) relevant bit of code is: my $msg = MIME::Lite -> new ( From => 'sen@example.com', To => 'recipi@example.com', Subject => "Some title", Type => 'multipart/mixed', ); $msg ->attach(Type => 'TEXT', Data => "This is the text part of the email", ); # The RTF document is loaded and stored in $rtf my $rtf_attach = MIME::Lite -> new( Type => 'application/rtf', Filename => "name_to_show.rtf", Data => $rtf ); $msg -> attach($rtf_attach); $msg -> send() or print_bug ("Unable to send email request"); Hope this helps Simon.
On 2007-06-04 21:37, J.D. Baldwin <INVALID_SEE_@example.com.invalid> wrote:
> I am trying to use a module to send an RTF email (because I need to > use color codes) from Perl. I have been using MIME::Lite to send > email attachments, but am unable to get it to send the mail itself as > RTF. [...] > As noted, this works fine. If I change this to > #!/usr/bin/perl -w > use strict; > use MIME::Lite; [...] > my $msg = MIME::Lite->new( > Subject => 'TEST RTF MESSAGE', > From => '@somewhere.com', > To => $email, > Type => 'text/rtf', > Data => $rtfstring > ); > $msg->send; > ... it simply doesn't work. The "raw" RTF shows up as plain text in > the email.
The first question is of course: Does your email client support RTF at all? If so, do you have any RTF messages which are displayed correctly? hp -- _ | Peter J. Holzer | I know I'd be respectful of a pirate |_|_) | Sysadmin WSR | with an emu on his shoulder. | | | h@hjp.at | __/ | http://www.hjp.at/ | -- Sam in "Freefall"
|
 |
 |
 |
 |
|