in reply to Re: email fails with attachments over 8kb
in thread email fails with attachments over 8kb

Yes, that sort of makes sense except for the fact that a previously compiled version works perfectly. Google isn't refusing any attachments when I use that version using all the same credentials.
  • Comment on Re^2: email fails with attachments over 8kb

Replies are listed 'Best First'.
Re^3: email fails with attachments over 8kb
by talexb (Chancellor) on May 25, 2017 at 16:29 UTC

    So that begs the question .. what are the differences between the version that works perfectly, and this version?

    Alex / talexb / Toronto

    Thanks PJ. We owe you so much. Groklaw -- RIP -- 2003 to 2013.

      That's the million dollar question. I have no way of knowing because I can't decompile the executable that works. Here's some code I got off the internet yesterday that uses Net::SMTP::SSL. I get the exact same problem when I use this code. If you test it with your email specs and add an attachment in the appropriate spot I would be interested to hear your results.
      #!/usr/bin/perl -w use Net::SMTP::SSL; use MIME::Base64; use File::Spec; use LWP::MediaTypes; sub send_mail_with_attachments { my $to = shift(@_); my $subject = shift(@_); my $body = shift(@_); my @attachments = @_; my $from = 'your_email_address'; my $password = 'your_password'; my $smtp; if (not $smtp = Net::SMTP::SSL->new('your_smtp_server', Port => 465, Debug => 1)) { die "Could not connect to server\n"; } # Authenticate $smtp->auth($from, $password) || die "Authentication failed!\n"; # Create arbitrary boundary text used to seperate # different parts of the message my ($bi, $bn, @bchrs); my $boundry = ""; foreach $bn (48..57,65..90,97..122) { $bchrs[$bi++] = chr($bn); } foreach $bn (0..20) { $boundry .= $bchrs[rand($bi)]; } # Send the header $smtp->mail($from . "\n"); my @recepients = split(/,/, $to); foreach my $recp (@recepients) { $smtp->to($recp . "\n"); } $smtp->data(); $smtp->datasend("From: " . $from . "\n"); $smtp->datasend("To: " . $to . "\n"); $smtp->datasend("Subject: " . $subject . "\n"); $smtp->datasend("MIME-Version: 1.0\n"); $smtp->datasend("Content-Type: multipart/mixed; BOUNDARY=\"$boundry\" +\n"); # Send the body $smtp->datasend("\n--$boundry\n"); $smtp->datasend("Content-Type: text/plain\n"); $smtp->datasend($body . "\n\n"); # Send attachments foreach my $file (@attachments) { unless (-f $file) { die "Unable to find attachment file $file\n"; next; } my($bytesread, $buffer, $data, $total); open(FH, "$file") || die "Failed to open $file\n"; binmode(FH); while (($bytesread = sysread(FH, $buffer, 1024)) == 1024) { $total += $bytesread; $data .= $buffer; } if ($bytesread) { $data .= $buffer; $total += $bytesread; } close FH; # Get the file name without its directory my ($volume, $dir, $fileName) = File::Spec->splitpath($file); # Try and guess the MIME type from the file extension so # that the email client doesn't have to my $contentType = guess_media_type($file); if ($data) { $smtp->datasend("--$boundry\n"); $smtp->datasend("Content-Type: $contentType; name=\"$fileName +\"\n"); $smtp->datasend("Content-Transfer-Encoding: base64\n"); $smtp->datasend("Content-Disposition: attachment; =filename=\ +"$fileName\"\n\n"); $smtp->datasend(encode_base64($data)); $smtp->datasend("--$boundry\n"); } } # Quit $smtp->datasend("\n--$boundry--\n"); # send boundary end message $smtp->datasend("\n"); $smtp->dataend(); $smtp->quit; } # Send away! &send_mail_with_attachments('your_email@gmail.com', 'Server just blew +up', 'Some more detail','enter path to attachment here');

        Oh, so you don't have the source code for something that's currently running, perhaps in production? I'm not used to that situation, having used script languages (well, Perl) for close to twenty years.

        I don't currently have the bandwidth to try your code out with my own SMTP service, so at this point all I can suggest is to simplify the problem as much as possible, and turn on whatever verbose/debugging options there are to help you understand which parts are working, and which parts are not working .. for some definition of 'working'.

        Alex / talexb / Toronto

        Thanks PJ. We owe you so much. Groklaw -- RIP -- 2003 to 2013.