Sending RTF email with Perl?

Discussion in 'Perl Misc' started by J.D. Baldwin, Jun 4, 2007.

  1. J.D. Baldwin

    J.D. Baldwin Guest

    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 = '';

    # create a new MIME Lite based email
    my $msg = MIME::Lite->new
    (
    Subject => 'HTML email test',
    From => '',
    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 => '',
    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
    \ / |to deny under oath that I ever made it. -T. Lehrer
    ***~~~~-----------------------------------------------------------------------
    J.D. Baldwin, Jun 4, 2007
    #1
    1. Advertising

  2. 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 => '',
    To => '',
    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.
    Simon Andrews, Jun 6, 2007
    #2
    1. Advertising

  3. On 2007-06-04 21:37, 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.

    [...]
    > 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 => '',
    > 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.
    | | | |
    __/ | http://www.hjp.at/ | -- Sam in "Freefall"
    Peter J. Holzer, Jun 10, 2007
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Xah Lee

    [perl-python] sending email

    Xah Lee, Jan 29, 2005, in forum: Python
    Replies:
    5
    Views:
    380
    Chris Mattern
    Jan 30, 2005
  2. Luke
    Replies:
    2
    Views:
    4,703
    Nigel Wade
    Mar 15, 2007
  3. rote
    Replies:
    8
    Views:
    765
  4. Tony
    Replies:
    2
    Views:
    286
  5. Lars Roland

    Sending email using perl

    Lars Roland, Nov 15, 2004, in forum: Perl Misc
    Replies:
    1
    Views:
    172
    Michele Dondi
    Nov 15, 2004
Loading...

Share This Page