Mail::Sender blocked - Use MIME-Lite to send text file as Attachment

Posted on 2003-10-24
Last Modified: 2008-02-01

Mail:Sender no longer works where my site is hosted. They decided make a change. Scripts can no longer use SMTP.

They suggested that I do
shell_exec("cat email.txt | /var/qmail/bin/qmail-inject");
but I don't know enough about MIME to make it so.

So I thought that I could use MIME-Lite. But it didn't work. No mail is delivered.

Any ideas?

use MIME::Lite;

    $msg = MIME::Lite->new(
                 From    =>'',
                 To      =>'',
                 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 file you wanted"
    $msg->attach(Type     =>'text/plain',
                 Path     =>'nc/jh10083.txt',
                Filename =>'nc/jh10083.txt',
         Disposition => 'attachment'
$msg->send('sendmail', "/usr/sbin/sendmail");
Question by:BrentNJ
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 2
  • +2

Assisted Solution

andreif earned 20 total points
ID: 9617878
are you getting any error message?

what if you replace /usr/sbin/sendmail with  /var/qmail/bin/qmail-inject ?

Author Comment

ID: 9619550
No error message. Unless I use /var/qmail/bin/qmail-inject instead of sendmail.
LVL 20

Expert Comment

ID: 9620219
It looks to me like you should be able to use the 'sendmail' method to send mail via qmail-inject. It's one of qmail's advertised compatibilities.

$msg->send( 'sendmail', "/var/qmail/bin/qmail-inject");

If you've already tried this, we'd need to see whatever error messages are produced, to make much further progress. The same people who cut off your SMTP access may have done something that requires you to go through an extra hoop (but writing the outgoing mail to an external mail.txt file just so you can 'cat' it through a pipe to 'qmail-inject' would seem to be a pretty silly hoop to have to go through).

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.


Author Comment

ID: 9620662
Previously tried
$msg->send('qmail', "/var/qmail/bin/qmail-inject");
which had error
Can't locate object method "send_by_qmail" via package "MIME::Lite"

I just tried
$msg->send( 'sendmail', "/var/qmail/bin/qmail-inject");
which has same problem as
$msg->send('sendmail', "/usr/sbin/sendmail");
 ---- no email is received at destination

The following sends the text file from the command line as an attachment, but removes line feeds or form feeds (not sure which but file in notepad is on one line - looks OK in VIM)
cat nc/jh10083.txt | uuencode nc/jh10083.txt | /usr/sbin/sendmail

I suppose getting Mime-Lite to work would be the best way to go.

Author Comment

ID: 9620827
The following works - it sends the attachment with proper line/form feeds.

One last question, besides attaching the file, the contents are including in the message itself. I wanted to send a different message.



use MIME::Lite;

$SUBJECT="Your attachment";

# Create a new multipart message:
$msg = new MIME::Lite
   From    => "$MAILFROM",
   To      => "$MAILTO",
   Subject => "$SUBJECT",
   Type    => 'multipart/mixed';

# Add parts (each "attach" has same arguments as "new"):
attach $msg
   Type     => 'text/plain',
   Path     => "$TXTFILE";

# Output the message to sendmail

open (SENDMAIL, "| /usr/sbin/sendmail -t -oi");
LVL 51

Expert Comment

ID: 9620877
open(F,">email.txt") && print F $msg->as_string(); close(F);
system("cat email.txt | /var/qmail/bin/qmail-inject");
LVL 20

Assisted Solution

jmcg earned 130 total points
ID: 9621525
It's getting more and more odd. If you can pipe something into sendmail explicitly, why the heck won't it work using MIME::Lite's normal methods? Your flags "-t -oi" match MIME::Lite's except it adds "-oem" to say "mail back errors".

I don't imagine you have access to your mail logs to see if any entry appears when you attempted to send mail with either sendmail or qmail-inject using the methods we were originally proposing, do you?
LVL 51

Expert Comment

ID: 9622164
> ..  why the heck won't it work using MIME::Lite ..
'cause it uses some defaults, like /usr/lib(sendmail, which might not be accurate on this server
If the ISP responds with a recomendation, you either should use it, or ask why this must be done this (strange and unsecure) way.

Author Comment

ID: 9622452
Thanks everyone. Yes its odd. This company was working out well for me until recently. After an upgrade, I could access files OK with SSH but not FTP; They added a footer to all email about reporting SPAM; They blocked SMTP; Probably something else.

Anyway, I don't have access to any mail logs.

To sum up issue with attaching files
1) Mail::Sender won't work anymore as SMTP is blocked from scripts;
2) MIME::Lite with $msg->send('sendmail', "/usr/sbin/sendmail"); or $msg->send( 'sendmail', "/var/qmail/bin/qmail-inject"); results in no email being delivered and no notification of failed delivery to originating address;
3) shell_exec("cat email.txt | /var/qmail/bin/qmail-inject"); is too cumbersome - I don't want to write MIME details in email.txt to denote attachments;
4) cat nc/jh10083.txt | uuencode nc/jh10083.txt | /usr/sbin/sendmail sends an attachment but concatenates the text into one line; and

5) MIME::Lite with open (SENDMAIL, "| /usr/sbin/sendmail -t -oi");
$msg->print(\*SENDMAIL); close(SENDMAIL);
works great, but also adds the text file contents into the body of the email itself.

At this point item 5 is the closest, but I’m nervous that if item 2 doesn’t work, then it’s just a matter of time before item 5 stops working.

For item 5, any idea how to eliminate the text file contents from displaying in the body of the email itself?

Anything else that I should try or be concerned with?

Thanks again
LVL 51

Accepted Solution

ahoffmann earned 130 total points
ID: 9623345
sounds that the culprit is sendmail (or whatever your ISP installed under this name).
sendmail itself cannot handle attachments propper, you need to do it in the stream (mail body) piped to sendmail.
MIME::Lite does this for you.
If it does not send mails, you need to check the logfiles (you need help from your ISP there).
If all fails, you may use Net::SMTP and compute the mail header and body yourself, and then send it using native SMTP commands (using Net::SMTP). This gives you at least the chance to catch the errors from you mail-server.
LVL 48

Assisted Solution

Tintin earned 20 total points
ID: 9631289
I'd try:

$mailtxt = $msg->print;

open QMAIL, "|/var/qmail/bin/qmail-inject" or die "Can not start qmail $!\n";
print QMAIL $mailtxt;
close QMAIL;

Author Comment

ID: 9651498
Thanks everyone, I ended up using

system("cat nc/jh10083.txt | unix2dos | uuencode nc/jh10083.txt | /usr/sbin/sendmail");

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (,  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

626 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question