[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Email attachments and library files



Hi Frances,

sorry for the delay.

>Thanks to Paul Schinder, Thomas Wegner, and Chris Nandor for all the help
>with this problem!
>
>I finally was able to get MIME::Entity working and to write a script that
>sends and email with an attachment.
>
>Now I have one more question, which is just a cosmetic thing but would be
>nice...
>Is there a way to have it include a full name along with the email address
>in the "From:" field?
>
>I found a way to do it with Mail::Address, but when I try to stick it into
>my email-sending script it crashes with a bunch of "out of memory" errors.
>MacPerl is using about 65 MB of memory so I am thinking it is because I
>did something wrong rather than being simply a memory error.
>
>I'm using Net::SMTP to send the message and MIME::Entity to include the
>attachment. Currently I'm setting a "$sender" variable and have the
>following line in my SMTP header section:
>$smtp->mail($sender);
>
>So I tried setting $sender the following way:
>$sender = Mail::Address->new("Full Name",
>                                  "address\@host.edu");

What you get here is an object reference, not a string. It is not a 
very good idea [ ;-) ], if you pass this to $smtp->mail(). Instead, 
use the format() method:

$addr = $sender->format; # now a string:  Full Name <address@host.edu>

Then, you may use the following code:

     $smtp->mail('address@host.edu'); # sender
     $smtp->to('toms_email@mail.tom.de'); # recipient

     $smtp->data(); # begin data

        # header stuff follows
        $smtp->datasend("From: $addr\n");  # will replace the 'From: 
...' that  $smtp->mail produces
        $smtp->datasend("Subject: Yet another mail\n");
        $smtp->datasend("\n"); # empty line -> end of header

        # message body follows
        $smtp->datasend("This is the message body\n.");

     $smtp->dataend(); # end data
     $smtp->quit; # game over

As RFC 821 (SMTP) states on page 4:

"Please note that the mail data includes the memo header
   items such as Date, Subject, To, Cc, From [...]."

>
>without changing the rest of my code (except to include "use
>Mail::Address;"), and now I get all the "out of memory" errors.
>
>Well, it's not a huge deal, but it would be nice. :)
>
>Thanks! :)
>
>Frances Schuetz

Hope that helps.

--Thomas

# ===== Want to unsubscribe from this list?
# ===== Send mail with body "unsubscribe" to macperl-request@macperl.org