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

Hi,

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?


#!/usr/bin/perl
use MIME::Lite;

    $msg = MIME::Lite->new(
                 From    =>'me@myhost.com',
                 To      =>'me@myhost.com',
                 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");
exit;
BrentNJAsked:
Who is Participating?
 
ahoffmannCommented:
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.
0
 
andreifCommented:
are you getting any error message?

what if you replace /usr/sbin/sendmail with  /var/qmail/bin/qmail-inject ?
0
 
BrentNJAuthor Commented:
No error message. Unless I use /var/qmail/bin/qmail-inject instead of sendmail.
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
jmcgOwnerCommented:
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).
0
 
BrentNJAuthor Commented:
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 me@myaddress.net

I suppose getting Mime-Lite to work would be the best way to go.
0
 
BrentNJAuthor Commented:
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.

Thanks



#!/usr/bin/perl

use MIME::Lite;


$TXTFILE="nc/jh10083.txt";
$SUBJECT="Your attachment";
$MAILTO="me\@myhost.com";
$MAILFROM="$ENV{LOGNAME}";

# 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");
$msg->print(\*SENDMAIL);
close(SENDMAIL);
0
 
ahoffmannCommented:
open(F,">email.txt") && print F $msg->as_string(); close(F);
system("cat email.txt | /var/qmail/bin/qmail-inject");
0
 
jmcgOwnerCommented:
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?
0
 
ahoffmannCommented:
> ..  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.
0
 
BrentNJAuthor Commented:
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 me@myaddress.net 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
0
 
TintinCommented:
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;
0
 
BrentNJAuthor Commented:
Thanks everyone, I ended up using

system("cat nc/jh10083.txt | unix2dos | uuencode nc/jh10083.txt | /usr/sbin/sendmail me@myhost.com");
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.