Good morning, I am using R to send mass emails with the following code:
setwd("C:/Users/oscariro/Documents/R/Devoluciones")
tempreport <- file.path(getwd(),"Reenvio.rmd")
#file.copy("STC.Rmd",tempreport,overwrite = TRUE)
a=1
# Loop para enviar correo por
for(i in 1:nrow(Reenvia %>% select(cta_usuario) %>% distinct())){
print(i)
Asesor_<- Reenvia %>% select(cta_usuario) %>% distinct() %>% slice(i) %>% as.character()
Nivelcc=Planta %>% filter(`FUERZA COMERCIAL`=="DIRECTOR") %>% filter(SBAN==Planta %>% filter(UsuarioCobis==Asesor_) %>%
select(SBAN) %>% distinct() %>% as.character() ) %>%
select(Correo) %>% distinct() %>% as.character()
print("2a7")
#nbcc="[email protected]"
parametros <- list(Comercial=Reenvia %>% filter(cta_usuario==Asesor_) %>% select(nombre_usuario) %>% distinct() %>% as.character(),
Asesor_=Asesor_)
email<-blastula::render_email(input = tempreport,render_options = list(params=parametros))
print(parametros$Comercial)
# En caso de no poder enviar imprimir mensaje que no se pudo enviar correo
tryCatch(
email %>% smtp_send(
from="[email protected]",
to=Planta %>% filter(UsuarioCobis==Asesor_) %>% select(Correo) %>% distinct() %>% as.character(),
#to="[email protected]",
cc=Nivelcc,#bcc = nbcc,
#cc="[email protected]",
#cc= c("[email protected]","[email protected]"),
subject = glue("El motor de alertamientos te informa"),
credentials=creds_key("outlook")
),error=function(e) {print(glue("No se le pudo enviar correo a {Asesor_}"))
#a=rbind(a,Asesor_)
#if(i==nrow(Alertas %>% select(Asesor) %>% distinct())){
#openxlsx::write.xlsx(a,glue("{nrow(a)}_Usuarios que recibieron correo-{today()}"))
#}
}
)
}
However, when shipment number 494 arrives, the shipment stops and the following error appears:
Error in file(file, ifelse(append, "a", "w")) :
cannot open the connection
In addition: Warning message:
In file(file, ifelse(append, "a", "w")) :
cannot open file 'alerta.knit.md': Too many open files