Skip to content

Commit

Permalink
Error message when email unsuccessful
Browse files Browse the repository at this point in the history
  • Loading branch information
msuchard committed Jun 8, 2015
1 parent cb4c76d commit 20c3920
Showing 1 changed file with 25 additions and 16 deletions.
41 changes: 25 additions & 16 deletions SkeletonStudy/R/StudyInvariant.R
Expand Up @@ -112,25 +112,34 @@ email <- function(from,
if (missing(subject)) subject <- getDefaultStudyEmailSubject()
if (missing(file)) file <- getDefaultStudyFileName()

if(!file.exists(file)) stop(paste(c("No results file named '",file,"' exists"),sep=""))
if(!file.exists(file)) stop(paste(c("No results file named '",file,"' exists"),sep = ""))

result <- mailR::send.mail(from = from,
to = to,
subject = subject,
body = paste("\n", dataDescription, "\n",
sep = ""),
smtp = list(host.name = "aspmx.l.google.com",
port = 25),
attach.files = file,
authenticate = FALSE,
send = TRUE)
if (result$isSendPartial()) {
stop("Error in sending email")
} else {
tryCatch({
result <- mailR::send.mail(from = from,
to = to,
subject = subject,
body = paste("\n", dataDescription, "\n",
sep = ""),
smtp = list(host.name = "aspmx.l.google.com",
port = 25),
attach.files = file,
authenticate = FALSE,
send = TRUE)
if (result$isSendPartial()) {
stop("Unknown error in sending email")
} else {
writeLines(c(
"Sucessfully emailed the following file:",
paste("\t", file, sep = ""),
paste("to:", to)
))
}
}, error = function(e) {
writeLines(c(
"Emailed the following file:",
"Error in automatically emailing results, most likely due to security settings.",
"Please manually email the following file:",
paste("\t", file, sep = ""),
paste("to:", to)
))
}
})
}

0 comments on commit 20c3920

Please sign in to comment.