When attaching text/plain file, SmtpMailSystem treats it as text/plain, not as attachment:

Content-Disposition: attachment;filename="file.txt"
Content-Type: text/plain;name="file.txt"
Content-Transfer-Encoding: base64

...

Solution I found at the moment: in smtp.mail.inc change position of whole block

elseif (strpos($body_part, 'Content-Disposition: attachment;')) {

after first block:

if (strpos($body_part, 'multipart/alternative')) {

Comments

miqmago’s picture

Also another 2 problems detected for drupal 7:

$attachment_new_filename needs to be wrapped with temporary://...
Also file_save_data returns a stdClass object, not a string.
Originally:

$attachment_new_filename = tempnam(realpath(file_directory_temp()), 'smtp');
$file_path               = file_save_data($attachment, $attachment_new_filename, FILE_EXISTS_REPLACE);

  if (!$mailer->AddAttachment($file_path, $file_name)) { // , $file_encoding, $filetype);

Needs to be:

$attachment_new_filename = str_replace(realpath(file_directory_temp()), 'temporary:/', tempnam(realpath(file_directory_temp()), 'smtp'));
$file                    = file_save_data($attachment, $attachment_new_filename, FILE_EXISTS_REPLACE);

  if (!$mailer->AddAttachment($file->uri, $file_name)) { // , $file_encoding, $filetype);
simon georges’s picture

The #1 should be fixed by this commit, so it's a duplicate of #1442514: Sending attachments using modules smtp and mimemail. Please target a specific problem when you create an issue.

Let's see about the problem indicated by the title of the issue.

simon georges’s picture

Version: 7.x-1.0-beta2 » 7.x-1.x-dev

Could you eventually test the (soon to be released) -dev version, as a few things have been fixed since then?

wundo’s picture

Issue summary: View changes
Status: Active » Closed (works as designed)

Closing very old (dead) issues, if you think this is still relevant please re-open.