Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
 
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
Attach text file to email

Posted by hugo_owen (hugo_owen), 9 May 2005
Trying to attach a text log file with perl and I keep getting the following message when the email comes in my inbox - this error is n the message body:

Subject: MIME-Version: 1.0Content-Description: Replacement for objectionable contentContent-Type: Text/HTMLX-NAIMIME-Modified: 1<html><head><meta HTTP-EQUIV="Content-Type" content="text/html"><meta HTTP-EQUIV="charset" content="utf-8"> <title>CORRUPT MAIL ALERT</title></head>    <body> <h1><font color="#FF0000">CORRUPT MAIL ALERT</font></h1> <p>A message or attachment was found to be corrupt and has been removed.</p> <p>Cause of corruption: Invalid headers. </p> <p>Copyright &copy; 1993-2003, Networks Associates Technology, Inc.<br>      All Rights Reserved.<br> <a href="http://www.mcafeesecurity.com">http://www.mcafeesecurity.com</a></p> </body></html>





Below is the code: - Please help - driving me mad.

use Net::SMTP;
use MIME::Lite;

my $nodename = $ENV{"COMPUTERNAME"};
my $from_address =  "${nodename}\@arup.com";
my $to_address = 'email_address';
my $subject = 'MIME Net::SMTP test';
my $mime_type = 'TEXT';
my $message = "Hello world!\n";

# Create the initial text of the message
my $mime_msg = MIME::Lite->new(
  From => $from_address,
  To   => $to_address,
  Subject => $subject,
  Type => $mime_type,
  Data => $message
  )
 or die "Error creating MIME body: $!\n";

my $filename = 'c:\tmp\test.txt';

# Attach the test file
$mime_msg->attach(
#   Type => 'application/zip',
  Type => 'TEXT',
  Path => $filename,
  )
 or die "Error attaching test file: $!\n";

my $message_body = $mime_msg->body_as_string();
my $servername = "smtp@arup.com";
$smtp = Net::SMTP->new($servername);
       die " couldn't connect to server" unless $smtp;

$smtp->mail( $from_address );
$smtp->to( $to_address );

$smtp->data();
$smtp->datasend($message_body);
$smtp->dataend();


Posted by admin (Graham Ellis), 10 May 2005
Have you tried saving out the message_body to a file on the machine that's generating the email and seeing what's there - it might well give you the clue.   The error message that you've posted is from your own mail filtering system and it's removing the evidence of what the real problem is ...

Posted by hugo_owen (hugo_owen), 10 May 2005
Thanks Graham, I've printed out to a file but it does'nt mean much to me any ideas what wrong??

This is a multi-part message in MIME format.

--_----------=_111571609534560
Content-Disposition: inline
Content-Length: 13
Content-Transfer-Encoding: binary
Content-Type: text/plain

Hello world!

--_----------=_111571609534560
Content-Disposition: inline; filename="test.txt"
Content-Length: 14
Content-Transfer-Encoding: binary
Content-Type: text/plain; name="test.txt"

THIS IS A TEST
--_----------=_111571609534560--




Posted by admin (Graham Ellis), 10 May 2005
Looks like you need to initialise your MIME boundary.  I would expect to see something like this as part of the email header

Code:
MIME-Version: 1.0
Content-Type: multipart/alternative;
     boundary="09845039450394rahhdkY-cmwdwiirmar"


Then the sections look something like

Code:
--09845039450394rahhdkY-cmwdwiirmar
Content-Type: text/plain;
     charset = "ISO-8859-1"
Content-Transfer-Encoding: 8bit



--09845039450394rahhdkY-cmwdwiirmar
Content-Type: text/html;
     charset = "ISO-8859-1"
Content-Transfer-Encoding: 8bit

<html>
<body>


(These examples have been "sampled" from an incoming bulk email I was sent   )

Translated ... means that you've probably got a header missing and so the boundaries such as you've sent them are illegal .... there's probably an extra call in one of those Perl modules to set it up.   Have a look and if you can't find it post further and I'll look overnight ... won't get a chance this afternoon I'm afraid

Posted by Custard (Custard), 10 May 2005
From memory, the mime boundary can be anything you like as long as it's unique (within the realm of the encapsulating email).

Can we see a dump of the headers too, as the original error refers to corrupt headers.

I wonder if your line mime_type = "TEXT" should be something like text/plain.

B



This page is a thread posted to the opentalk forum at www.opentalk.org.uk and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2024: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho