Link to home
Start Free TrialLog in
Avatar of BrentNJ
BrentNJ

asked on

Adding Subject and From to sendmail

Hi, based on server restrictions and a recently asked question, I am sending text file attachments using

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

How do I add Subject, From, and possibly text in the body of the email?
(the -f did not show the From when received)

A previous question described

echo -e "Subject: A subject\n\nMessage text" | sendmail -f my@address recipient@address

to add the Subject

But I couldn’t put it all together.

Thanks!!
Avatar of Tintin
Tintin

You *really* would have been better off using MIME::Lite as it is easier to set all these things, plus it makes it much more portable when moving between systems.

Was there any good reason you decided against using MIME::Lite?

Avatar of BrentNJ

ASKER

Well, issue 5 got worse -

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.

Now the text only shows up in the body, no longer with the attachment.

The last cutoff for registration is coming up. I expect a rush of last minute sign-ups, so I need to get something going.

If you have any other ideas please let me know.

Thanks!!



If you are using sendmail with MIME::Lite, you don't need to explicity print the message to a sendmail stream.

Just doing

$msg->send;

will work fine.

If you are not seeing an attachment, please post the test code you are using.  MIME::Lite is a *very* popular module, so I'd be surprised if you were getting any problems due to the module itself.
SOLUTION
Avatar of robysath
robysath

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of BrentNJ

ASKER

I will try above suggestions.

Thanks
Avatar of BrentNJ

ASKER

Tinton,

Here is the code. The text file comes through in the body instead of as an attachment. I noticed that the sample for a binary file attachment had a line Encoding => 'base64',
Do I need a similar line for a test attachment?

Thanks


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


$TXTFILE="nc/jh10083.txt";
$SUBJECT="Any attchement?";
$MAILTO="me\@myhost.net";

# Create a new multipart message:
$msg = new MIME::Lite
   From    => "$MAILFROM",
   To      => "$MAILTO",
   Cc      => "$MAILCOPY",
   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->send;
close(SENDMAIL);
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of BrentNJ

ASKER

Will do. I'll try it now.
Avatar of BrentNJ

ASKER

Message arrived with no attachment and no text in body of message.
Avatar of BrentNJ

ASKER

I did use an absolute path for my $txtfile.
I was assuming the path you gave in your sample code was the actual path, hence the reason I made the comment about using absolute paths.

Before you construct the mail message, add:

die "$txtfile not found" unless -f $txtfile;

And see what the result is.
Avatar of BrentNJ

ASKER

Thanks everyone for your help. It works but not consistently. I will probably change hosting services next year.