Issues

ZF-589: Problem with mail attachment

Description

I tried to send an attachment with a simple text mail using Zend_Mail::addAttachment() method, using default options. The mail is generated correctly but there's some problem with the attachment, as it is malformed when received.

Using standard base64 encoding it looks that there's a problem with line breaks in the attachment bytes. After some trial and error I had success in sending the attachment by setting Zend_Mime::LINELENGTH to 72 (instead of 74), but I didn't investigate why. Please let me know if something is needed to better understand the problem

Comments

Assigning to Matthew, scheduling for 0.7.0 release.

Hi Franco - what transport were you using? Can you snip a portion of the encoded message to show a before / after of the lines that were affected? It may also help to know a little more about the environment you're sending the mail from (Platform, Mail software, etc)

Hi, Transport is default mail(), here's a test script I used:

<?php require_once 'Zend/Mail.php'; $mail = new Zend_MAil(); $mail->setBodyText("Test body"); $mail->setSubject("Test subject"); $mail->setFrom("removed@rem.ove"); $mail->addTo("removed@aaa"); $att = file_get_contents("test.pdf"); $at = $mail->addAttachment($att); $at->filename = "test.pdf"; $mail->send(); ?>

I'll attach two mail messages, one with no changes to Zend framework 0.2.0, the other with Zend_Mime::LINELENGTH = 72. I'll also attach the original test.pdf file. Platform is ubuntu linux 6, postfix, php 5.1.6, apache 2.0

Thanks for the info. I've tried a number of scenarios and can't reproduce the problem you're seeing.

There's a couple of things that may help identify the problem as well - could you try sending the message with different line endings? You can use the code below to change the line ending to either "\r\n" or "\n" to see if that changes anything.


$transport = new Zend_Mail_Transport_Sendmail();
$transport->EOL = "\n";

$mail = new Zend_Mail();
$mail->setBodyText("Test body");
$mail->setSubject("Test subject");
$mail->setFrom("test@test.com");
$mail->addTo("test@test.com");
$att = file_get_contents("test.pdf");
$at = $mail->addAttachment($att);
$at->filename = "test.pdf";
$mail->send($transport);

Secondly, I'm scratching my head wondering why 74 chars has been used when 76 chars is the RFC2045 recommendation. Can you revert back to 74 chars for the above test, then perform another round of tests with 76 chars and see if that changes anything? I'm interested to see if your local mail (Postfix) is being difficult. You may also wish to try the SMTP transport to see if the problem persists.

Hi, I had no luck with "\n" but it works if I comment the second line ($transport->EOL = "\n";) and set LINELENGTH to 76. Looking at the mail files I attached I noticed that, for each line, the sequence \r\n is repeated twice (there's a blank line between one encoded line and the other). MAybe this could be of some help.

I experimented a bit with this issue, here's what I discovered:

  1. I couldn't make Zend_Mail_Transport_Smtp work, even with a small email:

//I tried this server, maybe another one will work
$tr = new Zend_Mail_Transport_Smtp("smtp.tiscali.it"); 
Zend_Mail::setDefaultTransport($tr);
$m = new Zend_Mail();
$m->setFrom("valid@email.addr");
$m->addTo("valid@email.addr");
$m->setSubject("Blah blah blah");
$m->setBodyText("AAAAA");
$m->send();

With this code I get an error 554 Message refused

  1. Using Zend_Mail_Transport_Smtp passing "localhost" (Ubuntu 6.10 with Postfix installed) to the constructor I can send the mail correctly, even with LINELENGTH=74, so for now I'll be using this method.

Closed for now - but If this resurfaces and we can get some more tangible tests then it will be given some further consideration.