Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Need a Mail::SendEasy example using attachments

by roboticus (Chancellor)
on Aug 16, 2006 at 19:27 UTC ( [id://567750]=note: print w/replies, xml ) Need Help??


in reply to Need a Mail::SendEasy example using attachments

keithneargarder--

I don't have one for Mail::SendEasy, but I have one I did a while ago using Mime::Lite and Net::SMTP. Here it is, if it'll help...

#!/usr/bin/perl #------------------------------------------------------------------- # faxer.pl <recipient> <file> # # Send file <file> to <recipient>. Note that the recipient field is # a specially formatted field that contains recipient name, fax #, # and email address of the fax server, like so: # # "/name=Lonnie Phillips/fax=5551234/<rfax@npc.net>" # # 20050111 Roboticus - Added comments, some error checking # ???????? LPhillips - originally written #------------------------------------------------------------------- use strict; use MIME::Lite; MIME::Lite->send('smtp','mail.your.domain',Timeout=>60); use Net::SMTP; my $smtp = Net::SMTP->new('mail.your.domain', Debug=>1); print $smtp->domain,"\n"; my $usage= 'usage: faxer.pl <recipient> where: <recipient> = Fax address, formatted like: "/name=Roboticus/fax=5551234/<rfax@your.domain>" '; #my $fax_dest = @ARGV[0] or die $usage . "\nmissing <recipient>"; my $msg = MIME::Lite->new( To => '/name=%fromName%/fax=%toFax%/<rfax@your.domain>', From => 'MailBot@your.domain', Subject => 'Roboticus\'s test fax', Type => 'multipart/related', ) or die "Error creating MIME container!\n"; $msg->attach( Type => 'text/html', Data => qq {<html> <body> <img src="cid:ltrhead.gif"> </p> <div align="center"> <table border="1"> <tr align="center"><td colspan="2">TO</td><td colspan="2">FROM</td></ +tr> <tr><td align="right">Name:</td><td>%toName%</td><td align="right">Na +me:</td><t d>%fromName%</tr> <tr><td align="right">Fax:</td><td>%toFax%</td><td align="right">Fax: +</td><td>% fromFax%</td></tr> <tr><td></td><td></td><td align="right">Phone:</td><td>%fromPhone%</t +d></tr> <tr><td></td><td></td><td align="right">EMail:</td><td>%fromEMail%</t +d></tr> </table> </div> <hr> </p> To Whom It May Concern,</p> Regional Security is currently conducting a review on merchant %MerchID% "%MerchName%" for a batch of \$%MerchBatch%.</p> All funds are on hold until the review is complete. If you have any questions or information, please feel free to contact me at %fromPhone +% or email me at %fromEMail%.</p> Thank You,</p> %fromName% </body> </html> }, ) or die "Error creating HTML!\n"; $msg->attach( Type => 'image/gif', Id => 'ltrhead.gif', Path => 'fake_letterhead.gif', ) or die "Error adding image!\n"; open(OUTF,">faxer.mht") or die "Can't open output file"; print OUTF $msg->as_string; close(OUTF); $smtp->mail('mmason@npc.net'); ##$smtp->to('/name=Roboticus/fax=5551234/<rfax@your.domain>'); $smtp->to('roboticus@your.domain'); $smtp->data(); $smtp->datasend($msg->as_string); $smtp->dataend(); $smtp->quit();

Note: I've hacked out a little proprietary stuff, and this is just an experimental (proof of concept) program I wrote some time ago. It functions, but will need some tweaking!

--roboticus

Replies are listed 'Best First'.
Re^2: Need a Mail::SendEasy example using attachments
by duckyd (Hermit) on Aug 16, 2006 at 22:02 UTC
    I'm not quite sure why you need to use Net::SMTP in your example, I've had luck with code like the following:
    use strict; use warnings; use MIME::Lite; my $msg = MIME::Lite->build( From => 'from@mail.address', To => 'recipient@mail.address', Subject => 'some subject', Type => 'multipart/mixed', ); $msg->attach( Type => 'TEXT', Data => "see attached file\n\n" ); $msg->attach( Type => 'AUTO', # change AUTO to your prefered type if +you wish Path => '/path/to/some/file', ); # MIME::Lite->send('smtp', 'some.smtp.host' ); # don't use sendmail, +see POD $msg->send();
      duckyd--

      I don't know that I needed it, but after hacking around with it last year, once I got it working, I stopped.

      Next time I have to do some EMail stuff, I'll use your suggestion and tune up the code a bit. Thanks!

      --roboticus

Sending an attachment with MIME::Lite. RFC2111 Content-Id requirements
by imp (Priest) on May 14, 2007 at 19:13 UTC
    RFC2111 specifies:
    Note: in Internet mail messages, the addr-spec in a Content-ID [MIME] or Message-ID [822] header are enclosed in angle brackets (<>).
    Whether this is neccesary depends on the mail client. Gmail requires the angle brackets, Outlook does not. To make this work in the above example this should be used instead:
    $msg->attach( Type => 'image/gif', Id => '<ltrhead.gif>', Path => 'fake_letterhead.gif', );
    The current version of MIME::Lite (3.0.1) does not add the angle brackets, but that could change in the future so be sure to check the documentation.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://567750]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2024-04-24 02:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found