Sending RTF email with Perl?

J

J.D. Baldwin

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 = '(e-mail address removed)';

# create a new MIME Lite based email
my $msg = MIME::Lite->new
(
Subject => 'HTML email test',
From => '(e-mail address removed)',
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 => '(e-mail address removed)',
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.
 
S

Simon Andrews

J.D. Baldwin said:
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 => '(e-mail address removed)',
To => '(e-mail address removed)',
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.
 
P

Peter J. Holzer

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 => '(e-mail address removed)',
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top