Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Perl Email attchment using Sendmail with out nay perl Modules like (MIME::Lite .etc )

by ppnair (Initiate)
on Oct 15, 2012 at 11:46 UTC ( [id://999070]=perlquestion: print w/replies, xml ) Need Help??

ppnair has asked for the wisdom of the Perl Monks concerning the following question:

have a file called 'test.txt',which I want to send it as an email attachment also want the contents in Email Message body.

(I want to achieve with sendmail with out using any Perl modules Like MIME::Lite .etc.)I could manage to write a Perl script with till here ,which will paste the content in the email body.

Please help me to make the same file also an attachment in same email.

#!/usr/bin/perl use strict; use warnings; $title='Test'; $to='test@mydomain.com'; $from= 'test@example.com'; $subject='Test mail'; my $file = "test.txt"; open(MAIL, "|/usr/sbin/sendmail -oi -t "); print MAIL "To: $to\n"; print MAIL "From: $from\n"; print MAIL "Subject: $subject\n\n"; print MAIL "Content-type: text/html\n\n"; open(FILE, "$file") or die "Cannot open $file: $!"; print MAIL <FILE>; close(FILE); close(MAIL);
  • Comment on Perl Email attchment using Sendmail with out nay perl Modules like (MIME::Lite .etc )
  • Download Code

Replies are listed 'Best First'.
Re: Perl Email attchment using Sendmail with out nay perl Modules like (MIME::Lite .etc )
by McA (Priest) on Oct 15, 2012 at 12:03 UTC

    Hi

    If you want to build a mail with attachment you have to build a valid MIME-message. That is not trivial. That's why there are so many big packages at CPAN. But if you really have the need, than I would suggest to look at the cli tool mail of your OS. The newer versions are able to handle attachments.

    So my proposal:

    my $rc = system("echo '' | mail -s 'Test' -a $file $to");

    Best regards
    McA

      Thank you

      Getting below error when i try mail command

      mail: invalid option -- a Usage: mail [-iInv] [-s subject] [-c cc-addr] [-b bcc-addr] to-addr .. +. [-- sendmail-options ...] mail [-iInNv] -f [name] mail [-iInNv] [-u user]

        That's the reason I wrote: ... the newer versions ...

        So, in this special case you're out of luck. Is there a reason you can't install MIME::Lite as suggested by another monk here?

        Best regards
        McA

Re: Perl Email attchment using Sendmail with out nay perl Modules like (MIME::Lite .etc )
by tobyink (Canon) on Oct 15, 2012 at 12:09 UTC
Re: Perl Email attchment using Sendmail with out nay perl Modules like (MIME::Lite .etc )
by choroba (Cardinal) on Oct 15, 2012 at 12:35 UTC
    Crossposted at StackOverflow. It is considered polite to inform about crossposting so people not attending both sites do not waste their time solving a problem already closed at the other end of the internet.
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

      Am sorry .I was not aware that both site are related.

        They are not. And that is the point.
        لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
Re: Perl Email attchment using Sendmail with out nay perl Modules like (MIME::Lite .etc )
by Jenda (Abbot) on Oct 15, 2012 at 22:01 UTC

    The important question is WHY? If you can upload your scripts, you can upload Perl-only modules. If you have a computer with a binary compatible OS and Perl version you can compile and upload even modules with XS parts.

    Jenda
    Enoch was right!
    Enjoy the last years of Rome.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (2)
As of 2024-04-20 01:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found