Skip to content

Commit

Permalink
Send an email to the PMET admin when a new job is submitted.
Browse files Browse the repository at this point in the history
  • Loading branch information
duocang committed Sep 8, 2024
1 parent fd8469c commit 8b09c48
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 50 deletions.
2 changes: 2 additions & 0 deletions PMETdev/intervals_index_pair.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions PMETdev/promoters_index_pair.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion PMETdev/promoters_index_pair_new_fimo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions PMETdev/promoters_only_pair.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
112 changes: 63 additions & 49 deletions R/utils/send_mail.R
Original file line number Diff line number Diff line change
@@ -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 <- "[email protected]"

# 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)

Expand All @@ -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(
'<!DOCTYPE html>',
'<html>',
'<head>',
'<meta charset="UTF-8">',
'<style>',
' body { font-family: Arial, sans-serif; line-height: 1.8; background-color: #f4f4f4; margin: 0; padding: 0; }',
' .container { max-width: 600px; margin: 40px auto; padding: 20px; background-color: #ffffff; border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.1); }',
' h2 { color: #333333; margin-bottom: 20px; }',
' p { font-size: 15px; color: #555555; margin: 10px 0; }',
' .note { font-size: 13px; color: #999999; margin-top: 20px; }',
' .footer { font-size: 13px; color: #888888; margin-top: 40px; text-align: center; }',
'</style>',
'</head>',
'<body>',
'<div class="container">',
'<h2>Dear PMET User,</h2>',
'<p>Your request is currently being processed. The results will be sent to your mailbox once PMET has completed its analysis.</p>',
'<p class="note">If you do not receive the results within two days, please reply to this email for further assistance.</p>',
'<p>Thank you for your patience!</p>',
'<div class="footer">Best regards,<br/>The PMET Team</div>',
'</div>',
'</body>',
'</html>',
sep = ""
)
} else {
subject <- "PMET result is ready!"
body <- paste(
'<!DOCTYPE html>',
'<html>',
'<head>',
'<meta charset="UTF-8">',
'<style>',
' body { font-family: Arial, sans-serif; line-height: 1.8; background-color: #f4f4f4; margin: 0; padding: 0; }',
' .container { max-width: 600px; margin: 40px auto; padding: 20px; background-color: #ffffff; border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.1); }',
' h2 { color: #333333; margin-bottom: 20px; }',
' p { font-size: 15px; color: #555555; margin: 10px 0; }',
' .link { font-size: 16px; color: #1a73e8; text-decoration: none; word-wrap: break-word; }',
' .link:hover { text-decoration: underline; }',
' .note { font-size: 13px; color: #999999; margin-top: 20px; }',
' .footer { font-size: 13px; color: #888888; margin-top: 40px; text-align: center; }',
'</style>',
'</head>',
'<body>',
'<div class="container">',
'<h2>Dear PMET User,</h2>',
'<p>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.</p>',
'<p><a href="', result_link, '" class="link">', result_link, '</a></p>',
'<p class="note">Please note: The results will be available on the server for one week. We recommend downloading your results at your earliest convenience.</p>',
'<p>If you have any questions or need further assistance, feel free to reply to this email.</p>',
'<p>Thank you for using our services!</p>',
'<div class="footer">Best regards,<br/>The PMET Team</div>',
'</div>',
'</body>',
'</html>',
sep = ""
)

}

smtp <- emayili::server(
host = EMAIL_SERVER,
port = EMAIL_PORT,
Expand All @@ -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)

0 comments on commit 8b09c48

Please sign in to comment.