From 8b09c48db53a813ec75f0fea7223a223e0d64eca Mon Sep 17 00:00:00 2001 From: Bai juyi Date: Sun, 8 Sep 2024 13:04:20 +0200 Subject: [PATCH] Send an email to the PMET admin when a new job is submitted. --- PMETdev/intervals_index_pair.sh | 2 + PMETdev/promoters_index_pair.sh | 2 + PMETdev/promoters_index_pair_new_fimo.sh | 2 +- PMETdev/promoters_only_pair.sh | 1 + R/utils/send_mail.R | 112 +++++++++++++---------- 5 files changed, 69 insertions(+), 50 deletions(-) diff --git a/PMETdev/intervals_index_pair.sh b/PMETdev/intervals_index_pair.sh index d0de132..a3e7b1f 100755 --- a/PMETdev/intervals_index_pair.sh +++ b/PMETdev/intervals_index_pair.sh @@ -135,6 +135,8 @@ while getopts ":r:o:k:n:f:t:x:g:c:e:l:" options; do esac done +Rscript R/utils/send_mail.R $email + # rename input file variable shift $((OPTIND - 1)) genomefile=$1 diff --git a/PMETdev/promoters_index_pair.sh b/PMETdev/promoters_index_pair.sh index ee68c30..08167aa 100755 --- a/PMETdev/promoters_index_pair.sh +++ b/PMETdev/promoters_index_pair.sh @@ -150,6 +150,8 @@ mkdir -p $indexingOutputDir start=$SECONDS +Rscript R/utils/send_mail.R $email + # ------------------------------------------------------------------------------------------- # 1. sort annotaion by gene coordinates print_fluorescent_yellow " 1. Sorting annotation by gene coordinates" diff --git a/PMETdev/promoters_index_pair_new_fimo.sh b/PMETdev/promoters_index_pair_new_fimo.sh index 80ef11f..a16c4b5 100755 --- a/PMETdev/promoters_index_pair_new_fimo.sh +++ b/PMETdev/promoters_index_pair_new_fimo.sh @@ -181,7 +181,7 @@ while getopts ":r:i:o:n:k:p:f:g:v:u:t:c:x:g:e:l:" options; do exit 1;; esac done - +Rscript R/utils/send_mail.R $email shift $((OPTIND - 1)) genomefile=$1 diff --git a/PMETdev/promoters_only_pair.sh b/PMETdev/promoters_only_pair.sh index d8c7837..bd77e70 100755 --- a/PMETdev/promoters_only_pair.sh +++ b/PMETdev/promoters_only_pair.sh @@ -88,6 +88,7 @@ while getopts ":d:g:i:t:o:e:l:" options; do esac done +Rscript R/utils/send_mail.R $email # ------------------------------------ Run pmet ---------------------------------- mkdir -p $outputdir diff --git a/R/utils/send_mail.R b/R/utils/send_mail.R index 9167edb..4961930 100644 --- a/R/utils/send_mail.R +++ b/R/utils/send_mail.R @@ -1,44 +1,3 @@ -# library(mailR) - -# # Define a function to send an email -# # Arguments: -# # recipient: The recipient of the email -# # result_link: The result link of the email -# SendResultMail <- function(recipient = NULL, result_link = NULL) { -# sender <- "result@pmet.simpleconstellation.com" - -# subject <- "PMET result is ready!" -# body <- paste("Dear PMET user,\n\n\n", -# result_link, -# "The result will be kept in the server for a week, please download it as soon as possible.\n\n\n Thank you!", sep = "\n\n") - -# send.mail( -# from = sender, -# to = recipient, -# subject = subject, -# body = body, -# smtp = list( -# host.name = "v095996.kasserver.com", -# port = 587, -# user.name = "", -# passwd = "", -# ssl = TRUE -# ), -# authenticate = TRUE, -# send = TRUE, -# # attach.files = emailFile, -# encoding = "utf-8" -# ) -# } - - -# args <- commandArgs(trailingOnly = TRUE) - -# recipient <- args[1] -# result_link <- args[2] - -# SendResultMail(recipient = recipient, result_link = result_link) - library(dplyr) library(emayili) @@ -53,15 +12,70 @@ SendResultMail <- function(recipient = NULL, result_link = NULL) { sender <- EMAIL_ADDRESS - subject <- "PMET result is ready!" - body <- paste( - "\n\n\nDear PMET user,\n\n\n", - "Please copy and paste the link into a browser if cliking failed\n\n", - result_link, - "\nThe result will be kept in the server for a week, please download it as soon as possible.\n\n\n Thank you!", - sep = "\n\n" + if (is.null(result_link)) { + subject <- "PMET is running, please be patient!" + + body <- paste( + '', + '', + '', + '', + '', + '', + '', + '
', + '

Dear PMET User,

', + '

Your request is currently being processed. The results will be sent to your mailbox once PMET has completed its analysis.

', + '

If you do not receive the results within two days, please reply to this email for further assistance.

', + '

Thank you for your patience!

', + '', + '
', + '', + '', + sep = "" + ) + } else { + subject <- "PMET result is ready!" + body <- paste( + '', + '', + '', + '', + '', + '', + '', + '
', + '

Dear PMET User,

', + '

We are pleased to inform you that your results are ready. Please click the link below to access your results. If the link does not work, you can copy and paste it into your browser’s address bar.

', + '

', result_link, '

', + '

Please note: The results will be available on the server for one week. We recommend downloading your results at your earliest convenience.

', + '

If you have any questions or need further assistance, feel free to reply to this email.

', + '

Thank you for using our services!

', + '', + '
', + '', + '', + sep = "" ) + } + smtp <- emayili::server( host = EMAIL_SERVER, port = EMAIL_PORT, @@ -79,6 +93,6 @@ SendResultMail <- function(recipient = NULL, result_link = NULL) { args <- commandArgs(trailingOnly = TRUE) recipient <- args[1] -result_link <- args[2] +result_link <- if (length(args) >= 2) args[2] else NULL SendResultMail(recipient = recipient, result_link = result_link)