DokuWiki

It's better when it's simple

User Tools

Site Tools


plugin:swiftmail

SwiftMailer plugin

Compatible with DokuWiki

Angua, Adora Belle

plugin This plugin uses the SwiftMailer class to send DokuWiki mails and supports using a remote SMTP (with optional auth) without relying on PHP's mail() function

Last updated on
2013-03-09
Provides
Action
Repository
Source

Tagged with email, smtp, smtpauth

This plugin replaces the way DokuWiki sends emails. Instead of relying on PHP's built-in mail function, it uses the SwiftMailer library. This is especially useful when configuring PHP for sending mails is complicated (Windows) or not possible. SwiftMail is included in the plugin and does not need to be downloaded separately.

Download and Installation

Download and install the plugin using the Plugin Manager using the download link given above. Refer to Plugins on how to install plugins manually.

Changes

Configuration

All config options can be set in the configuration manager under the “Swiftmail Plugin Settings” section (see screenshot). Additionally you need to set up the mailfrom option, which is in the “Notification Settings” section of the configuration manager.

SwiftMail Plugin Settings

When the last option is enabled the whole SMTP session will be printed directly to the screen when sending the mail fails.

Testing

The plugin adds a new item to the Admin screen. Using this you can trigger sending a test mail from DokuWiki. If something goes wrong sending this mail, a detailed log is printed.

Known Issues

This plugin does only support sending plain text emails. HTML mails and attachments are currently not supported (See Issue #7).

The plugin use an old version of Swiftmailer library but here is the nice workaround to get full capabilities with this plugin : HTML mails and attachments !

First, we need to add 2 lines in /inc/Mailer.class.php at line 629 ( method send() ) :

            'body'    => &$this->text,
            # Added vars
            'attach'  => &$this->attach,
            'html'    => &$this->html,
            # End added vars

This give us direct access of attachment array and body in html version.

And 1 line in /inc/Mailer.Class.php at line 79 ( method attachFile() ) :

        $this->attach[] = array(
          'path' => $path,
          ....

The path var is redundant with data but i would'nt rebuild the file with file_put_contents function and this version of SwiftMailer seems not support inline file data.

Then, we add some code for HTML body support in /lib/plugins/swiftmail/action.php in line 64 :

            //$message =& new Swift_Message($event->data['subject'], $event->data['body']);
            # We need access to $conf['htmlmail'] parameter
            global $conf;
            $message =& new Swift_Message($event->data['subject']);
            # add text/plain multipart body
  	    $message_text_part = new Swift_Message_Part($event->data['body']);
  	    $message->attach($message_text_part);
  	    # add text/html multipart body  		    
            if ($event->data['html'] && $conf['htmlmail']) {			  
		  $message_html_part = new Swift_Message_Part($event->data['html']);
		  $message_html_part->setContentType("text/html");
		  $message->attach($message_html_part);
	    }

Notice old line with $message = & new Swift_Message(… is commented.
global conf is needed to give access to global configuration parameters array. You can put it at the begining of the function.

And the attachment support in line 123 :

            // Attachment support
            if (count($event->data['attach'])>0){
              foreach ($event->data['attach'] as $attachment){
                $swiftAttachment = new Swift_Message_Attachment(new swift_file($attachment['path']),$attachment['name'],$attachment['mime']);
               $message->attach($swiftAttachment);
              }
           }

This work fine for me with support of htmlmail config parameter for notification. I use it too with Bureaucracy plugin.

Hope you find this hack great !
Flavien

plugin/swiftmail.txt · Last modified: 2015-05-27 17:08 by 77.151.242.178