Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > FAQ 9.21 How do I use MIME to make an attachment to a mail message?

Reply
Thread Tools

FAQ 9.21 How do I use MIME to make an attachment to a mail message?

 
 
PerlFAQ Server
Guest
Posts: n/a
 
      03-09-2011
This is an excerpt from the latest version perlfaq9.pod, which
comes with the standard Perl distribution. These postings aim to
reduce the number of repeated questions as well as allow the community
to review and update the answers. The latest version of the complete
perlfaq is at http://faq.perl.org .

--------------------------------------------------------------------

9.21: How do I use MIME to make an attachment to a mail message?

This answer is extracted directly from the "MIME::Lite" documentation.
Create a multipart message (i.e., one with attachments).

use MIME::Lite;

### Create a new multipart message:
$msg = MIME::Lite->new(
From =>'(E-Mail Removed)',
To =>'(E-Mail Removed)',
Cc =>'(E-Mail Removed), http://www.velocityreviews.com/forums/(E-Mail Removed)',
Subject =>'A message with 2 parts...',
Type =>'multipart/mixed'
);

### Add parts (each "attach" has same arguments as "new"):
$msg->attach(Type =>'TEXT',
Data =>"Here's the GIF file you wanted"
);
$msg->attach(Type =>'image/gif',
Path =>'aaa000123.gif',
Filename =>'logo.gif'
);

$text = $msg->as_string;

"MIME::Lite" also includes a method for sending these things.

$msg->send;

This defaults to using sendmail but can be customized to use SMTP via
Net::SMTP.



--------------------------------------------------------------------

The perlfaq-workers, a group of volunteers, maintain the perlfaq. They
are not necessarily experts in every domain where Perl might show up,
so please include as much information as possible and relevant in any
corrections. The perlfaq-workers also don't have access to every
operating system or platform, so please include relevant details for
corrections to examples that do not work on particular platforms.
Working code is greatly appreciated.

If you'd like to help maintain the perlfaq, see the details in
perlfaq.pod.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Problem with Email::MIME and Email::MIME::Attachment::Stripper ecureuil Perl Misc 0 05-28-2006 01:47 AM
Mail::MboxParser and Email::MIME::Attachment::Stripper Arvin Portlock Perl Misc 0 05-03-2006 10:18 PM
tomcat 4.x : setting mime type for a directory or setting a default mime type CJ Java 1 10-29-2004 07:51 PM
When use MIME::Lite module the attachment clip sign not shown for attachments Jane Humbrey Perl Misc 5 09-01-2003 12:23 AM



Advertisments