diff --git a/assets/email_template.html b/assets/email_template.html index 8357eeb4..d52fb2df 100644 --- a/assets/email_template.html +++ b/assets/email_template.html @@ -4,7 +4,7 @@
- +

NGI-ChIPseq: ChIP-Seq Best Practice v${version}

Run Name: $runName

diff --git a/assets/sendmail_template.txt b/assets/sendmail_template.txt index cfd81544..a76e8665 100644 --- a/assets/sendmail_template.txt +++ b/assets/sendmail_template.txt @@ -1,38 +1,62 @@ To: $email Subject: $subject Mime-Version: 1.0 -Content-Type: multipart/alternative;boundary="ngimethylseqmimeboundary" +Content-Type: multipart/related;boundary="ngimimeboundary" ---ngimethylseqmimeboundary -Content-Type: text/plain; charset=utf-8 - -$email_txt - ---ngimethylseqmimeboundary +--ngimimeboundary Content-Type: text/html; charset=utf-8 $email_html ---ngimethylseqmimeboundary +--ngimimeboundary Content-Type: image/png;name="NGI-ChIPseq_logo.png" Content-Transfer-Encoding: base64 -Content-ID: +Content-ID: Content-Disposition: inline; filename="NGI-ChIPseq_logo.png" -<% out << new File("$baseDir/assets/NGI-ChIPseq_logo.png").bytes.encodeBase64().toString() %> - ---ngimethylseqmimeboundary +<% out << new File("$baseDir/assets/NGI-ChIPseq_logo.png"). + bytes. + encodeBase64(). + toString(). + tokenize( '\n' )*. + toList()*. + collate( 76 )*. + collect { it.join() }. + flatten(). + join( '\n' ) %> + +--ngimimeboundary Content-Type: image/png;name="SciLifeLab_logo.png" Content-Transfer-Encoding: base64 Content-ID: Content-Disposition: inline; filename="SciLifeLab_logo.png" -<% out << new File("$baseDir/assets/SciLifeLab_logo.png").bytes.encodeBase64().toString() %> - ---ngimethylseqmimeboundary +<% out << new File("$baseDir/assets/SciLifeLab_logo.png"). + bytes. + encodeBase64(). + toString(). + tokenize( '\n' )*. + toList()*. + collate( 76 )*. + collect { it.join() }. + flatten(). + join( '\n' ) %> + +--ngimimeboundary Content-Type: image/png;name="NGI_logo.png" Content-Transfer-Encoding: base64 Content-ID: Content-Disposition: inline; filename="NGI_logo.png" -<% out << new File("$baseDir/assets/NGI_logo.png").bytes.encodeBase64().toString() %> +<% out << new File("$baseDir/assets/NGI_logo.png"). + bytes. + encodeBase64(). + toString(). + tokenize( '\n' )*. + toList()*. + collate( 76 )*. + collect { it.join() }. + flatten(). + join( '\n' ) %> + +--ngimimeboundary-- diff --git a/docs/usage.md b/docs/usage.md index 3c310750..120a9915 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -154,6 +154,9 @@ The output directory where the results will be saved. ### `--email` Set this parameter to your e-mail address to get a summary e-mail with details of the run sent to you when the workflow exits. If set in your user config file (`~/.nextflow/config`) then you don't need to speicfy this on the command line for every run. +### `--plaintext_email` +Set to receive plain-text e-mails instead of HTML formatted. + ### `-name` Name for the pipeline run. If not specified, Nextflow will automatically generate a random mnemonic. diff --git a/main.nf b/main.nf index 9fd48645..60a1a1ae 100755 --- a/main.nf +++ b/main.nf @@ -54,6 +54,7 @@ params.saveAlignedIntermediates = false params.broad = false params.outdir = './results' params.email = false +params.plaintext_email = false // Validate inputs macsconfig = file(params.macsconfig) @@ -86,6 +87,7 @@ params.three_prime_clip_r2 = 0 // Config / R locations params.multiqc_config = "$baseDir/conf/multiqc_config.yaml" multiqc_config = file(params.multiqc_config) +output_docs = file("$baseDir/docs/output.md") params.rlocation = false if (params.rlocation){ nxtflow_libs = file(params.rlocation) @@ -612,6 +614,7 @@ process output_documentation { input: val prefix from multiqc_prefix + file output from output_docs output: file "results_description.html" @@ -619,7 +622,7 @@ process output_documentation { script: def rlocation = params.rlocation ?: '' """ - markdown_to_html.r $baseDir/docs/output.md results_description.html $rlocation + markdown_to_html.r $output results_description.html $rlocation """ } @@ -678,17 +681,25 @@ workflow.onComplete { // Send the HTML e-mail if (params.email) { try { + if( params.plaintext_email ){ throw GroovyException('Send plaintext e-mail, not HTML') } // Try to send HTML e-mail using sendmail [ 'sendmail', '-t' ].execute() << sendmail_html - log.debug "[NGI-ChIPseq] Sent summary e-mail using sendmail" + log.info "[NGI-ChIPseq] Sent summary e-mail to $params.email (sendmail)" } catch (all) { // Catch failures and try with plaintext [ 'mail', '-s', subject, params.email ].execute() << email_txt - log.debug "[NGI-ChIPseq] Sendmail failed, failing back to sending summary e-mail using mail" + log.info "[NGI-ChIPseq] Sent summary e-mail to $params.email (mail)" } - log.info "[NGI-ChIPseq] Sent summary e-mail to $params.email" } + // Switch the embedded MIME images with base64 encoded src + ngichipseqlogo = new File("$baseDir/assets/NGI-ChIPseq_logo.png").bytes.encodeBase64().toString() + scilifelablogo = new File("$baseDir/assets/SciLifeLab_logo.png").bytes.encodeBase64().toString() + ngilogo = new File("$baseDir/assets/NGI_logo.png").bytes.encodeBase64().toString() + email_html = email_html.replaceAll(~/cid:ngichipseqlogo/, "data:image/png;base64,$ngichipseqlogo") + email_html = email_html.replaceAll(~/cid:scilifelablogo/, "data:image/png;base64,$scilifelablogo") + email_html = email_html.replaceAll(~/cid:ngilogo/, "data:image/png;base64,$ngilogo") + // Write summary e-mail HTML to a file def output_d = new File( "${params.outdir}/Documentation/" ) if( !output_d.exists() ) {