$smtp = Net::SMTP::Multipart->new("mailrelay.someco.com"); $smtp->Header(To => "someone\@someco.com", Subj => "Multipart Mail Demo", From => "me\@someco.com"); $smtp->Text("This is the first text part of the message"); $smtp->FileAttach("c:/tmp/myfile.xls"); $smtp->End();
This module uses the Net::SMTP and Mime::Base64 modules to compose and send multipart mail messages. It uses the Net::SMTP methods, but simplifies formatting of multipart messages using its internal methods Header, Text, FileAttach and End.
The new method invokes a new instance of the Net::SMTP::Multipart class, using the same arguments as the parent method.
The Header method creates the header of the multipart message. It should be called with the following arguments
an array of mail addresses to which the mail is to be sent
the mail address from which the mail is sent
the subject title of the mail
Additionally, you can specify the following additional arguments, if desired
This method generates a text part to the message. The argument provided is treated as text and populates the text part of the message.
This method includes a file (identified in the argument when this is called) within an encoded part of the message. Alternatively, this function can also be called with a reference to a two item array with a display filename as it's first element, and the actual filename as it's second. Just to throw something else into the mix here, you can also specify an open file handle in place of the filename.
This method generates an epilogue part to the message. The argument provided is treated as text and populates the epilogue (which most mail agents do not display). The mail message is then sent and the class instance destroyed.
$smtp = Net::SMTP::Multipart->new("mailrelay.someco.com"); $smtp->Header(To => "someone\@someco.com", Cc => [ "someoneelse\@example.com", "ceo\@example.com" ], Bcc => "coworker\@someco.com", Subj => "Multipart Mail Demo", From => "me\@someco.com"); $smtp->Text("This is the first text part of the message"); $smtp->FileAttach( [ 'ReadThis.doc', 'c:/tmp/ImportantInternalDocument.doc' ]); $smtp->End();
You can contact Orien for bug reports and suggestions for improments on this module at email@example.com. I'll be happy to help in any way that I can. In addition, I'll leave the original author's information here in case you have more luck contacting him than I did.
You can send bug reports and suggestions for improvements on this module to me at DaveRoberts@iname.com. However, I can't promise to offer any other support for this script.
This script is Copyright © 2002 Dave Roberts. All rights reserved.
This script is free software; you can redistribute it and/or modify it under the same terms as Perl itself. This script is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. The copyright holder of this script can not be held liable for any general, special, incidental or consequential damages arising out of the use of the script.
$Log: Multipart.pm $
Revision 1.5.1 2006/01/26 14:34:27 Orien Vandenbergh Fixed the bugs I mentioned in ticket 7706 at http://rt.cpan.org/Public/Bug/Display.html?id=7706
Revision 1.5 2002/11/11 12:12:18 Dave.Roberts corrected bug in documentation synopsis - changed Net::SMTP::MultiPart to Net::SMTP::Multipart
Revision 1.4 2002/04/05 11:36:33 Dave.Roberts change to version number generation code
Revision 1.3 2002/03/27 09:16:29 Dave.Roberts initial pod added
Revision 1.2 2002/03/26 12:03:23 Dave.Roberts added basic pod structure