Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Corruption of GIF image in email via MIME::Lite 2

Status
Not open for further replies.

1DMF

Programmer
Jan 18, 2005
8,795
GB
I seem to be getting a corruption when I email an in-line embedded GIF.

Here is the original file that was uploaded via my web app, it saved correctly and displays on the web page absolutely fine....

hlp_print.gif


When a new banner is added to the system, a copy of the banner is sent to certain employees as a notification that the banner is live along with details of clickthrough tracking, expiry date of the advert , location on the extranet etc..

I have added several JPG / PNG static files without problems and the email received displays them fine, however the above image is appearing in the email as follows...

corrupt.gif


And as you can see all the animation is also missing.

Why is this happening?

I'm reading the file using
Code:
# read image file to raw binary and set for result
local $/ = undef;
open (my $img, '/images/banners/' . $banner[0]{'Page'} . '_' . $banner[0]{'RecID'} . '.' . $banner[0]{'Ext'}) or die $!;
binmode $img;
$result->{data}->{raw} = <$img>;
close $img;

Which is passed to the emailing module that performs the MIME::Lite method...
Code:
$msg->attach( 
Encoding => 'base64',
Type     => 'image/' . $img->{ext},
Data     => $img->{raw},
Id       => $img->{id},
Disposition => 'inline'
 );

And then marked up in the email like so...
Code:
<img src="cid:<tmpl_var name='img'>" title="<tmpl_var name='tooltip'>" alt="<tmpl_var name='tooltip'>" />

The image is only 95kb in size so it can't be a size issue, it also appears to always happen when ever I use a GIF image regardless of it containing animation or just being a static GIF.

Something I am doing must be corrupting the image information somehow?

Your advise is very much appreciated.
1DMF

"In complete darkness we are all the same, it is only our knowledge and wisdom that separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"
Free Electronic Dance Music
 
Well I've been bashing my head all day with the nice folks on Perl IRC and had to re-write my MIME::Lite TLS hack and replace Net::SMTP::TLS with Net::SMTPS as even basic HTML emails were being corrupted by Net::SMTP::TLS.

So I wanged the refactor over to the new system and tested sending the banner advert email and it's sorted the corruption.

I don't know what Net::SMTP::TLS was doing to my emails by it was doing something weird!


"In complete darkness we are all the same, it is only our knowledge and wisdom that separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"
Free Electronic Dance Music
 
I've been running the refactor for a week now and all seems good.

I have updated my MIME::Lite TLS page with the new changes :
The module has had a few improvements made, but the core change is the update of the mimelite hack to use Net::SMTPS instead of Net::SMTPS::TLS...

Code:
#######################
# MIME::Lite TLS Hack #
#######################
sub mimehack {                        
            
    @MIME::Lite::SMTPS::ISA = qw( Net::SMTPS ); 
    sub MIME::Lite::SMTPS::print { shift->datasend(@_); }
                
    # Add MIME::Lite hack to support TLS authentication / encryption         
    *MIME::Lite::send_by_smtp_tls = sub { 
        
        # Set objects & arguments
        my($self, $sendmail, @args) = @_; 

        # Create SMTPS client:                  
        eval
        {                                    
                                
            my $smtp = MIME::Lite::SMTPS->new(@args);   
            $smtp->mail($self->get('From'));          
            $smtp->to($self->get('To'));    
            $smtp->cc($self->get('Cc')); 
            $smtp->bcc($self->get('Bcc'));                                                                      
            $smtp->data(); 

            # MIME::Lite can print() to anything with a print() method: 
            $self->print_for_smtp($smtp); 
            $smtp->dataend();
            $smtp->quit();  
                    
        }; 

        # check for TLS errors and set warnings
        $sendmail->warning($@) if $@;                   

        return ($@)?0:1;     
        
    }; 
                  
}

"In complete darkness we are all the same, it is only our knowledge and wisdom that separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"
Free Electronic Dance Music
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top