Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
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 ( #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 (Abbot) 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 (Chancellor) 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
Node Status?
node history
Node Type: perlquestion [id://999070]
Approved by nemesdani
help
Chatterbox?
[shmem]: Lady_Aleena: what editor are you using, on what platform?
[Lady_Aleena]: shmem, geany on Debian jessie.
[shmem]: some experience with vim?
[Lady_Aleena]: None
[shmem]: I don't know geany, and don't know whether it has support for ctags.
[Lady_Aleena]: ctags?
[shmem]: ctags is a program which (recursively) extracts the symbols from source and stores them in a one-file database. This allows you to query the locations where these symbols (e.g. a subroutine name) are used anywhere in the source code tree...
[shmem]: ...from inside the editor.
[shmem]: apt-get install exuberant-ctags
[Lady_Aleena]: I think I heard vim has a big learning curve.

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (9)
As of 2017-04-27 12:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I'm a fool:











    Results (505 votes). Check out past polls.