Hello,

I need to send attachments using smtp and mimemail modules and ended up adding some code to the mail() function in smtp.mail.inc just before the $mailer->Send() call.

    if (isset($message['params']['attachments'])) {
        $attachments = $message['params']['attachments'];
        foreach ($attachments as $attachment) {
            $filepath = $_SERVER['DOCUMENT_ROOT'] . base_path() . $attachment['filepath'];
            $mailer->AddAttachment($filepath);
        }
    }

It seems to work fine. There are only two "Deprecated function" messages coming from phpmailer. But this is not a problem.

It would be nice to have this feature in a future release of smtp module. ;-)

Michael

Files: 
CommentFileSizeAuthor
#19 patch.txt1.15 KBmoonberry
#12 smtp-1442514-12.patch1.14 KBtobiasb
PASSED: [[SimpleTest]]: [MySQL] 0 pass(es).
[ View ]
#8 1442514-8.patch1.05 KBkillua99
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch 1442514-8.patch. Unable to apply patch. See the log in the details link for more information.
[ View ]
#1 mimemail-attachment-1442514-1.patch850 bytesmavimo
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch mimemail-attachment-1442514-1.patch. Unable to apply patch. See the log in the details link for more information.
[ View ]

Comments

Issue tags:+mimemail, +attachment
StatusFileSize
new850 bytes
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch mimemail-attachment-1442514-1.patch. Unable to apply patch. See the log in the details link for more information.
[ View ]

Improved patch to support sending mail using filepath and filecontent.

Into mimemail we can send mail using:

<?php
  $params
= array(
   
'attachments' => array(
     
0 => array(
       
'filecontent' => '<?xml version="1.0" encoding="UTF-8"? ><test><item /></test>',
       
'filename' => 'test.xml',
       
'filemime' => 'text/xml',
      ),
     
1 => array(
       
'filepath' => 'public://test.xml',
       
'filename' => 'test.xml',
       
'filemime' => 'text/xml',
      ),
    ),
  );
?>

in accord with mimemail docs.

I'm sorry, I'm new to these stuff. What should I do with this .patch file or where should I add it?

Status:Active» Reviewed & tested by the community

Thanks for the patch @mavimo , patch #1 worked like a charm for me.

I think this should be ported to the next release.

Gabriel

Status:Reviewed & tested by the community» Fixed

Commited, thanks! :)

Version:7.x-1.0-beta1» 7.x-1.x-dev
Category:feature» support
Status:Fixed» Active

When I send a attachment application/pdf mime file it's apear.

The data could not be saved because the destination /tmp/smtpc856Ac is invalid. This may be caused by improper use of file_save_data() or a missing stream wrapper.

File smtp.mail.inc line 432
version = "7.x-1.0-beta2+3-dev"

Ok I can't do a patch cause I'm not using git (sorry) but you can follow this instruction.

Replace all the attachment_new_filename for this.

              $attachment_new_filename = drupal_tempnam('temporary://', 'file');
              $file_path               = file_save_data($attachment, $attachment_new_filename, FILE_EXISTS_RENAME);
              $real_path               = drupal_realpath($file_path->uri);
              if (!$mailer->AddAttachment($real_path, $file_name)) { // , $file_encoding, $filetype);
  

This is a good use when you creat a tmp name with tmp directory.

I get this error with mimemail (rule) and smtp

Notice: Undefined index: filename in SmtpMailSystem->mail() (Line 455 of sites/all/modules/contrib/smtp/smtp.mail.inc).
Notice: Undefined index: filemime in SmtpMailSystem->mail() (Line 455 of sites/all/modules/contrib/smtp/smtp.mail.inc).

Status:Active» Needs review
StatusFileSize
new1.05 KB
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch 1442514-8.patch. Unable to apply patch. See the log in the details link for more information.
[ View ]

An issue failing with temporary files.

Category:support» bug

Change status.

Status:Needs review» Reviewed & tested by the community

The patch in #8 definitely fixed my problem with temporary files from the MIME not saving correctly. Thanks for the patch, killua99!!

Status:Reviewed & tested by the community» Fixed

Last patch was committed.

Status:Fixed» Needs review
StatusFileSize
new1.14 KB
PASSED: [[SimpleTest]]: [MySQL] 0 pass(es).
[ View ]

Ok my bug is not solved with the latest release.

When you send a html-email via rules to use the attachments, mimemail creates only an array with the filepath key, no filename or something.

rules_action_mimemail -> drupal_mail -> mimemail_mail
(attachment is a string) -> ... -> attachment is an array.

Having the same issue as #7. Patch in #12 did not work to solve.

@cgdrupalkwk then your rule is wrong ;-)

Did you test send an attachment without using rules? Because this one seen another kind of issue but with the link of attachment. You use Rules + mimemail + smtp. This issue only use mimemail and smtp. Better to open a new one?

Ok lets say the patch is a followup. ;-)

I am having a similar problem with the attachment files. I don't use rules only the mimemail with the simplenews module and the error that i am getting is the bellow:

Fatal error: Cannot use object of type stdClass as array in C:\inetpub\wwwroot\sites\all\modules\smtp\smtp.mail.inc on line 449

The solution i found is to delete the lines 447 to 456 and the problem solved. Now i can send newsletters with the attached files.

I found that at line 449 tries to check a variable that is actualy an oblect like the bellow:

$ Object
(
    fid = String(4) "2772"
    uid = String(4) "1235"
    filename = String(45) "filename.pdf"
    uri = String(69) "public://(...)/filename.pdf"
    filemime = String(15) "application/pdf"
    filesize = String(6) "372540"
    status = String(1) "1"
    timestamp = String(10) "1365774040"
    rdf_mapping => Array (0)
    (
    )
)

StatusFileSize
new1.15 KB

I have same problem as #17 with sending attachements, here is a patch for dev version 2013-Mar-17.

For some reason I seem to get 2 (duplicate) attachments when using rules to send attachments, with both the patch and current Dev version.

+++ b/smtp.mail.inc 2013-04-29 12:22:37.333324000 +0200
@@ -441,12 +441,14 @@
+        if (!is_object($attachment)) {

Why you need to check is not a object? I mean with an isset or !empty you have done that kind of confirmation.

Had the same issue as #7 and patch in #12 solved it.

Patch #12 works fine for me.

Status:Needs review» Fixed

Patch from #12 was committed, thanks ;)

Automatically closed -- issue fixed for 2 weeks with no activity.