Hi,
I had problems with Backup and Migrate when sending emails with backup. My webhoster doesn't support current implementation of mime_mail (class responsible for sending emails with attachments located in includes/destinations.email.inc). I look into it and found solution. MimeMail module extends drupal_mail() function to support attachments. I think this is better solution and I think it should be commited to active branch. What do you think? I suggested implementation which is backward compatible below.
Just replace _backup_migrate_destination_email_mail_backup() function in this file includes/destinations.email.inc with version attached below
function _backup_migrate_destination_email_mail_backup($attachment, $to) {
$mimemail = FALSE;
//Check if modules mailsystem and mimemail is enabled
if(module_exists('mailsystem') && module_exists('mimemail')) {
//Check if we are using MimeMailSystem
$mail_system = variable_get('mail_system', mailsystem_defaults());
if($mail_system['default-system'] == 'MimeMailSystem') {
$mimemail = TRUE;
}
}
//if mimemail properly configured use it
if($mimemail) {
$module = 'backup_migrate';
$key = microtime();
$language = language_default();
$params = array();
$params['attachments'][] = array(
'filepath' => $attachment->path,
'filecontent' => '',
'filename' => $attachment->filename,
'filemime' => 'text/plain',
);
$from = variable_get('mimemail_mail', ini_get('sendmail_from'));
$send = FALSE;
$message = drupal_mail($module, $key, $to, $language, $params, $from, $send);
$message['subject'] = t('Database backup from !site: !file', array('!site' => variable_get('site_name', 'drupal'), '!file' => $attachment->filename));
$message['body'] = t('Database backup attached.') ."\n\n";
// Retrieve the responsible implementation for this message.
$system = drupal_mail_system($module, $key);
// Format the message body.
$message = $system->format($message);
// Send e-mail.
$message['result'] = $system->mail($message);
}else{
// Send mail
$attach = fread(fopen($attachment->path, "r"), filesize($attachment->path));
$mail = new mime_mail();
$mail->from = variable_get('site_mail', ini_get('sendmail_from'));
$mail->headers = 'Errors-To: [EMAIL='. $mail->from .']'. $mail->from .'[/EMAIL]';
$mail->to = $to;
$mail->subject = t('Database backup from !site: !file', array('!site' => variable_get('site_name', 'drupal'), '!file' => $attachment->filename));
$mail->body = t('Database backup attached.') ."\n\n";
$mail->add_attachment("$attach", $attachment->filename, "Content-Transfer-Encoding: base64 /9j/4AAQSkZJRgABAgEASABIAAD/7QT+UGhvdG9zaG", NULL, TRUE);
$mail->send();
}
}
I think it could be part of Backup and Migrate module.
Comments
Comment #0.0
parisekminor update
Comment #1
couturier commentedThis issue is 5 years old, and we are working on the port to D8 now with many other mail options available in 2017. If you still desire this feature, please open a new issue under the current version. The 7.x-2.x branch will be deprecated soon. See this issue: Verify 7.x-2.x -to- 7.x-3.x upgrade path, mark 7.x-2.x as unsupported.