Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2003-10-24
12
Medium Priority
?
987 Views
Last Modified: 2008-02-01
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;
0
Comment
Question by:BrentNJ
  • 5
  • 3
  • 2
  • +2
12 Comments
 
LVL 6

Assisted Solution

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

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

Author Comment

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

Expert Comment

by:jmcg
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).
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:BrentNJ
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 me@myaddress.net

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

Author Comment

by:BrentNJ
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.

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
 
LVL 51

Expert Comment

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

Assisted Solution

by:jmcg
jmcg earned 520 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?
0
 
LVL 51

Expert Comment

by:ahoffmann
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.
0
 

Author Comment

by:BrentNJ
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 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
 
LVL 51

Accepted Solution

by:
ahoffmann earned 520 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.
0
 
LVL 48

Assisted Solution

by:Tintin
Tintin earned 80 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;
0
 

Author Comment

by:BrentNJ
ID: 9651498
Thanks everyone, I ended up using

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

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
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

876 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